Last active
May 30, 2018 12:58
-
-
Save rifatx/8d106bdc70a681cefa07e3f6b5954c61 to your computer and use it in GitHub Desktop.
shell script to clean all but last N images in gcr
This file contains 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 | |
repoAddress="xx.gcr.io/xXx" | |
repos=$(gcloud container images list --format='table[no-heading](name:sort=1)' --repository=repoAddress) | |
while read -r repo; do | |
images=$(gcloud container images list-tags --limit=99999 --sort-by=~timestamp --format='get(digest)' $repo) | |
n=10 | |
while read -r image; do | |
if (( n < 1 )); then | |
gcloud container images delete --quiet "$repo@$image" | |
fi; | |
n=$((n-1)) | |
done <<< "$images" | |
done <<< "$repos" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment