Search code examples
ruby-on-railsrubyrubygemscapistranorelease-management

How do I use frozen Capistrano?


Backstory

I'm on Rails 2.1 and need to freeze the Capistrano gem to my vendor folder (as my host has broken their cap gem dependencies and I want to make myself as independent as possible).

On my local windows machine I've put the following my environment.rb

config.gem "capistrano", :version => "2.5.2"
config.gem "net-ssh", :lib => "net/ssh", :version => "2.0.4"
config.gem "net-scp", :lib => "net/scp", :version => "1.0.1"
config.gem "net-sftp", :lib => "net/sftp", :version => "2.0.1"
config.gem "net-ssh-gateway", :lib => "net/ssh/gateway", :version => "1.0.0"

The gems were already installed and so I froze them. Checking ...

>rake gems
...
[F] capistrano = 2.5.2
[F] net-ssh = 2.0.4
[F] net-scp = 1.0.1
[F] net-sftp = 2.0.1
[F]net-ssh-gateway = 1.0.0

I then commit to SVN locally and update on the prod Linux box.

Problem

When I try and run my frozen version of Capistrano I get the following error.

$ ./vendor/gems/capistrano-2.5.2/bin/cap deploy-with-migrations 
./vendor/gems/capistrano-2.5.2/bin/cap:3:in `require': no such file to load --capistrano/cli (LoadError)
    from ./vendor/gems/capistrano-2.5.2/bin/cap:3

Any ideas what I've done wrong?

Update

See new related question


Solution

  • You haven't done anything wrong. You're seeing this issue because the cap file under capistrano/bin/cap isn't meant to be run as a stand-alone. You'll see the same result if you try to run it from your primary gem folder. The cap executable (stored at /usr/bin/cap on a standard linux install) requires rubygems, registers capistrano and then loads the capistrano/bin/cap file.

    One solution to this would be to add require 'rubygems' to your capistrano/bin/cap file:

    #!/usr/bin/env ruby
    require 'rubygems'
    require 'capistrano/cli'
    Capistrano::CLI.execute
    

    If you don't want to modify capistrano/bin/cap you could specifically include the rubygems library when you run it using the -r flag. Your given command would look like this:

    $ ruby -r rubygems ./vendor/gems/capistrano-2.5.2/bin/cap deploy-with-migrations