rails capistrano3发布时assets的优化

发布代码(cap production deploy),如果app/assets/没有代码变化,就跳过assets:precompile !

namespace :deploy do
  # https://gist.github.com/5b3471d17b8ced329832
  Rake::Task["deploy:compile_assets"].clear_actions
  task :compile_assets => [:set_rails_env] do
    run_locally do
      if capture("git --no-pager diff #{fetch(:previous_revision)} #{fetch(:current_revision)} app/assets vendor/assets").empty?
         info "Skipping assets compilation"
      else
        invoke 'deploy:assets:precompile'
        invoke 'deploy:assets:backup_manifest'
      end
    end
  end
end

Comments