Heroku Buildpack: Custom SSH key
Use Custom SSH key buildpack if you need to, for example, download a dependency stored in a private repository.
Add the buildpack to your app:
heroku buildpacks:add --index 1 https://github.com/simon0191/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 assume that you named the key
Add the ssh key to your private repository account.
Encode the private key as a base64 string and add it as the
CUSTOM_SSH_KEYenvironment 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
CUSTOM_SSH_KEY_HOSTSenvironment variable of the heroku app.
# OSX $ heroku config:set CUSTOM_SSH_KEY=$(base64 --input ~/.ssh/deploy_key) CUSTOM_SSH_KEY_HOSTS=bitbucket.org,github.com # Linux $ heroku config:set CUSTOM_SSH_KEY=$(base64 ~/.ssh/deploy_key) CUSTOM_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.