繁体   English   中英

捆绑器:获取部分git repo?

[英]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代码提取到新存储库中,并按照您的尝试进行安装。 我个人会寻求这种解决方案。

如果您真的不想删除它,可以尝试一下原始项目中的子模块 这种方法可能非常棘手,甚至Github也不是很鼓励。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM