This document describes how to use GCR Cleaner in Cloud Build with Artifact Registry
-
Grant a role
roles/artifactregistry.repoAdmin
to the Cloud Build service account because it needartifactregistry.repositories.deleteArtifacts
permission. -
Export your project ID as an environment variable.
export PROJECT_ID="my-project"
-
Create a YAML file named cloudbuild.yaml which will always keep three images:
steps: - name: asia-docker.pkg.dev/gcr-cleaner/gcr-cleaner/gcr-cleaner-cli:latest args: - -repo - "asia-docker.pkg.dev/my-project/my-repo/my-image" - -keep - "3" - -tag-filter-any - ".*"
-
Manual trigger Cloud Build using gcloud CLI to check it:
gcloud builds submit \ --project "${PROJECT_ID}" \ --config cloudbuild.yaml .