Skip to content

Instantly share code, notes, and snippets.

@jarthod
Created September 20, 2015 08:20
Show Gist options
  • Save jarthod/17918ab22417f5e6818e to your computer and use it in GitHub Desktop.
Save jarthod/17918ab22417f5e6818e to your computer and use it in GitHub Desktop.
Capistrano local assets compile
# Rewrite precompile tasks to do it locally
Rake::Task["deploy:compile_assets"].clear
task :compile_assets => [:set_rails_env] do
# invoke 'deploy:assets:precompile'
invoke 'deploy:assets:precompile_local'
invoke 'deploy:assets:backup_manifest'
end
namespace :assets do
task :precompile_local do
# compile assets locally
run_locally do
execute "RAILS_ENV=#{fetch(:stage)} bin/rake assets:precompile"
end
# rsync to each server
local_dir = "./public/assets/"
on(roles :web) do
remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/public/assets/"
run_locally { execute "rsync -av #{local_dir} #{remote_dir}" }
end
# clean up
run_locally { execute "rm -rf #{local_dir}" }
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment