显示来自Vagrant的Grunt输出

时间:2014-08-04 03:50:03

标签: gruntjs vagrant chef chef-solo vagrantfile

更新了解决方案。非常感谢@Sneal

我有一个我设置的Vagrant框,我的食谱中的最终Chef Solo命令是一个grunt watch命令,当从命令行正常使用时,显示grunt watch执行的任务的输出(即编译较少)对css,jslinting错误等)但是当我的流浪盒出现时,我没有通过Vagrant输出输出。其他一切似乎都运行良好,包括LiveReload grunt通过Chrome LiveReload扩展程序执行。这就是我的Vagrantfile的样子:

VAGRANTFILE_API_VERSION = "2"
PORT = 9090

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
    config.vm.box = "precise-server-cloudimg-i386-vagrant-disk1"
    config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-i386-vagrant-disk1.box"

    config.vm.network "forwarded_port", guest: PORT, host: 8080
    config.vm.network "forwarded_port", guest: 35729, host: 35729

    config.ssh.forward_agent = true

    config.vm.synced_folder "../", "/vagrant", owner: "vagrant", group: "vagrant", mount_options: ["dmode=775", "fmode=775"]

    config.vm.provider "virtualbox" do |vb|
        vb.customize ["modifyvm", :id, "--memory", "2048"]
    end

    config.vm.provision :shell, :inline => "gem install chef --no-rdoc --no-ri --conservative"

    config.vm.provision "chef_solo" do |chef|
        chef.custom_config_path = "config.chef"
        chef.json = {
            :app => {
                :name => "website",
                :web_root => "/vagrant/app"
            },
            :user => {
                :name => "vagrant",
                :group => "vagrant"
            },
            :nginx => {
                :dir => "/etc/nginx",
                :port => PORT
            },
            :mysql => {
                :server_root_password => "reallyAwesomePassword",
                :allow_remote_root => false
            }
        }
        chef.run_list = [
            "recipe[apt]",
            "recipe[git]",
            "recipe[php5_ppa::from_ondrej]",
            "recipe[php]",
            "recipe[php5-fpm::install]",
            "recipe[nginx]",
            "recipe[mysql::client]",
            "recipe[mysql::server]",
            "recipe[composer]",
            "recipe[nodejs]",
            "recipe[website]"
        ]
    end
    # replaces the commented section below
    config.vm.provision :shell, :inline => "cd /vagrant && grunt watch"
end

我在grunt命令之后添加了一条额外的日志消息,甚至没有显示。这是我的网站食谱:

execute 'sudo gem install compass' do
    cwd '/vagrant'
    user 'vagrant'
    action :run
    environment ({'HOME' => '/home/vagrant', 'USER' => 'vagrant'})
end

execute 'sudo gem install sass' do
    cwd '/vagrant'
    user 'vagrant'
    action :run
    environment ({'HOME' => '/home/vagrant', 'USER' => 'vagrant'})
end

execute 'sudo npm install -g yo phantomjs' do
    cwd '/vagrant'
    user 'vagrant'
    action :run
    environment ({'HOME' => '/home/vagrant', 'USER' => 'vagrant'})
end

directory node.app.web_root do
    owner node.user.name
    mode "0755"
    recursive true
end

template "#{node.nginx.dir}/sites-available/#{node.app.name}.conf" do
    source "nginx.conf.erb"
    mode "0644"
end

nginx_site "#{node.app.name}.conf"

cookbook_file "#{node.app.web_root}/info.php" do
    source "info.php"
    mode "0755"
    owner node.user.name
end

execute 'bower install' do
    cwd '/vagrant'
    user 'vagrant'
    action :run
    environment ({'HOME' => '/home/vagrant', 'USER' => 'vagrant'})
end

execute 'sudo npm install' do
    cwd '/vagrant'
    user 'vagrant'
    action :run
    environment ({'HOME' => '/home/vagrant', 'USER' => 'vagrant'})
end

execute 'composer --verbose -v install' do
    cwd '/vagrant'
    user 'vagrant'
    action :run
    environment ({'HOME' => '/home/vagrant', 'USER' => 'vagrant'})
end

# execute 'grunt watch' do
#     cwd '/vagrant'
#     user 'vagrant'
#     action :run
#     environment ({'HOME' => '/home/vagrant', 'USER' => 'vagrant'})
# end

log "message" do
  message "All Done!"
  level :info
end

我需要做些什么才能让grunt输出显示在厨师输出中?对Vagrant和Chef来说仍然是新手,所以任何建议都表示赞赏。

1 个答案:

答案 0 :(得分:1)

我会使用Chef来配置我的基础架构和工具,但是然后使用一个单独的Vagrant shell配置程序来实际执行grunt命令。 Vagrant shell配置程序将显示stdout。