Use SSH key buildpack if you need to, for example, download a dependency stored in a private repository.
Based on http://stackoverflow.com/a/29677091/3303182.
-
Add the buildpack to your app:
heroku buildpacks:add --index 1 https://github.com/chrise86/custom-ssh-key-buildpack
-
Generate a new SSH key (https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/)
For this example I will suppose that you named the key
deploy_key
. -
Add the ssh key to your private repository account.
-
Encode the private key as a base64 string and add it as the
SSH_KEY
environment variable of the heroku app. -
Make a comma separated list of the hosts for which the ssh key should be used and add it as the
SSH_KEY_HOSTS
environment variable of the heroku app.# OSX $ heroku config:set SSH_KEY=$(base64 --input ~/.ssh/deploy_key) SSH_KEY_HOSTS=bitbucket.org,github.com # Linux $ heroku config:set SSH_KEY=$(base64 ~/.ssh/deploy_key) SSH_KEY_HOSTS=bitbucket.org,github.com
-
Deploy your app and enjoy :)
I needed to install dependencies stored in private repositories but I didn't want to hardcode passwords in the code. I found a solution in StackOverflow but it only worked for the node buildpack so I decided to create this technology agnostic buildpack.