Skip to content

Instantly share code, notes, and snippets.

@krists
Created March 13, 2016 18:30
Show Gist options
  • Save krists/bdb5dc9609030604ca07 to your computer and use it in GitHub Desktop.
Save krists/bdb5dc9609030604ca07 to your computer and use it in GitHub Desktop.
Compile Rails assets locally and rsync them to server (Capistrano 3)
# lib/capistrano/tasks/assets.rake
namespace :assets do
desc "Precompile assets locally and then rsync to web servers"
task :precompile do
on roles(:web) do
rsync_host = host.to_s
run_locally do
with rails_env: fetch(:stage) do
execute :bundle, "exec rake assets:precompile"
end
execute "rsync -vrhe ssh --progress --delete ./public/assets/ #{fetch(:user)}@#{rsync_host}:#{shared_path}/public/assets/"
execute "rm -rf public/assets"
execute "rm -rf tmp/cache/assets"
end
end
end
end
namespace :deploy do
after :updated, "assets:precompile"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment