LoginSignup
52
37

More than 5 years have passed since last update.

GitHubのプライベートリポジトリのgemをbundle installする

Posted at

結論

bundler 1.11以上で export BUNDLE_GITHUB__COM=<username>:<personal access token> する

補足

諸般の事情でプライベートリポジトリで管理したいgemがある場合、bundle installするにはどのようにすればよいのか。

ぐぐると、こんなかんじで、GitHubのuser/passwordやpersonal access tokenを環境変数で渡す例が見つかるんですが、

How can I specify a gem to pull from a private github repository?

gem 'my_gem', :git => 'https://my_username:my_password@github.com/my_github_account/my_repo.git', :ref => 'revision_no'

Building a project with private gems

gem 'ventana', git: "https://#{ENV['GITHUB_TOKEN']}:x-oauth-basic@github.com/thoughtbot/ventana.git"

この方法は、Gemfile.lockにパスワードやトークンが残ってしまうので、セキュリティ的には片手落ちでよくありません。

もうちょっと調べてみると、bundler 1.11以上であれば、Gemfileに書かなくても環境変数から読んでくれるようになってました。

github.comにホストしている場合は、 BUNDLE_GITHUB__COM という環境変数でユーザ名とパーソナルアクセストークンをexportしておくと見てくれます。

export BUNDLE_GITHUB__COM=<username>:<personal access token>

試してないですが、github.com以外もドメインに対応した同じルールで環境変数を見てくれるみたい。
あとbundle configにセットする方法もある。bundlerの公式ドキュメントは以下をどうぞ。

52
37
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
52
37