簡體   English   中英

用於開發的本地寶石路徑和用於生產的遠程Git回購

[英]Local Gem Path For Development And Remote Git Repo For Production

我有一個我正在本地工作的寶石,由項目使用。

如果我使用path指定gem的位置,我可以進行更改,項目會選擇新的代碼:

gem 'example', :path => "~/path/to/gems/example"

但是,當我推送到Heroku時,捆綁失敗,因為Heroku無法訪問本地計算機上的gem源。

所以我可以將寶石源推送到遠程倉庫並將寶石源指向那里:

gem 'example', :github => 'example/example', :branch => 'example_feature'

但是我現在需要將更改推送到此repo,然后更新gem以獲取項目中的新變化:

$ cd ~/path/to/gems/example
$ git c -a -m "Update gem"
$ git push origin example_feature
$ cd ~/path/to/projects/project
$ gem update example

通過為我的本地倉庫設置本地覆蓋,我可以減輕這種痛苦:

$ bundle config local.example ~/path/to/gems/example

但是,如果我想在我的項目中進行新的更改,每次更改gem源時,我仍然需要將更改的文件添加到git,commit,然后是$ gem update example

有沒有辦法讓我的項目自動獲取本地更改(就像我使用path ),但仍然在生產中使用遠程倉庫?

在v1.2之前的Bundler

通過Gemfile,

group :development, :test do
  gem 'example', :path => "~/path/to/gems/example"
end

group :production do
  gem 'example', :github => 'example/example', :branch => 'example_feature'
end

...或者,使用相對路徑到寶石並確保Heroku在同一位置看到寶石,

gem 'example', :path => "../../gems/example"

...或者,嘗試在捆綁器http://bundler.io/v1.3/deploying.html中使用--deployment標志,它應該將您的寶石源與應用程序捆綁在一起,然后您可以將其提交到應用程序的git,以便理論Heroku然后應該使用本地副本而不是使用git來獲取寶石源(我在理論上說是因為Heroku有它自己的怪癖)

Bundler v1.2及更高版本

http://bundler.io/v1.2/man/bundle-config.1.html#LOCAL-GIT-REPOS

Bundler還允許您在本地使用git存儲庫而不是使用遠程版本。 這可以通過設置本地覆蓋來實現:

bundle config local.GEM_NAME /path/to/local/git/repository

例如,為了使用本地Rack存儲庫,開發人員可以調用:

bundle config local.rack ~/Work/git/rack

現在,不使用簽出遠程git存儲庫,而是使用本地覆蓋。 與路徑源類似,每次本地git存儲庫更改時,Bundler都會自動獲取更改。 這意味着本地git repo中的提交會將Gemfile.lock中的修訂更新為本地git repo修訂版。 這需要與git子模塊一樣注意。 在推送到遠程之前,您需要確保已按下本地覆蓋,否則您可能指向僅存在於本地計算機中的提交。

Bundler會進行許多檢查以確保開發人員無法使用無效引用。 特別是,我們強制開發人員在Gemfile中指定一個分支以使用此功能。 如果Gemfile中指定的分支與本地git存儲庫中的當前分支不匹配,Bundler將中止。 這可確保開發人員始終針對正確的分支進行操作,並防止意外鎖定到其他分支。 最后,Bundler還確保Gemfile.lock中的當前版本存在於本地git存儲庫中。 通過這樣做,Bundler強制您獲取遙控器中的最新更改。

正如@bbozo所提到的,當你在gemfile中使用git存儲庫時,你可以使用bundle本地覆蓋進行開發 ,它將在你的Gemfile.lock中存儲修訂哈希。 在生產時,這些精確的修訂版哈希將在運行bundle install時檢出。

Gemfile:gem'example gem 'example', git: 'https://github.com/your_name/example.git', branch: :master

Bundle config shell命令: bundle config local.example /path/to/local/git/repository

Gemfile.lock(自動生成): GIT remote: https://github.com/your_name/example.git revision: b9270e61abb89e1ff77fb8cfacb463e4d04388ad branch: master

請注意,在“example”git存儲庫中提交后,您需要在主應用程序上運行bundle install,以便重建Gemfile.lock以包含新的版本哈希。 我建議使用下面的gem,因為它可以為您自動執行此過程,也可以幫助其他方案。 有關詳細信息,請參閱gem頁面:

https://github.com/EPI-USE-Labs/git-bundle

我在互聯網上找到的最佳解決方案https://rossta.net/blog/how-to-specify-local-ruby-gems-in-your-gemfile.html

bundle config local.tacokit / path / to / tacokit

在Gemfile中使用gem“tacokit”,github:“rossta / tacokit”,分支:“master”

這個東西是工作和測試的解決方案

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM