Skip to content

Instantly share code, notes, and snippets.

@msuzoagu
Forked from keighl/application.rb
Created August 24, 2019 00:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save msuzoagu/ab51ee50b4a9ee2b46a34dcab4d690f8 to your computer and use it in GitHub Desktop.
Save msuzoagu/ab51ee50b4a9ee2b46a34dcab4d690f8 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment