-
-
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
This file contains hidden or 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
# 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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thx for your job