Skip to content

Instantly share code, notes, and snippets.

@buntine
Created July 14, 2014 01:36
Show Gist options
  • Save buntine/bf9d27ebbacba53e5c32 to your computer and use it in GitHub Desktop.
Save buntine/bf9d27ebbacba53e5c32 to your computer and use it in GitHub Desktop.
Rails 4, Capistrano 3.2.1+ local precompilation using rsync
# Clear existing task so we can replace it rather than "add" to it.
Rake::Task["deploy:compile_assets"].clear
desc "Precompile assets locally and then rsync to web servers"
task :compile_assets do
on roles(:web) do
rsync_host = host.to_s
run_locally do
with rails_env: :production do ## Set your env accordingly.
execute :bundle, "exec rake assets:precompile"
end
execute "rsync -av --delete ./public/assets/ #{fetch(:user)}@#{rsync_host}:#{shared_path}/public/assets/"
execute "rm -rf public/assets"
# execute "rm -rf tmp/cache/assets" # in case you are not seeing changes
end
end
end
@Jesus
Copy link

Jesus commented Jul 30, 2014

Thanks for sharing this, I've found it very useful.

I've forked the it to precompile the assets only once. The code above would run assets:precompile once for each server in role :web. https://gist.github.com/Jesus/80ef0c8db24c6d3a2745

@snackycracky
Copy link

thx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment