Skip to content

Instantly share code, notes, and snippets.

@codingfoo
Created March 11, 2014 20:15
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codingfoo/9494072 to your computer and use it in GitHub Desktop.
Save codingfoo/9494072 to your computer and use it in GitHub Desktop.
Rails 4 Capistrano 2 local assets precompile
namespace :deploy do
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile, :roles => :app, :except => { :no_release => true } do
system("bundle check"); exit if $? != 0
system("RAILS_ENV=#{stage} bundle exec rake assets:precompile"); exit if $? != 0
servers = find_servers :roles => :web, :except => { :no_release => true }
run <<-CMD.compact
cp -- #{shared_manifest_path.shellescape} #{current_path.to_s.shellescape}/assets_manifest#{File.extname(shared_manifest_path)}
CMD
run <<-CMD.compact
rm -- #{shared_manifest_path.shellescape}
CMD
servers.each { |server| system("rsync --recursive --times --rsh=ssh --compress --human-readable --progress public/assets #{user}@#{server}:#{shared_path} > /dev/null"); exit if $? != 0 }
system("RAILS_ENV=#{stage} bundle exec rake assets:clean")
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment