ACR - Purging images tagged with {<!-- -->{.Run.ID}}

C.Holmes 21 Reputation points
2020-06-29T15:15:30.883+00:00

Hi,

I've just set up a task to build images to an azure container registry when I commit to github by following this tutorial:

https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-build-task

In the tutorial it uses {{.Run.ID}} as the image tag which is great for having unique tags. Unfortunately, I'd also like to automate the deleting of old images, ideally images that 3 versions old. I looked at this link:

https://learn.microsoft.com/en-us/azure/container-registry/container-registry-auto-purge

but it only demonstrate on demand or scheduled tasks for deleting images that are older than x number of days. Is there a way to delete images based off their run Id (although with multiple repositories that doesn't seem to increase in fixed increments) or delete images based on their age in relation to the newest image?

Alternatively, is there a way using multi-step tasks detailed here:
https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tutorial-multistep-task
https://learn.microsoft.com/en-us/azure/container-registry/container-registry-tasks-reference-yaml

to on commit, check the image is working, and if so rename the old image and put a new image in its place?

Thanks,
Callum

Azure Container Registry
Azure Container Registry
An Azure service that provides a registry of Docker and Open Container Initiative images.
478 questions
0 comments No comments
{count} votes

Accepted answer
  1. prmanhas-MSFT 17,906 Reputation points Microsoft Employee
    2020-07-02T14:34:38.467+00:00

    @C.Holmes The only way this would be possible for now would be to leverage the --filter with a --ago set to a small time duration (e.g. 1h)

    At a minimum, specify the following when you run ACR purge:
    --filter - A repository and a regular expression to filter tags in the repository. Examples: --filter "hello-world:." matches all tags in the hello-world repository, and --filter "hello-world:^1." matches tags beginning with 1. Pass multiple --filter parameters to purge multiple repositories.
    --ago - A Go-style duration string to indicate a duration beyond which images are deleted.

    The duration consists of a sequence of one or more decimal numbers, each with a unit suffix. Valid time units include "d" for days, "h" for hours, and "m" for minutes. For example, --ago 2d3h6m selects all filtered images last modified more than 2 days, 3 hours, and 6 minutes ago, and --ago 1.5h selects images last modified more than 1.5 hours ago.

    You can then come up with a tagging pattern that a regex could find easily which dev images or which images that are safe to be deleted based on the tagging pattern you decided

    For example, you can tag all your dev/ci build with a -rc- string to know those are release candidate or you can add the commitID to your tag to know that those are not official released TAG.

    Another approach is to leverage two different repo in ACR, one for non-prod and one for released images. Normally you shouldn't delete any official released images.

    Hopefully to provide you with some ideas on how to proceed.

    Please 'Accept as answer' if it helped, so that it can help others in the community looking for help on similar topics

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.