Charlie Martin Charlie Martin - 2 years ago 60
Node.js Question

Can I use npm private github dependencies on Heroku

I'm trying to push a Node.js application to Heroku. The app uses npm to fetch private github repositories, which are specified in

, like this...

"dependencies": {
"my-private-dep": "github:my-org/my-repo"

The build fails during the
npm install
phase because the github host keys are not in the containers

remote: npm ERR! Host key verification failed.

This is expected behavior of SSH. Does Heroku provide a workaround for this? For example, dokku, which uses the same buildpack has a host keys plugin that will inject the host keys into the container before each build, which resolves this issue. Does Heroku have a similar solution?

Answer Source

It turns out that there is a buildpack that makes this relatively easy -

However, I found that, for whatever reason, setting the SSH_HOSTS environment variable was not working correctly for me - according to the docs, it is supposed to set Github by default, and then you can add others if you like... I am actually using Gitlab for this particular project, but found that when I set the config like so:

$ heroku config:set SSH_HOSTS="[email protected]"

it was not being detected. I ended up cloning the buildpack and changing bin/compile line 13 to

ssh_hosts=${SSH_HOSTS:-"[email protected]"}

and just pushing it up to my own repo to use for this project. Worked like a charm.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download