Last active
September 6, 2024 07:36
-
-
Save Marusyk/e20223625d0c18b7fe88b9eec7b946f2 to your computer and use it in GitHub Desktop.
Automatically purge images from an Azure Container Registry
This file contains hidden or 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 | |
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