2011-12-19 81 views
10

我在我的电脑上有一堆宝石,我想在厨师食谱中使用。是否可以从本地缓存中捆绑/安装宝石?

我知道这是可能把他们像的/ tmp /宝石,只是一个目录:

cd /tmp/gems 
gem install *.gem 

是否有可能把所有的宝石在一个目录下我可以捆绑安装它们无需下载再次?

cd /somedir/my_rails_project 
bundle 

我想节省带宽。另外

gem "nokogiri", :path => "~/sw/gems/nokogiri" 

,您可以设置在它与宝石本地Git仓库,写的Gemfile类似这样的:

回答

4

您可以向Gemfile(例如,从文档)添加本地目录

gem "gem1", :git => "file:///tmp/gems", 
      :branch => "gem1" 
+0

这是一个解决方案,但它会更好,如果它是透明的(没有变化我的Gemfile)。 – ayckoster 2011-12-19 22:55:18

+0

您可以从缓存中为安装gem(使用gem install)编写脚本。 – avy 2011-12-20 10:26:39

+0

@avy:我是那么做的。 – ayckoster 2012-01-01 19:50:09

24

bundle install --local应该是你想要的。从bundle-install手册页:

 
--local 
    Do not attempt to connect to rubygems.org, instead using just the 
    gems located in vendor/cache. Note that if a more appropriate 
    platform-specific gem exists on rubygems.org, this will bypass 
    the normal lookup. 
+0

如果部署(与capistrano或类似的)使用 - 部署,并确保符号链接供应商/捆绑共享/ vendor_bundle或类似(如http://bundler.io/v1.5/deploying.html中所述) – 2014-03-20 11:31:11

2

使用

bundle package 

锁,然后缓存宝石到./vendor/cache。

软件包命令会将 软件包中宝石的.gem文件复制到./vendor/cache中。之后,当您运行软件包安装时,Bundler将使用缓存中的宝石,优先于 ruby​​gems.org上的宝石。

http://bundler.io/v1.6/bundle_package.html

0

如果你想使用本地缓存的CI加快bundle install,例如为目的时,码头工人,容器用于运行测试,你可以使用--path。这将使用给定路径中的宝石,除非它们不存在,否则它会将它们下载到该位置。

这假设CI构建可以在码头集装箱内安装持久性卷。因此,举例来说,如果CI机器有一个目录/var/cache/drone可安装在泊坞窗容器为./cache那么你可以做:

bundle install --without=development --quiet --path=cache