Search code examples
azure-container-registry

'acr purge --untagged' is removing all tagged images from an ACR repository


If I have the following tags and manifest in an ACR repository...

enter image description here

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.

enter image description here

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?


Solution

  • I have tried to reproduce the same in my environment I have two repositories ,hello-world with 1 tag: latest enter image description here

    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

    enter image description here

    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.

    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
    

    enter image description here

    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:

    enter image description here

    Result: deleted tagged manifest which is the only one present:

    enter image description here