Skip to content

Instantly share code, notes, and snippets.

@tiagoamaro
Last active December 21, 2015 11:59
Show Gist options
  • Save tiagoamaro/6303123 to your computer and use it in GitHub Desktop.
Save tiagoamaro/6303123 to your computer and use it in GitHub Desktop.
Capistrano task for compiling tasks locally
# UPDATE: This will only work for Capistrano 2.x and probably will not work for Capistrano 3.
#
# This Gist was based on fernando blat post: (http://fernando.blat.es/post/12563486374/optimize-deploy-time-compiling-your-assets-locally)
set :rails_env, 'production'
namespace :assets do
desc 'Run the precompile task locally and rsync with shared'
task :precompile do
run_locally('rm -rf public/assets/*')
run_locally("RAILS_ENV=#{rails_env} rake assets:precompile")
run_locally('touch assets.tgz && rm assets.tgz')
run_locally('tar zcvf assets.tgz public/assets/')
run_locally('mv assets.tgz public/assets/')
end
desc 'Upload precompiled assets'
task :upload_assets do
upload "public/assets/assets.tgz", "#{release_path}/assets.tgz"
run "cd #{release_path}; tar zxvf assets.tgz; rm assets.tgz"
end
end
before 'deploy:update_code', 'assets:precompile'
after 'deploy:create_symlink', 'assets:upload_assets'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment