-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
acr_clean.sh
executable file
·28 lines (23 loc) · 984 Bytes
/
acr_clean.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash
# WARNING! This script deletes data!
# Run only if you do not have systems
# that pull images via manifest digest.
# Change to 'true' to enable image delete
ENABLE_DELETE=false
# Modify for your environment
# TIMESTAMP can be a date-time string such as 2019-03-15T17:55:00.
REGISTRY=idiomatically893a
REPOSITORY=idiomatically
TIMESTAMP=2020-07-28
# Delete all images older than specified timestamp.
if [ "$ENABLE_DELETE" = true ]
then
az acr repository show-manifests --name $REGISTRY --repository $REPOSITORY \
--orderby time_asc --query "[?timestamp < '$TIMESTAMP'].digest" -o tsv \
| xargs -I% az acr repository delete --name $REGISTRY --image $REPOSITORY@% --yes
else
echo "No data deleted."
echo "Set ENABLE_DELETE=true to enable deletion of these images in $REPOSITORY:"
az acr repository show-manifests --name $REGISTRY --repository $REPOSITORY \
--orderby time_asc --query "[?timestamp < '$TIMESTAMP'].[digest, timestamp]" -o tsv
fi