8

由于安装 nokogiri gem (1.6.0) 需要时间,我的生产部署需要额外的几分钟。我知道这是因为安装 gem 会触发本机扩展编译。

请注意,我已打包我的捆绑包并将其签入 DVCS

bundle package

如果没有其他任何改变,有没有办法避免重新编译本机扩展,以便部署更快?

更新:

我使用 Opscode Chef 进行部署(具体来说是chef-solo)

环境为:Ubuntu 12.04LTS 64bit Ruby 193-p448

4

1 回答 1

5

I found a way to do this. Here is the explanation:

Bundler, by default installs gems into a folder pointed by the environment variable BUNDLE_PATH. The default value of BUNDLE_PATH is vendor/bundle. Hence all gems are installed in /vendor/bundle folder, which happens to be a private folder (for each version of the Rails application). When a new version of the Rails application is installed, vendor/bundle does not exist. Hence Bundler installs/precompiles each gem. It picks up the gems from vendor/cache which is a good saving over downloading the same from rubygems.org, but it still cannot avoid compilation of native extensions.

We can override this by passing --path /shared/path to the bundle install command line. This will ensure that the gems are always installed in /shared/path, which is accessible to all versions (of the Rails application).

With this approach, bundler will not try to reinstall/recompile a gem, since it finds the same already installed.

so, this is the magic command that worked for me

bundle install --local --deployment --path /shared/bundle --without development test
于 2013-09-26T07:38:45.483 回答