diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..8e9de10 Binary files /dev/null and b/.DS_Store differ diff --git a/README.md b/README.md index caa3a7e..bc7d6f6 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ deployment option for a detailed guide: - [Scheduled GitHub Action workflow](docs/deploy-github-actions.md) - [Deployed to Cloud Run](docs/deploy-cloud-run.md) +- [Deploy GCR Cleaner to Cloudbuild](docs/deploy-gcp-cloudbuild.md) For one-off tasks, you can also run GCR Cleaner locally: diff --git a/docs/.DS_Store b/docs/.DS_Store new file mode 100644 index 0000000..193b142 Binary files /dev/null and b/docs/.DS_Store differ diff --git a/docs/deploy-gcp-cloudbuild.md b/docs/deploy-gcp-cloudbuild.md new file mode 100755 index 0000000..1ea7c7f --- /dev/null +++ b/docs/deploy-gcp-cloudbuild.md @@ -0,0 +1,39 @@ +# Deploy GCR Cleaner to Cloudbuild + +This document describes how to use GCR Cleaner in GCP [Cloud Build][cloud-build] with [Artifact Registry][artifact-registry] + +1. Grant a role `roles/artifactregistry.repoAdmin` to the [Cloud Build service account][cloud-build-service-account] + because it need `artifactregistry.repositories.deleteArtifacts` permission. + +1. Export your project ID as an environment variable. + + ```sh + export PROJECT_ID="my-project" + ``` + +1. Create a YAML file named cloudbuild.yaml which will always keep three images: + + ```yaml + 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 + - ".*" + ``` + +1. Manual trigger Cloud Build using [gcloud CLI][cloud-cli] to check it: + + ```sh + gcloud builds submit \ + --project "${PROJECT_ID}" \ + --config cloudbuild.yaml . + ``` + +[cloud-build]: https://cloud.google.com/build +[artifact-registry]: https://cloud.google.com/artifact-registry +[cloud-cli]: https://cloud.google.com/cli +[cloud-build-service-account]: https://cloud.google.com/build/docs/cloud-build-service-account \ No newline at end of file