Skip to content

Instantly share code, notes, and snippets.

@Marusyk
Last active September 6, 2024 07:36
Show Gist options
  • Save Marusyk/e20223625d0c18b7fe88b9eec7b946f2 to your computer and use it in GitHub Desktop.
Save Marusyk/e20223625d0c18b7fe88b9eec7b946f2 to your computer and use it in GitHub Desktop.
Automatically purge images from an Azure Container Registry
#!/bin/bash
REGISTRY={{name}}
REPOSITORIES=$(az acr repository list --name $REGISTRY --output tsv | grep '^prefix')
for REPOSITORY in ${REPOSITORIES[*]}
do
echo =======================================================================
echo Creating task for repository: $REPOSITORY
echo =======================================================================
PURGE_CMD="acr purge --filter '$REPOSITORY:.*' --ago 7d --untagged --keep 7"
NAME=$(echo "$REPOSITORY" | awk -F'-' '{print $NF}')
az acr task create --name purge-$NAME \
--cmd "$PURGE_CMD" \
--schedule "0 0 * * *" \
--registry $REGISTRY \
--output table \
--context /dev/null
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment