When we push repeatedly into gcr.io
with the same image name and a version (tag), there is a high number of untagged images.
Is there a simple way to remove all untagged images for a single image using the gcloud
CLI tool to avoid incurring Storage costs?
gcloud container images list-tags gcr.io/project-id/repository --format=json --limit=unlimited
will give you an easily consumable json blob of info for images in a repo (such as digests w/ associated tags).
In order to just enumerate all digests which lack tags:
gcloud container images list-tags gcr.io/project-id/repository --filter='-tags:*' --format='get(digest)' --limit=unlimited
Which you can iterate over and delete with:
gcloud container images delete --quiet gcr.io/project-id/repository@DIGEST