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?
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...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With