TalkingQuickly / capistrano-3-rails-template

Template for deploying Rails applications with Capistrano 3
270 stars 149 forks source link

When compiling assets locally, rsync uses the wrong port #10

Open danielristic opened 10 years ago

danielristic commented 10 years ago

I'm testing deploys on vagrant but it failed during asset precompilation as rsync was using the default 22 port and vagrant is expecting port 2222 by default.

I set this up in the vagrant.rb file I use to define the deploy environment:

server '127.0.0.1:2222', user: 'deploy', roles: %w{web app db}, primary: true

But rsync still used the port 22.

So I directly modified the code in compile_assets_locally.cap to

execute"rsync -e 'ssh -p2222' -av ./public/assets/ #{role.user}@#{role.hostname}:#{release_path}/public/assets/;"

But it looks like there's probably a cleaner way to specify the port used when deploying?

christiangenco commented 10 years ago

If you set your ssh port in config/deploy/production.rb with:

set :ssh_options, {
  port: 42663
}

Then you could do:

execute "rsync -av -e 'ssh -p #{fetch(:ssh_options)[:port]}' ./public/assets/ #{role.user}@#{role.hostname}:#{release_path}/public/assets/;"

Which isn't pretty, but now you're not repeating yourself or statically defining anything in your compile_assets_locally.cap.

This would fail if ssh_options[:port] is undefined.

viktomas commented 10 years ago

@christiangenco that solution works only when you use the :ssh_options configuration, when you put the port into connection string or in server options, it won't work.

I fixed this by using upload! capistrano function. Unfortunately I didn't figure out how to connect my pull request to this issue.