Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I access a private github repo from heroku?

I have a private repo that I'm trying to access when deploying to Heroku. However, Heroku doesn't let me clone the private repo, and gives me the following error (as i would expect):

Host key verification failed.
       fatal: The remote end hung up unexpectedly
       Git error: command `git clone
       '[email protected]:pr/lm-models.git'
       "/tmp/build_3r0z0znww0zda/vendor/bundle/ruby/1.9.1/cache/bundler/git/lm-models-aab025aaadbe07202b16e1db7505ae1726f8723a"
       --bare --no-hardlinks` in directory /tmp/build_3r0z0znww0zda has failed.
 !
 !     Failed to install gems via Bundler.
 !
 !     Heroku push rejected, failed to compile Ruby/rails app

I have found this, but do not want to display my username/password in clear text:

Linking heroku app to a private(organization) github repo

like image 574
Kamilski81 Avatar asked Apr 01 '13 23:04

Kamilski81


People also ask

Can Heroku access private repository?

Heroku does not have the private keys necessary to access your private Github repositories, and as such, attempts to access those private repos will fail. Rather than providing Heroku with the private keys necessary to access your Github repo, its much better to use OAuth tokens.

Can you see private GitHub repositories?

Public repositories are accessible to everyone on the internet. Private repositories are only accessible to you, people you explicitly share access with, and, for organization repositories, certain organization members.

Are Heroku git private?

No, the code is not public. Do not confuse GIT with GITHUB. When you deploy to heroku the repository is private to the owner and the added collaborators.


2 Answers

This worked for me:

  1. Generate a Github Access Token
  2. In requirements.txt list private module as follows:

    git+https://your_user_name:[email protected]/your_company/your_module.git
    
like image 82
TinaW Avatar answered Oct 20 '22 16:10

TinaW


Heroku only supports HTTP(S) Basic authentication with Git out of the box. That's unfortunate as it means you'd need to add your credentials as part of the installation URL and commit that as plain text in your list of dependencies. For your app to support SSH keys instead, do the following:

  1. Create a new SSH key which will be used by Heroku to access the GitHub repository. Choose a distinct name, e.g. id_rsa_heroku.
  2. Add the public part of the key to your GitHub account (link to settings).
  3. Use the heroku-buildpack-ssh-key: heroku buildpacks:add https://github.com/heroku/heroku-buildpack-ssh-key.git -i 1
  4. Set the private part of the key as an environment variable for your Heroku app: heroku config:set BUILDPACK_SSH_KEY=$(cat ~/.ssh/id_rsa_heroku)

From this moment, Heroku should be able to access and download code from any private repositories you have access to.

like image 24
Honza Javorek Avatar answered Oct 20 '22 18:10

Honza Javorek