Wolfmans Howlings

A programmers Blog about Programming solutions and a few other issues

Allow a different local and remote subversion repository path for Capistrano

Posted by Jim Morris on Wed Nov 15 14:04:28 -0800 2006

One of the things that bugs me about Capistrano is the requirement that access to the remote subversion repository have the same path from the local machine and the remote machine. This is never the case in my experience.

I have been getting around it by setting the path to svn://localhost/... and running ssh locally to port forward the SVN port to the remote host. This sucks as I usually forget to run ssh in another window first.

So I added an optional configuration variable to be set in deploy.rb called local_repository_path, so now you set the repository path as normal, which is the path the remote server uses to access the SVN repository, and you set the path that the local machine (your workstation) uses to access the same repository...

set :repository, "svn://localhost/#{application}/trunk"
set :local_repository_path, "svn+ssh://myremotehost.com/path/to/repostitory/#{application}/trunk"

Ideally one would patch the Capistrano distribution to achieve this, but thanks to the magic of ruby you can patch it from your own setup so I put the following into lib/tasks/patch_capistrano.rb

Then simply add this line to your config/deploy.rb...

require 'lib/tasks/patch_capistrano'

and everything works fine now.

Note there are only two scm methods that access SVN from the local machine, latest_revision and diff. I have patched both.

I'll tidy this up, make the default for local_repository_path be repository, and submit the patch to the Capistrano folks, who will hopefully commit it to the source code, as it won't affect existing users, but will make the rest of us a little happier.

Posted in Rails  |  Tags rails,capistrano,subversion  |  4 comments

Comments

  1. Marcelo said on Wed Feb 14 10:13:11 -0800 2007
    Thanks a lot!
  2. Rob Dupuis said on Tue Oct 16 06:48:17 -0700 2007
    When reading variable xxx In capistrano 2.1 (poss 2.0 too?) the scm recipes check for a` local_xxx` equivalent. So you can just use `:local_repository` if you need to configure a different local repo url.
  3. jxh said on Sun Jan 11 20:42:55 -0800 2009
    To clarify that bit about "local":

    For the case where your desktop needs to reach svn with ssh, but the svn repository happens to be on the same machine where you're deploying your app, your `deploy.rb` needs to look something like this:

        set :repository, "file:///home/svn/main/rails/myapp"
        set :local_repository, "svn+ssh://myserver.my.domain/main/rails/myapp"

    Note the underscore needed after "local".
  4. wolfmanjm said on Sun Jan 11 20:57:56 -0800 2009
    I fixed it in the Dupuis comment. Please note that Capistrano 2 has a completely different way of doing things.

(leave email »)