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

前端 未结 8 1990
攒了一身酷
攒了一身酷 2020-12-02 07:51

I have a private repository on Github that I want to use. I deploy my app to Heroku. How can I specify a private repository as the source on my gemfile? I imagine it wouldn\

相关标签:
8条回答
  • 2020-12-02 08:18

    The best way I've found to deploy a gem pulled from a private repo is to use GitHub's OAuth access. To do so:

    1. Create a GitHub user with access to the repo in question (best for teams – if you're okay exposing your personal access tokens, you can simply use your own account).

    2. Create an GitHub OAuth token for the user. It's dead simple to do this over the GitHub API just using curl; see the OAuth API for more.

    3. Add the token to the git url in your Gemfile. Example:

    gem 'mygem', git: 'https://xxx123abc:x-oauth-basic@github.com/user_or_team/mygem.git'
    

    I'm currently using this method on Heroku and it works great. The beauty is that you don't have to expose your own personal information, and you can revoke or regenerate the token at any point if something is compromised.

    0 讨论(0)
  • 2020-12-02 08:19

    I found that if I have access from my terminal to github (by uploading an ssh key to github), I can simply do:

    gem 'my_gem', :git => 'git@github.com:my_user/my_repo.git', :ref => 'revision_no'
    

    without polluting my code with my git username or password

    0 讨论(0)
提交回复
热议问题