Skip to content

Instantly share code, notes, and snippets.

@phinze
Created March 29, 2013 15:00
Show Gist options
  • Save phinze/5271374 to your computer and use it in GitHub Desktop.
Save phinze/5271374 to your computer and use it in GitHub Desktop.
no access to git from your production app box? still want to use git to deploy so you are dealing in SHAs/clones and not timestamps/tars? access your repo using a reverse ssh tunnel!
# config/deploy.rb
$: << File.expand_path('../../lib', __FILE__)
require 'capistrano_hacks/reverse_tunnel'
set :scm, :git
set :local_repository, '.'
set :reverse_tunnel_port, 52222
set :repository, Capistrano::Hacks.tunneled_repository_url(self)
set :ssh_options, { :forward_agent => true }
# lib/capistrano_hacks/reverse_tunnel.rb
require 'etc'
module Capistrano
module Hacks
def self.tunneled_repository_url(configuration)
user = Etc.getlogin
path = Dir.pwd
host = 'localhost'
port = configuration.fetch(:reverse_tunnel_port)
"ssh://#{user}@#{host}:#{port}#{path}"
end
end
# Monkey patch the connection factory to make the tunnel
class Configuration
module Connections
class DefaultConnectionFactory #:nodoc:
def connect_to(server)
connection = SSH.connect(server, @options)
connection.forward.remote_to(22, 'localhost', @options.fetch(:reverse_tunnel_port))
connection
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment