在后续的bundle安装上跳过本机扩展重新编译

时间:2021-11-19 00:18:53

My production deployments take a few extra minutes due to time it takes to install nokogiri gem (1.6.0). I understand this is because installing the gem triggers native extension compilation.

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

Note that I have packaged my bundle and checked it into DVCS

请注意,我已打包我的包并将其检入DVCS

bundle package

Is there a way to avoid recompilation of native extensions if nothing else has changed, so that deployments are faster?

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

Update:

I use Opscode Chef to deploy (chef-solo to be specific)

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

environment is: Ubuntu 12.04LTS 64bit Ruby 193-p448

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

1 个解决方案

#1


4  

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.

默认情况下,Bundler会将gem安装到环境变量BUNDLE_PATH指向的文件夹中。 BUNDLE_PATH的默认值是vendor / bundle。因此,所有gem都安装在/ vendor / bundle文件夹中,该文件夹恰好是一个私有文件夹(对于每个版本的Rails应用程序)。安装新版本的Rails应用程序时,vendor / bundle不存在。因此Bundler安装/预编译每个gem。它从供应商/缓存中获取宝石,这比从rubygems.org下载宝石更好,但它仍然无法避免编译本机扩展。

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

我们可以通过将--path / shared / path传递给bundle install命令行来覆盖它。这将确保gems始终安装在/ shared / path中,所有版本(Rails应用程序)都可以访问。

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

使用这种方法,bundler不会尝试重新安装/重新编译gem,因为它找到了已经安装的gem。

so, this is the magic command that worked for me

所以,这是对我有用的神奇命令

bundle install --local --deployment --path /shared/bundle --without development test

#1


4  

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.

默认情况下,Bundler会将gem安装到环境变量BUNDLE_PATH指向的文件夹中。 BUNDLE_PATH的默认值是vendor / bundle。因此,所有gem都安装在/ vendor / bundle文件夹中,该文件夹恰好是一个私有文件夹(对于每个版本的Rails应用程序)。安装新版本的Rails应用程序时,vendor / bundle不存在。因此Bundler安装/预编译每个gem。它从供应商/缓存中获取宝石,这比从rubygems.org下载宝石更好,但它仍然无法避免编译本机扩展。

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

我们可以通过将--path / shared / path传递给bundle install命令行来覆盖它。这将确保gems始终安装在/ shared / path中,所有版本(Rails应用程序)都可以访问。

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

使用这种方法,bundler不会尝试重新安装/重新编译gem,因为它找到了已经安装的gem。

so, this is the magic command that worked for me

所以,这是对我有用的神奇命令

bundle install --local --deployment --path /shared/bundle --without development test