Last active
February 16, 2021 11:34
-
-
Save ReallyLiri/3dfa7e0cc3cd8d77c0cb1c212490d920 to your computer and use it in GitHub Desktop.
Google Container Registry cleanup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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