Skip to content

Instantly share code, notes, and snippets.

@xdevmaycry
Last active May 3, 2023 02:00
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save xdevmaycry/95a94cb0cfea03cfe9aa2340f89aff80 to your computer and use it in GitHub Desktop.
Save xdevmaycry/95a94cb0cfea03cfe9aa2340f89aff80 to your computer and use it in GitHub Desktop.
Setup repo deploy key to allow private NPM Package hosted on Github.com be read by CircleCI

Setup repo deploy key to allow private NPM Package hosted on Github.com be read by CircleCI

Takes about 2 minutes

1. Add the private package to your project and test the git link

GitHub, private repo:

$ npm install git+ssh://git@github.com/username/my-new-project.git#master

2. Setup Deploy Key for the private Github Repo

  1. Open Git Bash.

  2. Paste the text below, substituting in your GitHub email address.

$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

## when prompt, save the key as /home/username/.ssh/reponame_rsa
  1. Copy the content of the generated public key (~/.reponame_rsa.pub)

  2. Visit your repo > Settings > Deploy Keys > Add Deploy Key

  3. Paste the copied content and named the key as CI Deploy Key

3. Login to CircleCI and add the private SSH key as 'SSH Keys'

  1. Login to CircleCI

  2. Go to Project > Project Settings > SSH Permissions > Add SSH Keys

  3. For Hostname, enter github.com

  4. For Private Key, paste from the content of ~/.ssh/reponame_rsa (YES, the PRIVATE KEY)

4. Update your CI script to add the SSH Keys

Examples

steps:
  - add_ssh_keys:
      fingerprints:
        - "b7:35:a6:4e:9b:0d:6d:d4:78:1e:9a:97:2a:66:6b:be"

OR

steps:
  # adds default ssh key for this project
  - add_ssh_keys
# Get the latest from GitHub, public repo:
$ npm install username/my-new-project --save-dev
# GitHub, private repo:
$ npm install git+https://token:x-oauth-basic@github.com/username/my-new-project.git#master
$ npm install git+ssh://git@github.com/username/my-new-project.git#master
# … or from Bitbucket, public repo:
$ npm install git+ssh://git@bitbucket.org/username/my-new-project.git#master --save-dev
# Bitbucket, private repo:
$ npm install git+https://username:password@bitbucket.org/username/my-new-project.git#master
$ npm install git+ssh://git@bitbucket.org/username/my-new-project.git#master
# … or, if you published as npm package:
$ npm install my-new-project --save-dev
@aonrobot
Copy link

Thank you!!. It's making my day. Very useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment