Last active
October 8, 2019 09:17
-
-
Save schnatterer/f893846a40d21bbdce6bb2948546bace to your computer and use it in GitHub Desktop.
Deletes all images of a Google Container Registry Repo
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
#!/usr/bin/env bash | |
set -o nounset -o pipefail -o errexit | |
function main() { | |
ROOT_REPO="${1}" | |
local count=0 | |
for REPO in $(gcloud container images list --repository=${ROOT_REPO} --limit=999999 | tail -n +2); do | |
for IMAGE in $(gcloud container images list --repository=${REPO} --limit=999999 | tail -n +2); do | |
for DIGEST in $(gcloud container images list-tags "${IMAGE}" --limit=999999 --format='get(digest)'); do | |
gcloud container images delete -q --force-delete-tags "${IMAGE}@${DIGEST}" | |
let count=count+1 | |
done | |
done | |
done | |
echo "Deleted ${count} images in ${REPO}." >&2 | |
} | |
main "$@" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment