Created
December 19, 2012 16:42
-
-
Save keighl/4338134 to your computer and use it in GitHub Desktop.
Faster Rails asset precompilation via Capistrano .. just do it locally!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Speed things up by not loading Rails env | |
config.assets.initialize_on_precompile = false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
@keighl I've created a fork of your gist that I used with Capistrano 3 and Rails 4: https://gist.github.com/basti/9232976
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
I ended up turning this strategy into a rubygem. Thanks for the inspiration.
https://github.com/spagalloco/capistrano-local-precompile