What is the preferred way to install private github repos as node modules?


#1

I have a pipeline that runs my mocha tests, and needs to do an NPM install in order to do it. Up until this point all of our NPM packages have been public, so there’s no problem with this step.

However we are creating internal packages within our company that will remain private. During npm install, buddy fails due to the fact that it doesn’t have permission. We use ssh to install locally, and I was wondering if there is a way to do that with Buddy as well.

Edit: I changed the title, and thought I should clarify. I am not using the NPM private modules service, but rather have private repos in github that I directly reference in my package.json file.

Thanks!
Jake


#2

With the help of support, I was able to figure this out. I had to create a machine user on github and add it to my project. I think created a key pair for this user, and added the public key to github. I then took the private key and had to move it into the file system in an uploads folder. As part of the build process, I move that key to /root/.ssh/ and then add it to ssh-agent and add github to the list of known host. It looks like this

mkdir -p /root/.ssh
cp uploads/id_rsa /root/.ssh/id_rsa
chmod 600 /root/.ssh/id_rsa
eval "$(ssh-agent -s)"
ssh-add /root/.ssh/id_rsa
touch /root/.ssh/known_hosts
ssh-keyscan -H github.com >> /root/.ssh/known_hosts
npm install
npm test

#3

Thanks for posting that, Jake. Like we said:

We’re currently working on delivering new function that allows for adding a key to the pipeline (next to the environment variables). The key will be automatically available in the container. This feature should be ready in about 2 weeks.


#4

Just an update: ssh keys are now available as environment variables! I added my private key as id_rsa and now my code looks like this:

eval "$(ssh-agent -s)"
ssh-add /root/.ssh/id_rsa
touch /root/.ssh/known_hosts
ssh-keyscan -H github.com >> /root/.ssh/known_hosts
npm install
npm test

I still have to add the rsa key to ssh-agent and github to the list of known hosts, but this is much better than it was before! Thanks!


#5

Jake,
Indeed, the keys are now available from pipelines. Here are detailed instructions in case other users may need it: https://buddy.works/knowledge/deployments/how-use-ssh-keys-in-actions

Thanks for the heads up!