Github gives a generous limits for your private projects, its to good for your private repos or even small startups. However, Github package has a constraint of 500mb size, which is quite low.

Lets compare the pricing for both github & gcp (as of July 2021)

  Storage (per GB) Data Transfer (per GB)
Github $0.25 $0.50
GCP artifactory $0.10 $0.01 - $0.15

Looking at pricing, storing artifacts in GCP is a good idea.

Setting up service account

The first thing, we need to set up our service account, so that github has required permission to publish the packages.

Login to google console and navigate to `IAM

You need to add following permission for publishing artifacts (optionally you can provide Cloud Run Service Agent for cloud run deployments)

Then generate & download key in json format

Setup Tokens

The first step is to set up a personal access token.

Go to your profile and click to settings.

Go to developer section

Add a new token GCP_ARTIFACTORY_SERVICE_ACCOUNT with the contents for download service account key. Also add another token GCP_PROJECT_ID with your GCP project id.

Publish packages to GCP artifact registry

Time to setup a github action to push npm package to repository. You will need to add .github/workflows/ci.yaml

There are 5 steps performed here:

  1. Checkout the project
  2. Set version using sed command (In my package.json, I have kept the version 1.0.0-SNAPSHOT, and using the sed command update it to build version).
  3. Next we are setting up GCP credentials
  4. The we are builing package.
  5. Finally, deploying our package to the artifactory.

We are using --registry argument to point to our package repository.

Note: You will have to use npm scope to associate this repository. i.e. your package name should be like @<YOUR-SCOPE>/<YOUR-PACKAGE-NAME>.

Using packages from GCP repository

Go to artifact registry on gcp console

Select your repository, and click on the Setup instructions, and copy the snippet into a file npmrc

Note: SCOPE is the npm scope to associate with this repository

Here we are generating a npmrc file, with registry details, followed by authenticating gcp registry by npm run artifactregistry-login .npmrc.

Now you are equipped with knowlege to publish and consume packages from your gcp artifactory registry.

If you liked this article, you can buy me a coffee

Tags: ,



Kumar Rohit

Kumar Rohit

I like long drives, bike trip & good food. I have passion for coding, especially for Clean-Code.

Leave a comment