Usage Scenarios
Usage Scenarios
Local Development
# Set the environment variable in your shell profile
export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your-key.json"
# Install the auth helper once
pip install keyrings.google-artifactregistry-auth
# Install packages
pip install --index-url https://<REGION>-python.pkg.dev/<PROJECT>/<REPOSITORY>/simple/ <PACKAGE_NAME>
Docker / Containers
FROM python:3.12-slim
COPY requirements.txt .
# Install the auth helper
RUN pip install keyrings.google-artifactregistry-auth
# The key is passed at build time or runtime
ENV GOOGLE_APPLICATION_CREDENTIALS=/secrets/key.json
RUN --mount=type=secret,id=gcp_key,target=/secrets/key.json \
pip install --index-url https://<REGION>-python.pkg.dev/<PROJECT>/<REPOSITORY>/simple/ \
-r requirements.txt
COPY . .
# Build with the service account key
docker build --secret id=gcp_key,src=/path/to/your-key.json -t your-image .
CI/CD Pipelines
# GitHub Actions example
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Authenticate to Google Cloud
uses: google-github-actions/auth@v2
with:
credentials_json: ${{ secrets.GCP_SA_KEY }}
- name: Install dependencies
run: |
pip install keyrings.google-artifactregistry-auth
pip install --index-url https://<REGION>-python.pkg.dev/<PROJECT>/<REPOSITORY>/simple/ -r requirements.txt
Virtual Environments
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate
# Install the auth helper inside the venv
pip install keyrings.google-artifactregistry-auth
# Install packages
pip install --index-url https://<REGION>-python.pkg.dev/<PROJECT>/<REPOSITORY>/simple/ <PACKAGE_NAME>