Created
March 29, 2013 15:00
-
-
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!
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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