Skip to content

Instantly share code, notes, and snippets.

@ederparaiso
Created October 20, 2019 21:09
Show Gist options
  • Save ederparaiso/7b06f89303cabe71d9940a5095168114 to your computer and use it in GitHub Desktop.
Save ederparaiso/7b06f89303cabe71d9940a5095168114 to your computer and use it in GitHub Desktop.
Purge container images in Azure Container Registry
#!/bin/bash
# WARNING! This script deletes data!
# Purge old images retaining configured amount of tags. Tag latest will be always preserved.
REGISTRY=your_registry
REPOSITORY=your_repository
HISTORY_SIZE=amount_of_tags_to_be_remain
az acr repository show-tags -n $REGISTRY --repository $REPOSITORY --orderby time_desc --query "[?@ != 'latest'] | [$HISTORY_SIZE:]" -o tsv \
| xargs --replace=tag --verbose az acr repository delete -n $REGISTRY --image $REPOSITORY:tag --yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment