Skip to content

Instantly share code, notes, and snippets.

@ReallyLiri
Last active February 16, 2021 11:34
Show Gist options
  • Save ReallyLiri/3dfa7e0cc3cd8d77c0cb1c212490d920 to your computer and use it in GitHub Desktop.
Save ReallyLiri/3dfa7e0cc3cd8d77c0cb1c212490d920 to your computer and use it in GitHub Desktop.
Google Container Registry cleanup
#!/bin/bash
# USAGE: gcr-cleanup.sh [tag-to-clean]
# if you want to cleanup a specific tag, pass its name, otherwise all non-tagged images will be cleaned
images=$(gcloud container images list --repository=gcr.io/xxx --format='get(name)')
for image_name in $images; do
if [ -n "$1" ]
then
gcloud container images untag --quiet $image_name:$1
else
for digest in `gcloud container images list-tags $image_name --filter='-tags:*' --format='get(digest)' --limit=100`; do
echo DELETING $image_name@$digest
gcloud container images delete --quiet $image_name@$digest
done
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment