Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete untagged images on Google Cloud Registry [closed]

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 from a project, or at least for a single image, to avoid incurring Storage costs?

like image 939
Robert Lacok Avatar asked Sep 27 '17 14:09

Robert Lacok


People also ask

How do I delete old photos from GCR?

Go to the Container Registry page. Click on the image name to see version(s) of that image. In the registry, check the box next to the version(s) of the image that you want to delete. Click DELETE on the top of the page.

Where does the container images get stored in cloud run?

Container images stored in the same project as the one you are creating the job or service in. Container images from other Google Cloud projects (provided that the correct IAM permissions are set).


2 Answers

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

like image 53
jsand Avatar answered Oct 20 '22 18:10

jsand


Handy when you glue them together with awk and xargs

gcloud container images list-tags gcr.io/${PROJECT_ID}/${IMAGE} --filter='-tags:*' --format='get(digest)' --limit=unlimited | awk '{print "gcr.io/${PROJECT_ID}/${IMAGE}@" $1}' | xargs gcloud container images delete --quiet

like image 10
nuzz Avatar answered Oct 20 '22 18:10

nuzz