Legacy Capistrano Issues

I have some apps deployed with older versions of capistrano but I still want to be able to use the latest capistrano on newer projects. Ideally I’d update the older apps to use the newer capistrano, but sometimes that requires a lot of work for not much benefit when I have a perfectly good copy of the old capistrano laying around to run those old deploy scripts with.

However, by perfectly good, I mean broken. It breaks because it doesn’t specifically require the correct versions of other gems but this you can fix. This is how I fixed it for my particular use case. I’m assuming you have a recent version of rubygems where you can use the gem method for specifying require’s gem versions.

Open up your old cap program, mine was here:
/usr/local/lib/ruby/gems/1.8/gems/capistrano-1.4.1/bin/cap

Before the “require ‘capistrano/cli’” line add the following:

gem 'net-ssh', '=1.0.10'
gem 'net-sftp', '=1.1.0'
gem 'capistrano', '=1.4.1'

I also edited my lib/tasks/capistrano.rake file to have the following code in it.

def cap(*parameters)
  begin
    require 'rubygems'
  rescue LoadError
    # no rubygems to load, so we fail silently
  end

  gem 'net-ssh', '=1.0.10'
  gem 'net-sftp', '=1.1.0'
  gem 'capistrano', '= 1.4.1'
  require 'capistrano/cli'

  Capistrano::CLI.new(parameters.map { |param| param.to_s }).execute!
end

Then I created a new symlink.

ln -s /usr/local/lib/ruby/gems/1.8/gems/capistrano-1.4.1/bin/cap /usr/local/bin/old_cap

Now I can run my old stuff and I have my old cap program as well.

Found this interesting? Share it:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Furl
  • Ma.gnolia
  • NewsVine
  • Reddit
  • TwitThis

Leave a Reply