|
| 1 | +# Artifact Registry Setup for External Container Images |
| 2 | + |
| 3 | +## Overview |
| 4 | + |
| 5 | +Google Cloud Run now restricts container image sources to: |
| 6 | +- `gcr.io` (Google Container Registry) |
| 7 | +- `*.docker.pkg.dev` (Artifact Registry) |
| 8 | +- `docker.io` (Docker Hub) |
| 9 | + |
| 10 | +To use images from other registries like `quay.io`, you must set up an Artifact Registry remote repository that acts as a proxy. |
| 11 | + |
| 12 | +## One-Time Setup |
| 13 | + |
| 14 | +This setup only needs to be done once per GCP project. |
| 15 | + |
| 16 | +### Option 1: Using the Setup Script |
| 17 | + |
| 18 | +1. Run the provided setup script: |
| 19 | + ```bash |
| 20 | + cd scripts |
| 21 | + PROJECT_ID=your-project-id ./setup-artifact-registry.sh |
| 22 | + ``` |
| 23 | + |
| 24 | +2. The script will: |
| 25 | + - Enable the Artifact Registry API |
| 26 | + - Create a remote repository named `quay-remote` |
| 27 | + - Configure it to proxy quay.io |
| 28 | + |
| 29 | +### Option 2: Manual Setup |
| 30 | + |
| 31 | +1. Enable the Artifact Registry API: |
| 32 | + ```bash |
| 33 | + gcloud services enable artifactregistry.googleapis.com |
| 34 | + ``` |
| 35 | + |
| 36 | +2. Create the remote repository: |
| 37 | + ```bash |
| 38 | + gcloud artifacts repositories create quay-remote \ |
| 39 | + --repository-format=docker \ |
| 40 | + --mode=remote-repository \ |
| 41 | + --location=us-central1 \ |
| 42 | + --description="Remote repository for quay.io images" \ |
| 43 | + --remote-docker-repo=https://quay.io |
| 44 | + ``` |
| 45 | + |
| 46 | +## Using the Remote Repository |
| 47 | + |
| 48 | +After setup, you need to update your image URLs: |
| 49 | + |
| 50 | +### Original Image URL |
| 51 | +``` |
| 52 | +quay.io/reiemp/hrafnar:latest |
| 53 | +``` |
| 54 | + |
| 55 | +### New Image URL |
| 56 | +``` |
| 57 | +us-central1-docker.pkg.dev/YOUR_PROJECT_ID/quay-remote/reiemp/hrafnar:latest |
| 58 | +``` |
| 59 | + |
| 60 | +### In Terraform |
| 61 | + |
| 62 | +Update your module configuration: |
| 63 | + |
| 64 | +```hcl |
| 65 | +module "hrafnar_deploy" { |
| 66 | + source = "../.." |
| 67 | + |
| 68 | + project_id = "your-project-id" |
| 69 | + name_prefix = "my-app" |
| 70 | + app_image = "us-central1-docker.pkg.dev/your-project-id/quay-remote/reiemp/hrafnar" |
| 71 | + app_image_tag = "latest" |
| 72 | + |
| 73 | + # ... other configuration |
| 74 | +} |
| 75 | +``` |
| 76 | + |
| 77 | +## Testing |
| 78 | + |
| 79 | +To verify the setup works: |
| 80 | + |
| 81 | +1. Test pulling an image through the remote repository: |
| 82 | + ```bash |
| 83 | + docker pull us-central1-docker.pkg.dev/YOUR_PROJECT_ID/quay-remote/reiemp/hrafnar:latest |
| 84 | + ``` |
| 85 | + |
| 86 | +2. Deploy to Cloud Run: |
| 87 | + ```bash |
| 88 | + gcloud run deploy test-app \ |
| 89 | + --image=us-central1-docker.pkg.dev/YOUR_PROJECT_ID/quay-remote/reiemp/hrafnar:latest \ |
| 90 | + --region=us-central1 |
| 91 | + ``` |
| 92 | + |
| 93 | +## Troubleshooting |
| 94 | + |
| 95 | +### Authentication Issues |
| 96 | +If the quay.io repository requires authentication: |
| 97 | +1. Store credentials in Secret Manager |
| 98 | +2. Configure the remote repository with authentication: |
| 99 | + ```bash |
| 100 | + gcloud artifacts repositories update quay-remote \ |
| 101 | + --location=us-central1 \ |
| 102 | + --remote-username=YOUR_USERNAME \ |
| 103 | + --remote-password-secret-version=projects/PROJECT_ID/secrets/quay-password/versions/latest |
| 104 | + ``` |
| 105 | + |
| 106 | +### Image Not Found |
| 107 | +- Verify the original image exists on quay.io |
| 108 | +- Check that the repository path is correct |
| 109 | +- Ensure the Artifact Registry API is enabled |
| 110 | + |
| 111 | +### Performance |
| 112 | +- First pull will be slower as it fetches from quay.io |
| 113 | +- Subsequent pulls use the cached version in Artifact Registry |
| 114 | +- Configure cleanup policies to manage storage costs |
0 commit comments