I have a Docker image of a javascript application that uses private npm packages stored in Google's Artifact Registry.
Inside Google's CloudBuild I can specify docker build -t myimage --network=cloudbuild .
and inside the docker build I can run npx google-artifactregistry-auth
which retrieves the credentials using the build service account and then I can run my RUN npm install
.
However, locally when I have ADC on my computer (macOS), setup by running gcloud auth application-default login
, running the same command in docker fails saying:
#19 2.583 npm WARN exec The following package was not found and will be installed: google-artifactregistry-auth@3.1.1
#19 6.822 Retrieving application default credentials...
#19 6.846 Retrieving credentials from gcloud...
#19 6.856 Error: Fail to get credentials. Please run:
#19 6.856gcloud auth application-default login
,gcloud auth login
, or
#19 6.856export GOOGLE_APPLICATION_CREDENTIALS=<path/to/service/account/key>
#19 6.856 at Object.getCreds (/root/.npm/_npx/64aef35f3ba01c7c/node_modules/google-artifactregistry-auth/src/auth.js:40:9)
#19 6.856 at async main (/root/.npm/_npx/64aef35f3ba01c7c/node_modules/google-artifactregistry-auth/src/main.js:83:19)
I tried setting the environment variable to my local path to no avail:
docker build --build-arg GOOGLE_APPLICATION_CREDENTIALS=/Users/myname_here/.config/gcloud/application_default_credentials.json -t hello_world .