|
1 | 1 | # ssh-private-key-buildpack
|
2 | 2 |
|
3 |
| -A heroku buildpack for setting the ssh private key as part of the application build. It's meant to be used with [heroku-buildpack-multi](https://github.com/heroku/heroku-buildpack-multi), before other buildpacks which require the key to be present, like installing private `npm` modules from `github`. |
| 3 | +A Heroku buildpack for setting the ssh private key as part of the application build. It's meant to be used as part of a setup [using multiple buildpacks](https://devcenter.heroku.com/articles/using-multiple-buildpacks-for-an-app), so other buildpacks can authenticate with hosts using ssh keys, for instance to install dependencies from private git repositories. |
4 | 4 |
|
5 | 5 | # Example usage
|
6 | 6 |
|
7 |
| -Upload the private key to heroku (note that the key needs to be base64 encoded). |
| 7 | +## Configure Multiple Buildpacks |
| 8 | +### _Option 1:_ Heroku CLI or Dashboard |
| 9 | +Add the buildpack to your Heroku app either using the CLI or the Heroku dashboard. The `ssh-private-key-buildpack` needs to run before any buildpack trying to get ssh access. In the following example, it runs before the `heroku/go` buildpack. |
8 | 10 |
|
9 |
| -``` |
10 |
| -heroku config:set SSH_KEY=$(cat ~/.ssh/id_rsa | base64) |
11 |
| -``` |
| 11 | + $ heroku buildpacks:set --index 1 https://github.com/debitoor/ssh-private-key-buildpack.git |
| 12 | + $ heroku buildpacks:add heroku/go |
12 | 13 |
|
13 |
| -Add a `.buildpacks` file (used by `heroku-buildpack-multi`) which contains this and the default node.js buildpack. |
| 14 | +### _Option 2:_ Use `heroku-buildpack-multi` |
| 15 | +Instead of setting the buildpacks directly with Heroku they can also be configured using a `.buildpacks` in combination with [`heroku-buildpack-multi`]( https://github.com/heroku/heroku-buildpack-multi). |
14 | 16 |
|
15 |
| -``` |
16 |
| -https://github.com/debitoor/ssh-private-key-buildpack.git#v1.0.0 |
17 |
| -https://github.com/heroku/heroku-buildpack-nodejs.git#v75 |
18 |
| -``` |
| 17 | + $ heroku buildpacks:set https://github.com/heroku/heroku-buildpack-multi.git |
| 18 | +The same example given for the CLI use would have the following `.buildpacks` file. |
19 | 19 |
|
20 |
| -Now as long as the public key is present on github and the user has the correct permissions, it's possible to install `npm` modules from private `githup` repositories. |
| 20 | + $ cat .buildpacks |
| 21 | + https://github.com/debitoor/ssh-private-key-buildpack.git |
| 22 | + https://github.com/heroku/heroku-buildpack-go |
| 23 | + |
| 24 | +## Configure SSH Key |
| 25 | + |
| 26 | +Set the private key environment variable `SSH_KEY` of your Heroku app (note that the key needs to be base64 encoded). |
| 27 | + |
| 28 | + $ heroku config:set SSH_KEY=$(cat path/to/your/keys/id_rsa | base64) |
| 29 | + |
| 30 | +By default the buildback adds Github to `known_hosts`. However you can configure your app to allow custom hosts, too. All that's needed is the set `SSH_HOSTS` for you app to a comma-separated list of hosts, e.g. `git@github.com,example.com` |
| 31 | + |
| 32 | + $ heroku config:set SSH_HOSTS="git@github.com,example.com" |
0 commit comments