We have a Google Artifact Registry for our Python packages. Authentication works like this. Locally it works well.
However, how do I pass credentials to Docker build when I want to build a Docker image that needs to install a package from our private registry?
I'd like to keep the Dockerfile the same when building with a user account or with a service account.
This works, but I'm not sure it's best practice:
FROM python:3.9
RUN pip install keyring keyrings.google-artifactregistry-auth
COPY requirements.txt .
RUN --mount=type=secret,id=creds,target=/root/.config/gcloud/application_default_credentials.json \
pip install -r requirements.txt
Then build with:
docker build --secret="id=creds,src=$HOME/.config/gcloud/application_default_credentials.json" .