[英]bundler: fetch partial git repo?
我有一個Rails項目,其根目錄包含my_gem
文件夾:
my_repo
├── app
├── config
├── Gemfile
├── Gemfile.lock
├── db
├── lib
├── log
├── my_gem <-- the gem folder
├── public
├── Rakefile
├── README.md
├── script
├── test
├── tmp
└── vendor
我通過在Gemfile中添加以下行,在另一個項目中使用了這個gem:
git 'git@gitlab.mydomain.com:qosenergy/my_repo.git', :branch => 'master' do
gem 'my_gem'
end
它可以正常工作,除了獲取所有存儲庫(代表數百兆字節(相對於唯一的my_gem
文件夾小於1Mo)),並且當我從使用gem的存儲庫構建docker映像時,這是有問題的:因為超過60%圖像大小由my_repo
包含的全軌應用程序my_repo
。
我如何才能保留這種行為的優勢,而僅保留my_gem
文件夾而不是完整的存儲庫?
根據捆綁程序文檔 ,您似乎可以在給定存儲庫中獲取一個或多個gem。
例如, Rails回購包含幾個寶石:actioncable,actionmailer,actionpack ...
指定包含多個.gemspec文件的git存儲庫應被視為gem源
git 'https://github.com/rails/rails.git' do gem 'railties' gem 'action_pack' gem 'active_model' end
如果您my_gem
包含的項目有一個給定的.gemspec
,你應該能夠不用下載它包含完整的應用程序進行安裝。 如果以這種方式完成此操作,則可以考慮其他選擇。
Git稀疏簽出
Git提供了稀疏簽出的功能,用於僅克隆存儲庫中的給定路徑。 您可以閱讀此博客的一些用例:
$ mkdir pcl-examples
$ cd pcl-examples #make a directory we want to copy folders to
$ git init #initialize the empty local repo
$ git remote add origin -f https://github.com/PointCloudLibrary/pcl.git #add the remote origin
$ git config core.sparsecheckout true #very crucial. this is where we tell git we are checking out specifics
$ echo "examples/*" >> .git/info/sparse-checkout" #recursively checkout examples folder
$ git pull --depth=2 origin master #go only 2 depths down the examples directory
這個答案可能使這個概念更加清晰,但是我沒有弄清楚如何在Gemfile
利用它。
其他調試
由於您正在構建Docker映像,因此可以參考此清單以了解Rails錯誤。 但是,看來您沒有遇到任何錯誤,而只是圖像大小問題。
幾個干凈的解決方案
我想最干凈的解決方案是將gem代碼提取到新存儲庫中,並按照您的嘗試進行安裝。 我個人會尋求這種解決方案。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.