If I have the following tags and manifest in an ACR repository...
Which returns the following when I run the following command...
az acr repository show-manifests --name "[registry-name]" --repository "[repository-name]"
[
{
"digest": "sha256:30be2b07e723b0f36fed370c386b027e52dbcd0ad2ad2fcac1d3b7d1b361292f",
"tags": [
"982878",
"master"
],
"timestamp": "2022-09-07T15:49:04.4187041Z"
}
]
When I run the following purge command....
az acr run --cmd "acr purge --filter '[repository-name]:.*' --untagged --ago 1m" --registry [registry-name] /dev/null
It is deleting the tags and manifest, and because it deletes everything the repository is deleted as well.
Why is it doing this when I'm using the --untagged
flag and you can clearly see it's not untagged based on the starting state?
I have tried to reproduce the same in my environment
I have two repositories ,hello-world with 1 tag: latest
I checked with below command which you tried:
PURGE_CMD="acr purge --filter 'hello-world:.*' \
--untagged –ago 1m"
az acr run \
--cmd "$PURGE_CMD" \
--registry myregistry807 \
/dev/null
It is deleting even the tagged repository
This command:
az acr run --cmd "acr purge --filter 'hello-world:.*' --untagged --ago 1d" --registry myregistry807 /dev/null
It is deleting the tags first, and then it is deleting the untagged manifests and then the registry.
You can check this Purge tags and manifests-run-in-an-on-demand-task - Azure Container Registry | Microsoft Docs:
This purge command deletes all image tags and manifests in the repository (hello-world in my case) repository in myregistry that were modified more than 1 day ago and all the untagged manifests.
[?tags[0]==null]
to delete
only repos with no tag or null tag.In bash:
az acr repository show-manifests -n myregistry807 –repository targetrepository --query "[?tags[0]==null].digest" -o tsv | xargs -I% az acr repository delete -n myregistry807 -t targetrepository @% --yes
for preview version:
az acr manifest list-metadata -r myregistry807 -n hello-world --query "[?tags[0]==null].digest" -o tsv | xargs -I% az acr repository delete -n myregistry807 -t hello-world@% --yes
and repository is not deleted as it has tags.
then i checked with [?tags[0]!=null]
to delete all tags except null, and it successfully worked for me:
Result: deleted tagged manifest which is the only one present: