Created
April 26, 2021 11:52
-
-
Save philippdrebes/5ae63fe8cc02ac0822ec46712d2ea155 to your computer and use it in GitHub Desktop.
Script for cleaning up development tags from Azure Container Registry. Images are untagged so that the manifests will get deleted according to the configured retention policy.
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
#!/bin/bash | |
registry_name=my-registry | |
hundred_days_ago=$(date -d 'now - 100 days' +%s) | |
for repo in $(az acr repository list --name $registry_name | jq -r '.[]') | |
do | |
echo '-----------------------------------------------------------------' | |
echo $repo | |
echo '-----------------------------------------------------------------' | |
for tag in $(az acr repository show-tags -n $registry_name --repository $repo --detail | jq -cr '.[] | {name,lastUpdateTime}') | |
do | |
tag_name=$(echo $tag | jq '.name' | sed -e 's/^"//' -e 's/"$//') | |
last_update_time=$(echo $tag | jq '.lastUpdateTime' | sed -e 's/^"//' -e 's/"$//') | |
echo $tag_name | |
if [[ $tag_name =~ ^develop-[0-9]*$ ]]; then | |
tag_time=$(date -d $last_update_time +%s) | |
if (( tag_time <= hundred_days_ago )); then | |
echo "Tag $tag_name is older than 100 days" | |
# az acr repository delete -n $registry_name --image $repo:$tag_name -y | |
az acr repository untag -n $registry_name --image $repo:$tag_name | |
fi | |
fi | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment