0

I am deploying a Rails application using AWS OpsWorks. To precompile the assets, I use the following Chef recipe:

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

It precompiles correctly, but in following deployments it goes through the whole precompile process again, even though no asset was modified and the assets folder is shared. I also tried a Chef hook, as suggested here, with the same result. How could you make it run only when needed?

Community
  • 1
  • 1
davids
  • 6,259
  • 3
  • 29
  • 50

1 Answers1

0

You can add not_if or only_if clause to the statement:

Something like this:

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

If you want it to run every time there is a change in a certain directory, you can use chef notifications.

semirami
  • 289
  • 2
  • 7