Skip to content

Instantly share code, notes, and snippets.

@snow
Forked from twetzel/deploy.rb
Last active August 29, 2015 14:24
Show Gist options
  • Save snow/f3ea4943ccddb3a83836 to your computer and use it in GitHub Desktop.
Save snow/f3ea4943ccddb3a83836 to your computer and use it in GitHub Desktop.
# 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(:rails_env)} bundle exec rake assets:precompile"
end
# rsync to each server
local_dir = "./public/assets/"
on roles( fetch(:assets_roles, [:web]) ) do
# this needs to be done outside run_locally in order for host to exist
remote_dir = "#{host.user}@#{host.hostname}:#{release_path}/public/assets/"
run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }
end
# clean up
run_locally { execute "rm -rf #{local_dir}" }
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment