Skip to content

Instantly share code, notes, and snippets.

@Jesus
Forked from buntine/deploy.rb
Last active June 2, 2016 23:31
Show Gist options
  • Save Jesus/80ef0c8db24c6d3a2745 to your computer and use it in GitHub Desktop.
Save Jesus/80ef0c8db24c6d3a2745 to your computer and use it in GitHub Desktop.
# 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
# compile assets locally
run_locally do
with rails_env: fetch(:stage) do
execute :bundle, "exec rake assets:precompile"
end
end
# rsync to each server
local_dir = "./public/assets/"
on roles(:web) do
# this needs to be done outside run_locally in order for host to exist
remote_dir = "#{host.user}@#{host.hostname}:#{shared_path}/public/assets/"
run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }
end
# clean up
run_locally { execute "rm -rf #{local_dir}" }
end
@aq1018
Copy link

aq1018 commented Aug 2, 2014

👍

@toymachiner62
Copy link

My ssh port is not the default port 22.

How can I tweak this so I can specify a port in my connection?

remote_dir = "#{host.user}@#{host.hostname}:#{shared_path}/public/assets/"    
run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }

@toymachiner62
Copy link

I figured it out, you need to change

run_locally { execute "rsync -av --delete #{local_dir} #{remote_dir}" }

to this:

run_locally { execute "rsync -av -e 'ssh -p 2222' --delete #{local_dir} #{remote_dir}" }

@twetzel
Copy link

twetzel commented Sep 1, 2014

Thanks !

made another version, includes some changes to fully integrate in capistrano flow (and make rollback work)

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