开发者

Bundler Capistrano question: How does Rails know where my gems are?

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 thes开发者_开发问答e? 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...


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

Docs are here.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜