8

I'm using the standard bundler/capistrano recipe that installs all necessary gems on the server after deploy:update_code

Works like a charm and has simplified my life significantly.

I'm using Rails 2.3.10 and 'patched' the boot.rb and created the preinitializer as was necessary.

My question is, how does Rails know that my gems reside in the shared/bundle directory, and how does it know to use these? Is this directory somehow automatically added to the load path? How do these gems take precedent over system gems?

2 Answers 2

11

jdl, thanks for the heads up on where to look. Here's my understanding of what happens.

Bundler automatically installs the gems into shared/bundle, as specified using bundle_dir from the Gemfile, it defaults to this:

# (line 39 bundler/deployment.rb)
set :bundle_dir, File.join(fetch(:shared_path), 'bundle')

:shared_path comes from capistrano

So that's step one of installing the gems. Now, as far as I understand, when you specify a directory to install gems into, Bundler always modifies the .bundle/config in the root dir (ie where the Gemfile is located). This is what mine looks like after doing that bundle install to the shared dir:

--- 
BUNDLE_DISABLE_SHARED_GEMS: "1"
BUNDLE_WITHOUT: development:test
BUNDLE_FROZEN: "1"
BUNDLE_PATH: /mnt/apps/my_app/shared/bundle

Then, (as pointed out by jdl) the GEM_HOME gets set based off this .bundle/config.

The method configure_gem_home_and_path in bundler.rb sets ENV['GEM_HOME'] and it's based off of some settings, that, through a convoluted process end up getting the BUNDLE_PATH from your .bundle/config.

whew...

0

The GEM_HOME environment variable is what you're looking for.

Docs are here.

4
  • but my question is... how is GEM_HOME pointing to my shared/bundle directory, which I've never explicitly set this. I'm assuming Bundler does some magic, but I can't see where.
    – brad
    Mar 17, 2011 at 15:37
  • Sorry, I don't have more time for this. Look in bundler.rb in the Bundler gem. You should find something in there that modifies GEM_HOME and GEM_PATH. Trace that code, and I'll bet you find where it's grabbing the gems you're referring to.
    – jdl
    Mar 17, 2011 at 19:42
  • see my post below, think i got it answered
    – brad
    Mar 18, 2011 at 15:04
  • I think this answer is not related to capistrano but general bundler usage Nov 1, 2018 at 20:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.