passenger does not see gems in vendor/cache

I am using capistrano v2.9.0 to deploy to a ubuntu server running
apache v2.2.12, passenger v3.0.4, ruby v1.9.2 and rails v3.0.1. When
I deploy a new application, I often get error messages like:

Could not find net-ssh-2.2.2 in any of the sources
(Bundler::GemNotFound)

The missing gem is actually in the vendor/cache directory, but it is
being ignored. For a while I was globally installing these missing
gems, but recently I found that by running the command:

$ bundle install --path vendor/cache

after deploying the application, passenger would use the gems in the
application.

Why do I need to do this extra step and why can't capistrano do it for
me?

Correction. I'm actually running rails v3.0.7.

I am using capistrano v2.9.0 to deploy to a ubuntu server running
apache v2.2.12, passenger v3.0.4, ruby v1.9.2 and rails v3.0.1. When
I deploy a new application, I often get error messages like:

Could not find net-ssh-2.2.2 in any of the sources
(Bundler::GemNotFound)

The missing gem is actually in the vendor/cache directory, but it is
being ignored. For a while I was globally installing these missing
gems, but recently I found that by running the command:

$ bundle install --path vendor/cache

My understanding (which may be faulty) is that the --path option tell
bundle install where to put the gems, so this command installs the
gems to vendor/cache.

after deploying the application, passenger would use the gems in the
application.

Why do I need to do this extra step and why can't capistrano do it for
me?

Because that is what bundle install is for, to install the appropriate
gems as defined by Gemfile and gemfile.lock.
The one thing I am not sure of is why it did not work when the gems
were already in vendor/cache. How did you get them there in the first
place?

Colin

In my development environment I used the command:

$ bundle pack

to get the gems into vendor/cache. I then committed them to
subversion and

$ cap deploy

copied them from subversion to the target machine.

So the question is, what is the difference between
bundle pack
and
bundle install --path vendor/cache

Colin

I found the pack command in "Agile Web Development with Rails", fourth
edition on page 235. I stumbled across the install command while
researching this issue on the web.

Looking into this I see one big difference:

$ bundle install --path vendor/cache

installs all of ruby in the directory vendor/cache/ruby! It also
creates a file .bundle/config containing:

$ cat .bundle/config

I am having the same issue(s). It appears that bundle puts the gems into
vendor/cache, but the application (or capistrano during install?) is not
looking for them there. The installation fails, but examining
shared/cached-copy/vendor/cache on the server (deployment destination)
shows the "missing" gems are there.

Where did you run "bundle install --path vendor/cache"? On the
development machine, or the server?

Has there been any progress with a work-around?

By the way... running "bundle install --path vendor/cache" on the
development system, then re-deploying did not fix the problem -- the
deploy still failed at the assets compile step.

To get it to deploy I have to shell into the server, cd to
"shared/cached-copy" and then run "bundle pack" to install the missing
gems. After that the project will deploy, at least until the gem list is
changed again.

Well, this makes little sense to me, but it is a work-around for this
problem.

Add the following line to your deploy.rb file:

   before "deploy:assets:precompile", :bundle_install

I've also run (on the server) "bundle config path vendor/cache" and
placed "export BUNDLE_PATH=vendor/cache" in the .bashrc file.

Now, before precompiling the assets, the bundler installs the gems,
apparently into vendor cache. The last few lines are:

** [out :: <server name>] Installing will_paginate (3.0.2)
** [out :: <server name>]
** [out :: <server name>] Updating .gem files in vendor/cache
** [out ::<server name>] Your bundle is complete! It was installed into
./vendor/cache
    command finished in 103066ms

and the deployment continues to completion.

The end of my deploy.rb file looks like...

# This is a hack to avoid deployment failure on the assets:precompile
step
# Failure is "Could not find <some gem> in any of the sources"
# seems to be a bundler problem, as all gems are in vendor/cache, and
shouldn't need
# a bundle:install command
before "deploy:assets:precompile", :bundle_install

after "deploy:update_code", :bundle_install
desc "install the necessary prerequisites"
task :bundle_install, :roles => :app do
  run "cd #{release_path} && bundle install"
end

See here for an explanation to this issue, that was presumably closed
last September...

https://github.com/capistrano/capistrano/issues/81

Where did you run "bundle install --path vendor/cache"? On the
development machine, or the server?

I ran the bundle install command on the server after deploying the
application.

Has there been any progress with a work-around?

No. Based on your other responses, I'm going to try running:

$ bundle config --path vendor/cache

on the server after deployment. If this works, I'll play around with
changing deploy.rb to try to get capistrano to perform this action.

One big difference between our applications is I am still on Rails 3.0
and you appear to be on Rails 3.1.

If you add '--local' to your 'set :bundle_flags' statement, capistrano
will automatically look into vendor/cache for the gems during the
deploy process without extra work.
They should be previously packaged with bundle package.

Thank you. That's what I needed.

Oops. Pilot error.

set :bundle_flags, '--local'

did not work.

Usually it looks more like:
set :bundle_flags, "--deployment --local --without development test"

--deployment has several effects, which you can read at bundler page
as they are qute a few to write them here, specific to deployment
environments
--without avoids installing gems grouped on :development and :test on
your Gemfile

Anyway, you should post your error messages for further help if this
doesn't solve them.

Good luck!

Could not find net-ssh-2.2.2 in any of the sources
(Bundler::GemNotFound)

$ ls -l vendor/cache/net*
-rw-rw-r-- 1 xxx xxx 27136 2012-01-17 08:44 vendor/cache/net-
scp-1.0.4.gem
-rw-rw-r-- 1 xxx xxx 61440 2012-01-17 08:44 vendor/cache/net-
sftp-2.0.5.gem
-rw-rw-r-- 1 xxx xxx 133120 2012-01-17 08:44 vendor/cache/net-
ssh-2.2.2.gem
-rw-rw-r-- 1 xxx xxx 18432 2012-01-17 08:44 vendor/cache/net-ssh-
gateway-1.1.0.gem

I added:

set :bundle_flags, "--deployment --local --without development test"

to deploy.rb and then reran

$ cap deploy

Is tthat correct? I could not find set :bundle_flags in the
capistrano documentation.

I found the solution. Insert the line:

require "bundler/capistrano"

into deploy.rb