Skip to content

Instantly share code, notes, and snippets.

@tyler-boyd
Forked from twetzel/deploy.rb
Last active May 23, 2018 08:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save tyler-boyd/90bc453d29c46cfd3db0105d0f7d4c9b to your computer and use it in GitHub Desktop.
Save tyler-boyd/90bc453d29c46cfd3db0105d0f7d4c9b to your computer and use it in GitHub Desktop.
Compile assets locally with Capistrano 3.8.1 and Rails 5.1.1
# Clear existing task so we can replace it rather than "add" to it.
Rake::Task["deploy:compile_assets"].clear
namespace :deploy do
desc 'Compile assets'
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
desc "Precompile assets locally and then rsync to web servers"
task :precompile_local do
# compile assets locally
run_locally do
execute "RAILS_ENV=#{fetch(:stage)} bundle exec rake assets:precompile"
end
# rsync to each server
dirs = {
'./public/assets/' => 'public/assets/',
'./public/packs/' => 'public/packs/'
}
on roles( fetch(:assets_roles, [:web]) ) do
# this needs to be done outside run_locally in order for host to exist
dirs.each do |local, remote|
remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/#{remote}"
run_locally { execute "rsync -av --delete #{local} #{remote_dir}" }
end
end
# clean up
run_locally { execute "rm -rf #{dirs.keys.first}" }
end
end
end
@robotzhang
Copy link

thx for your job

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