Skip to content

Instantly share code, notes, and snippets.

@keighl
Created December 19, 2012 16:42
Show Gist options
  • Select an option

  • Save keighl/4338134 to your computer and use it in GitHub Desktop.

Select an option

Save keighl/4338134 to your computer and use it in GitHub Desktop.
Faster Rails asset precompilation via Capistrano .. just do it locally!
# Speed things up by not loading Rails env
config.assets.initialize_on_precompile = false
# Without turbo sprockets ... rm assets when we're done
namespace :deploy do
task :default do
update
assets.precompile
restart
cleanup
# etc
end
end
namespace :assets do
desc "Precompile assets locally and then rsync to app servers"
task :precompile, :only => { :primary => true } do
run_locally "bundle exec rake assets:precompile;"
servers = find_servers :roles => [:app], :except => { :no_release => true }
servers.each do |server|
run_locally "rsync -av ./public/assets/ #{user}@#{server}:#{current_path}/public/assets/;"
end
run_locally "rm -rf public/assets"
end
end
# With turbo sprockets ... keeps assets around instead of rm'ing it
namespace :deploy do
task :default do
update
assets.precompile
restart
cleanup
# etc
end
end
namespace :assets do
desc "Precompile assets locally and then rsync to app servers"
task :precompile, :only => { :primary => true } do
run_locally "mkdir -p public/__assets; mv public/__assets public/assets;"
run_locally "bundle exec rake assets:clean_expired; bundle exec rake assets:precompile;"
servers = find_servers :roles => [:app], :except => { :no_release => true }
servers.each do |server|
run_locally "rsync -av ./public/assets/ #{user}@#{server}:#{current_path}/public/assets/;"
end
run_locally "mv public/assets public/__assets"
end
end
@stve
Copy link
Copy Markdown

stve commented Oct 4, 2013

I ended up turning this strategy into a rubygem. Thanks for the inspiration.

https://github.com/spagalloco/capistrano-local-precompile

@basti
Copy link
Copy Markdown

basti commented Feb 26, 2014

@keighl I've created a fork of your gist that I used with Capistrano 3 and Rails 4: https://gist.github.com/basti/9232976

@neolyte
Copy link
Copy Markdown

neolyte commented Sep 20, 2014

I've been looking for something like that for SO long .. and this one is the only that seamlessly work. Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment