1

将我的应用程序部署到 Amazon 的 Opsworks 时,我的资产预编译步骤经常失败。

厨师食谱如下所示:

node[:deploy].each do |application, deploy|
  deploy deploy[:deploy_to] do
    before_restart do
      rails_env = deploy[:rails_env]
      current_release = release_path
      execute "rake assets:precompile" do
        user deploy[:user]
        cwd current_release
        command "bundle exec rake assets:precompile"
        environment "RAILS_ENV" => rails_env
      end
    end
  end
end

...产生此错误:

Mixlib::ShellOut::ShellCommandFailed
------------------------------------
Expected process to exit with [0], but received ''
---- Begin output of bundle exec rake assets:precompile ----
STDOUT: 
STDERR: I, [2014-07-15T02:05:30.399857 #12281]  INFO -- : Writing <asset path>
...
...
...
---- End output of bundle exec rake assets:precompile ----
Ran bundle exec rake assets:precompile returned 

编译步骤似乎成功了,为什么 Chef 会出错?

4

1 回答 1

2

经过一番调查,看起来 Sprockets 正在将信息消息记录到标准错误中,Chef 将其解释为失败。

一个更改此行为的拉取请求,但它似乎与其中一位贡献者停滞不前......

因此,与此同时,我将 stderr 重定向到 stdin,如下所示:

node[:deploy].each do |application, deploy|
  deploy deploy[:deploy_to] do
    before_restart do
      rails_env = deploy[:rails_env]
      current_release = release_path
      execute "rake assets:precompile" do
        user deploy[:user]
        cwd current_release
        command "bundle exec rake assets:precompile 2>&1"
        environment "RAILS_ENV" => rails_env
      end
    end
  end
end
于 2014-07-15T07:36:41.193 回答