Last Updated: February 25, 2016
·
3.421K
· gregmolnar

Capistrano task for deploy compiled assets

If you deploy to an Amazon VPS with capistrano you might find the assets compilation time too long. In some cases it is faster to compile the assets locally but it is not a good practice to commit the compiled assets into the repo and capistrano deploys from that. Here is a workaround for this:

  namespace :assets do
    desc "compile assets locally and upload before finalize_update"
    task :deploy do
        %x[bundle exec rake assets:clean && bundle exec rake assets:precompile]
        ENV['COMMAND'] = " mkdir '#{release_path}/public/assets'"
        invoke
        upload '/path/to/app/public/assets', "#{release_path}/public/assets", {:recursive => true}
    end
end
after "deploy:finalize_update", "assets:deploy"