{"id":24994435,"url":"https://github.com/marekaf/gcr-lifecycle-policy","last_synced_at":"2025-04-12T03:24:33.700Z","repository":{"id":40263322,"uuid":"208222302","full_name":"marekaf/gcr-lifecycle-policy","owner":"marekaf","description":"Google Container Registry image lifecycle policy - retention","archived":false,"fork":false,"pushed_at":"2024-02-12T08:13:26.000Z","size":5836,"stargazers_count":56,"open_issues_count":1,"forks_count":15,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-06T12:37:35.473Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/marekaf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-09-13T08:09:55.000Z","updated_at":"2024-02-12T08:13:30.000Z","dependencies_parsed_at":"2024-06-18T22:46:16.386Z","dependency_job_id":"4185aa16-ec50-4573-9c96-2e49367fc460","html_url":"https://github.com/marekaf/gcr-lifecycle-policy","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marekaf%2Fgcr-lifecycle-policy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marekaf%2Fgcr-lifecycle-policy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marekaf%2Fgcr-lifecycle-policy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/marekaf%2Fgcr-lifecycle-policy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/marekaf","download_url":"https://codeload.github.com/marekaf/gcr-lifecycle-policy/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248511068,"owners_count":21116345,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-04T14:53:23.209Z","updated_at":"2025-04-12T03:24:33.678Z","avatar_url":"https://github.com/marekaf.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# GCR Retention policy\nThis simple golang CLI tool is handling retention policy of images in Google Container Registry (and Google Artifact Registry for Docker) in a similar manner as Elastic Container Registry does (original [blogpost talking about the details here](https://blog.marekbartik.com/posts/2019-09-26_google-container-registry-lifecycle-policy-for-images-retention/))\n\nIt scans all the Docker registry images (it supports paths like `eu.gcr.io/my-project/foo/bar/my-service:123`) and fetches their tags using Docker v2 API. Then it deletes some of them based on parametrized filters and input GKE clusters.\n\n![](/assets/render.gif)\n\n## Retention policy configuration\n\nUsing `--cluster path/to/kubeconfig` it queries all pods and replicasets in the GKE cluster and prevents these image tags before deleting.\n\n```shell\n$ gcr cleanup --help\nUsage:\n  gcr cleanup [flags]\n\nFlags:\n      --dry-run         dry-run for images cleaning (default true)\n  -h, --help            help for cleanup\n      --keep-tags int   number of tags to keep per image (default 10)\n      --retention int   number of days of retention to keep images (default 365)\n\nGlobal Flags:\n      --cluster string      kubeconfig path (default \"/Users/marek/.kube/config\")\n      --creds string        credential file (default \"./creds/serviceaccount.json\")\n      --log-level string    log level (default \"ERROR\")\n      --registry string     GCR url to use (default \"eu.gcr.io\")\n      --repos stringArray   list of repos you want to work with\n      --sort-by string      field to sort images by (default \"timeCreatedMs\")\n```\n\n`TIP`: For Google Artifact Registry use `--sort-by=\"timeUploadedMs\"`\n\n`WARNING`: This is an alpha version! Be very careful using this in production.\n\n## How to build it\n```shell\nmake dep\nmake build\n```\n\n## How to run it\n\n### Provision GCP IAM service account\n`serviceaccount.json` is a json key of IAM service account called `gcr-retention-policy` that has these roles\n\n```\nKubernetes Engine Cluster Viewer\nKubernetes Engine Developer\nKubernetes Engine Service Agent\nStorage Object Admin\nArtifact Registry Repository Administrator\n```\n\n### Run it\n\n```shell\nmake build \u0026\u0026 ./bin/gcr --help\n```\n\n### `gcr cleanup` without kubeconfig\n\nIf you want to nuke old images without checking if they're currently used in a cluster you can do so by setting `--cluster=\"\"`. When using this \"dummy mode\" your IAM service account doesn't need any `Kubernetes Engine` roles listed above.\n\n## TODO:\n- release binary to Github Release\n- release docker image to Docker Hub\n- try to make use of `https://github.com/google/go-containerregistry/tree/master`\n- support Cloud Run in `--cluster` (not it supports only GKE)\n- prepare example deployment for Cloud Scheduler + Cloud Run (or Cloud Functions)\n- make the horrible code a bit less horrible and more reusable\n\n# deprecation info\nthis tool used bash/jq before and the code is still kept [here](https://github.com/marekaf/gcr-lifecycle-policy/releases/tag/0.1). I will not continue maintaining the bash/jq version but focus purely in the new one in Go.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarekaf%2Fgcr-lifecycle-policy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarekaf%2Fgcr-lifecycle-policy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarekaf%2Fgcr-lifecycle-policy/lists"}