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.

On 11 January 2012 16:09, jsnark [email protected] wrote:

$ 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

On Jan 11, 11:55am, Colin L. [email protected] wrote:

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.

On 11 January 2012 18:06, jsnark [email protected] wrote:

Colin
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

On Jan 11, 2:52pm, Colin L. [email protected] wrote:

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 D. 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

BUNDLE_PATH: vendor/cache
BUNDLE_DISABLE_SHARED_GEMS: “1”

I guess I’d rather not have a fresh copy of ruby with each
application, so I’m back to my original problem - how to get passenger
and capistrano to set things up so that the gems in vendor/cache are
used.

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?

The command that fails on the server during deployment is: “rake
RAILS_ENV=production RAILS_GROUPS=assets assets:precompile”

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 :: ] Installing will_paginate (3.0.2)
** [out :: ]
** [out :: ] Updating .gem files in vendor/cache
** [out ::] 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 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…

On Jan 13, 3:39pm, “Steven F.” [email protected] wrote:

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.

On 11 ene, 17:09, jsnark [email protected] wrote:

$ 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?

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.

Oops. Pilot error.

set :bundle_flags, ‘–local’

did not work.

On 16 ene, 15:54, jsnark [email protected] wrote:

Oops. Pilot error.

set :bundle_flags, ‘–local’

did not work.

On Jan 16, 9:43am, jsnark [email protected] wrote:

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!

On Jan 16, 9:25am, Xuan [email protected] wrote:

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.

I found the solution. Insert the line:

require “bundler/capistrano”

into deploy.rb

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.