2011-12-19 98 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 
相關問題