Skip to content

Commit

Permalink
[Added]add-gcp-cloudbuild-instruction (#135)
Browse files Browse the repository at this point in the history
Hi

I write some instrction about how to use gcr-cleaner in GCP cloudbuild.
I think it may be necessary. Because I spend some time to try how to use
and README.md doesn't have instrction about it
  • Loading branch information
winds6206 authored Feb 21, 2023
1 parent 12d7c1b commit b628a87
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
Binary file added .DS_Store
Binary file not shown.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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:

Expand Down
Binary file added docs/.DS_Store
Binary file not shown.
39 changes: 39 additions & 0 deletions docs/deploy-gcp-cloudbuild.md
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit b628a87

Please sign in to comment.