I would like to use Google Cloud Build to build my docker images. These docker images use private packages that are downloaded from Google Artifact Registry.
The builder itself is authenticated and can use the npx google-artifactregistry-auth
command. But I cannot call it inside the docker build process.
When I build the image locally I pass my credentials into Dockerfile like so:
--build-arg GOOGLE_CREDS=\"$(cat $GOOGLE_APPLICATION_CREDENTIALS)\"
Is there a way to make this work out of the box or do I have to make a separate service account and upload its key as a secret to cloud build? Kind of annoying since both services are on google cloud....
EDIT: By request I'm adding info on how artifact registry is handled when I build it locally. My docker command is:
docker build --rm --build-arg GOOGLE_CREDS=\"$(cat $GOOGLE_APPLICATION_CREDENTIALS)\" -f 'Dockerfile' -t image:latest .
Relevant parts of the docker image are:
ARG GOOGLE_CREDS
ENV GOOGLE_APPLICATION_CREDENTIALS=/credentials.json
RUN echo ${GOOGLE_CREDS} > $GOOGLE_APPLICATION_CREDENTIALS
COPY .npmrc_template /root/.npmrc
RUN npx google-artifactregistry-auth ~/.npmrc
RUN yarn install --silent
.npmrc_template contains details about the private repository but no password. It is then filled by google-artifactregistry-auth
command