My production environment does not have access to my subversion
repository. At first I took a look at the gateway implementation, but
that assumes the reverse (limited access to the production machines).
In other posts I've seen some people using
set :deploy_via, :copy
which is an excellent method, but I didn't want to screw with the
existing infrastructure. At this point I just wanted Capistrano to
automate some non-rails website updates with the existing setup. Sadly
my searching didn't turn up a way forward a local port to the remote
servers. Thankfully the rails code is easy enough to read and all I
had to do was add two methods.
== snip ssh_forwarding.rb ==
module Capistrano
class Configuration
module Actions
module Invocation
def forward_local_port(localport,host,remoteport)
execute_on_servers({}) do |servers|
servers.each do |s|
puts sessions[s].forward
sessions[s].forward.local(localport,'localhost',remoteport)
end
end
end
def forward_remote_port(localport,host,remoteport)
execute_on_servers({}) do |servers|
servers.each do |s|
sessions[s].forward.remote_to(localport,'localhost',remoteport)
end
end
end
end
end
end
end
== snip ==
http://pastie.caboo.se/81955
Now in my capfile I can have:
== snip capfile ==
require 'ssh_forwarding'
role :webserver, "example.com"
task :tunnelled_svn_command, :roles => :webserver do
forward_remote_port(3690,'127.0.0.1',3690)
run "cd /var/www/; svn up"
end
== snip ==
http://pastie.caboo.se/81955
The methods grab each of the open Net::SSH:Sessions for the servers in
the current role and call the Net::SSH forwarding commands.
forward_local_port is basically what is done in the gateway
implementation's forwarding. The bit that I needed was
forward_remote_port which lets me take svn from the localhost, or
whatever local net box, and forward it each of the servers.
Net:SSH forwarding methods :
http://net-ssh.rubyforge.org/api/classes/Net/SSH/Service/Forward/Driver.html
Hope this is helpful.
--
Andy
--~--~---------~--~----~------------~-------~--~----~
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/capistrano
-~----------~----~----~----~------~----~------~--~---