OpsWorks:资产预编译多次

时间:2015-07-15 15:44:14

标签: ruby-on-rails deployment chef aws-opsworks

我正在使用AWS OpsWorks部署Rails应用程序。要预编译资产,我使用以下Chef配方:

node[:deploy].each do |application, deploy|

    deploy_to = node[:deploy][application][:deploy_to]
    rails_env = node[:deploy][application][:rails_env]

    directory "#{deploy_to}/shared/assets"

    link "#{deploy_to}/current/public/assets" do
      to "#{deploy_to}/shared/assets"
    end

    execute "rake assets:precompile" do
      cwd "#{deploy_to}/current"
      command "bundle exec rake assets:precompile"
      environment "RAILS_ENV" => rails_env
    end

end

它可以正确预编译,但在以下部署中,它会再次经历整个预编译过程,即使没有修改资产并且资源文件夹是共享的。我也按照建议here尝试了一个Chef钩子,结果相同。你怎么能在需要的时候让它运行?

1 个答案:

答案 0 :(得分:0)

您可以在语句中添加not_if或only_if子句:

这样的事情:

execute "rake assets:precompile" do
  cwd "#{deploy_to}/current"
  command "bundle exec rake assets:precompile"
  environment "RAILS_ENV" => rails_env
  not_if { File.exists?("<path to expected precompiled asset>") }
end

如果您希望每次某个目录发生更改时都可以运行,则可以使用主厨notifications