Skip to content

Instantly share code, notes, and snippets.

@schnatterer
Last active October 8, 2019 09:17
Show Gist options
  • Save schnatterer/f893846a40d21bbdce6bb2948546bace to your computer and use it in GitHub Desktop.
Save schnatterer/f893846a40d21bbdce6bb2948546bace to your computer and use it in GitHub Desktop.
Deletes all images of a Google Container Registry Repo
#!/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