Skip to content

Instantly share code, notes, and snippets.

@hone
Last active October 26, 2021 12:11
Show Gist options
  • Save hone/b0c0093374097313ab7f to your computer and use it in GitHub Desktop.
Save hone/b0c0093374097313ab7f to your computer and use it in GitHub Desktop.
Private GitHub repos with Bundler on Heroku

Setting Up Private GitHub Repos with Bundler on Heroku

To get a private GitHub repo to work on Heroku, you can leverage the netrc buildpack in conjunction with the Heroku Ruby buildpack.

When setting up the Gemfile, make sure to use the https GitHub URL. This mechanism does not work with git+ssh.

gem "some_private_gem", git: "https://github.com/org/some_private_gem.git"

GitHub OAuth Token

First, you'll need a GitHub OAuth token to be used. There's ways to do it via the commandline, but I find the personal settings page the easiest way especially if you're using 2 factor auth. Since you'll only need read access make sure to set that and restrict access to things that aren't needed like gist.

Assuming you already have a heroku app, you can set the token given that the netrc buildpack will use.

$ heroku config:set GITHUB_AUTH_TOKEN=<my-read-only-token>

Buildpacks

DISCLAIMER: Third-party buildpacks contain software that is not under Heroku’s control and are not supported by Heroku. Please inspect the source of any buildpack you plan to use and proceed with caution.

The heroku toolbelt supports chaining multiple buildpacks to be run in succession.

$ heroku buildpacks:add https://github.com/timshadel/heroku-buildpack-github-netrc.git
$ heroku buildpacks:add heroku/ruby

With all of that setup, you can new deploy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment