Skip to content

Instantly share code, notes, and snippets.

@michaelact
Last active November 25, 2021 08:51
Show Gist options
  • Save michaelact/cab52dd8935be028689896ecc49c1633 to your computer and use it in GitHub Desktop.
Save michaelact/cab52dd8935be028689896ecc49c1633 to your computer and use it in GitHub Desktop.
Install NPM package from artifact registry inside Container Image | Must be have Service Account file!
#!/bin/bash
set -e
gcloud auth activate-service-account \
--project=$GCP_PROJECT \
--key-file=${GCP_KEY_FILENAME:-service_account.json}
gcloud artifacts print-settings npm \
--project=$GCP_PROJECT \
--scope=$PACKAGE_SCOPE \
--repository=$PACKAGE_REPOSITORY \
--location=$PACKAGE_LOCATION > .npmrc
curl -sLfo /tmp/setup.sh https://deb.nodesource.com/setup_12.x \
&& chmod +x /tmp/setup.sh \
&& /tmp/setup.sh \
&& rm -fr /tmp/setup.sh \
&& apt-get install nodejs \
&& rm -fr /var/lib/apt/lists/*
npx google-artifactregistry-auth
npm ci
version: '3.8'
services:
builder:
image: gcr.io/cloud-builders/gcloud
entrypoint: /bin/bash
command: bash -c ./build.sh
working_dir: /tmp/frontend-utils
# Set the environment variables below from your host machine
# Or set variable value inside this file following https://docs.docker.com/compose/environment-variables/#set-environment-variables-in-containers
environment:
- GCP_PROJECT
- GCP_KEY_FILENAME
- PACKAGE_SCOPE
- PACKAGE_REPOSITORY
- PACKAGE_LOCATION
volumes:
- .:/tmp/frontend-utils
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment