Last active
August 29, 2015 13:56
-
-
Save bigfive/9085824 to your computer and use it in GitHub Desktop.
Capistrano local asset precompile
This file contains 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
set :local_path, Dir.pwd | |
namespace :deploy do | |
namespace :assets do | |
desc 'Run asset procompilation locally' | |
task :precompile_locally, :roles => :web, :except => {:no_release => true} do | |
run_locally("bundle exec rake assets:precompile") | |
end | |
desc 'Copy procompiled assets to servers' | |
task :copy_local_assets, :roles => :web, :except => {:no_release => true} do | |
servers = find_servers_for_task(current_task) | |
port_option = port ? " -e 'ssh -p #{port}' " : '' | |
servers.each do |server| | |
run_locally "rsync --recursive --times --rsh=ssh --compress --human-readable #{port_option} --progress public/assets #{user}@#{server}:#{latest_release}/public" | |
end | |
end | |
desc 'Overridden by config/deploy_local_assets.rb.rb' | |
task :precompile, :roles => :web, :except => {:no_release => true} do | |
# dont precompile, we already did a local precompile | |
end | |
desc 'Overridden by config/deploy_local_assets.rb.rb' | |
task :symlink do | |
# dont symlink the asset directory from shared - we just put them in the release dir | |
end | |
desc 'Remove temporary files from local precompilation' | |
task :clean_up_local_precompile, :roles => :web, :except => {:no_release => true} do | |
run_locally("rm -rf public/assets/*") | |
end | |
end | |
end | |
before 'deploy:update', 'deploy:assets:precompile_locally' | |
after 'deploy:update', 'deploy:assets:copy_local_assets' | |
after 'deploy:assets:copy_local_assets', 'deploy:assets:clean_up_local_precompile' | |
on_rollback { find_and_execute_task 'deploy:assets:clean_up_local_precompile' } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
And add
load 'config/deploy_local_assets'
to your Cap file