Skip to content

Commit 3a87d81

Browse files
committed
incorp'd Steve's suggestions
1 parent 6f5960d commit 3a87d81

File tree

1 file changed

+52
-28
lines changed

1 file changed

+52
-28
lines changed

articles/container-registry/container-registry-auto-purge.md

Lines changed: 52 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ At a minimum, specify the following when you run `acr purge`:
4040

4141
* `--registry` - The Azure container registry where you run the command.
4242
* `--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.
43-
* `--ago` - An expression in Go duration format to indicate a duration beyond which images are deleted. For example, `--ago 2d3h6m` selects all images last modified more than 2 days, 3 hours, and 6 minutes ago.
43+
* `--ago` - A Go-style [duration string](https://golang.org/pkg/time/) to indicate a duration beyond which images are deleted. The duration consists of a sequence of decimal number, each with a unit suffix. Valid time units include "d" for days, "h" for hours, "m" for minutes. For example, `--ago 2d3h6m` selects all filtered images last modified more than 2 days, 3 hours, and 6 minutes ago. `--ago 1.5h` selects all filtered images last modified more than 1.5 hours ago.
4444

4545
`acr purge` supports several optional parameters. The following two are used in examples in this article:
4646

@@ -53,56 +53,74 @@ For additional parameters, run `acr purge --help`.
5353

5454
### Run in an on-demand task
5555

56-
The following example uses the [az acr run][az-acr-run] command to run the `purge` command on-demand. This example deletes all image tags and manifests in the `hello-world` repository in *myregistry* that were modified more than 1 day ago. The task runs without a source context.
56+
The following example uses the [az acr run][az-acr-run] command to run the `purge` command on-demand. This example deletes all image tags and manifests in the `hello-world` repository in *myregistry* that were modified more than 1 day ago. The container command is passed using an environment variable. The task runs without a source context.
5757

5858
```azurecli
59+
# Environment variable for container command line
60+
PURGE_CMD="mcr.microsoft.com/acr/acr-cli:0.1 purge \
61+
--registry {{.Run.Registry}} --filter \"hello-world:.*\" --untagged --ago 1d"
62+
5963
az acr run \
60-
--cmd "mcr.microsoft.com/acr/acr-cli:0.1 purge --registry {{.Run.Registry}} --filter "hello-world:.*" --untagged --ago 1d" \
64+
--cmd "$PURGE_CMD" \
6165
--registry myregistry \
6266
/dev/null
6367
```
6468

6569
### Run in a scheduled task
6670

67-
The following example uses the [az acr task create][az-acr-task-create] command to create a daily [scheduled ACR task](container-registry-tasks-scheduled.md). The task purges tags modified more than 7 days ago in the `hello-world` repository. The task runs without a source context.
71+
The following example uses the [az acr task create][az-acr-task-create] command to create a daily [scheduled ACR task](container-registry-tasks-scheduled.md). The task purges tags modified more than 7 days ago in the `hello-world` repository. The container command is passed using an environment variable. The task runs without a source context.
6872

6973
```azurecli
74+
# Environment variable for container command line
75+
PURGE_CMD="mcr.microsoft.com/acr/acr-cli:0.1 purge \
76+
--registry {{.Run.Registry}} --filter \"hello-world:.*\" --ago 7d"
77+
7078
az acr task create --name purgeTask \
71-
--cmd "mcr.microsoft.com/acr/acr-cli:0.1 purge --registry {{.Run.Registry}} --filter "hello-world:.*" --ago 7d" \
72-
--context /dev/null \
79+
--cmd "$PURGE_CMD" \
7380
--schedule "0 0 * * *" \
74-
--registry myregistry
81+
--registry myregistry \
82+
--context /dev/null
7583
```
7684

7785
Run the [az acr task show][az-acr-task-show] command to see that the timer trigger is configured.
7886

7987
### Purge large numbers of tags and manifests
8088

81-
Purging a large number of tags and manifests could take several minutes or longer. To purge thousands of tags and manifests, the on-demand or scheduled task command might need to run longer than the default timeout time of 600 seconds for an on-demand task, or 3600 seconds for a scheduled task. In this case, pass the `--timeout` parameter to set a larger value.
89+
Purging a large number of tags and manifests could take several minutes or longer. To purge thousands of tags and manifests, the command might need to run longer than the default timeout time of 600 seconds for an on-demand task, or 3600 seconds for a scheduled task. If the timeout time is exceeded, only a subset of tags and manifests are deleted. To ensure that a large-scale purge is complete, pass the `--timeout` parameter to increase the value.
8290

83-
For example, the following on-demand task times out after 3600 seconds (1 hour):
91+
For example, the following on-demand task sets a timeout time of 3600 seconds (1 hour):
8492

8593
```azurecli
94+
# Environment variable for container command line
95+
PURGE_CMD="mcr.microsoft.com/acr/acr-cli:0.1 purge \
96+
--registry {{.Run.Registry}} --filter \"hello-world:.*\" --untagged --ago 1d"
97+
8698
az acr run \
87-
--cmd "mcr.microsoft.com/acr/acr-cli:0.1 purge --registry {{.Run.Registry}} --filter "hello-world:.*" --untagged --ago 1d" \
99+
--cmd "$PURGE_CMD" \
88100
--registry myregistry \
89101
--timeout 3600 \
90102
/dev/null
91103
```
92104

93105
## Example: Scheduled purge of multiple repositories in a registry
94106

95-
This example walks through using `acr purge` to periodically clean up multiple repositories in a registry. For example, you might have a development pipeline that pushes images to the `devimage1` and `devimage2` repositories. You periodically import development images into a production repository for your deployments, so you no longer need the development images. On a weekly basis, you purge the `devimage1` and `devimage2` repositories, in preparation for the coming week's work.
107+
This example walks through using `acr purge` to periodically clean up multiple repositories in a registry. For example, you might have a development pipeline that pushes images to the `samples/devimage1` and `samples/devimage2` repositories. You periodically import development images into a production repository for your deployments, so you no longer need the development images. On a weekly basis, you purge the `samples/devimage1` and `samples/devimage2` repositories, in preparation for the coming week's work.
96108

97109
### Preview the purge
98110

99111
Before deleting data, we recommend running an on-demand purge task using the `--dry-run` parameter. This option allows you to see the tags and manifests that the command will purge, without removing any data.
100112

101-
In the following example, the filter in each repository selects all tags. The `--ago 0d` parameter matches images of all ages in the repositories that match the filters. Modify the selection criteria as needed for your scenario. The `--untagged` parameter indicates to delete manifests in addition to tags.
113+
In the following example, the filter in each repository selects all tags. The `--ago 0d` parameter matches images of all ages in the repositories that match the filters. Modify the selection criteria as needed for your scenario. The `--untagged` parameter indicates to delete manifests in addition to tags. The container command is passed to the [az acr run][az-acr-run] command using an environment variable.
102114

103115
```azurecli
116+
# Environment variable for container command line
117+
PURGE_CMD="mcr.microsoft.com/acr/acr-cli:0.1 purge \
118+
--registry {{.Run.Registry}} \
119+
--filter \"samples/devimage1:.*\" --filter \"samples/devimage2:.*\" \
120+
--ago 0d --untagged --dry-run"
121+
104122
az acr run \
105-
--cmd "mcr.microsoft.com/acr/acr-cli:0.1 purge --registry {{.Run.Registry}} --filter "devimage1:.*" --filter "devimage2:.*" --ago 0d --untagged --dry-run" \
123+
--cmd "$PURGE_CMD" \
106124
--registry myregistry \
107125
/dev/null
108126
```
@@ -113,18 +131,18 @@ Sample output:
113131

114132
```console
115133
[...]
116-
Deleting tags for repository: devimage1
117-
myregistry.azurecr.io/devimage1:232889b
118-
myregistry.azurecr.io/devimage1:a21776a
119-
Deleting manifests for repository: devimage1
120-
myregistry.azurecr.io/devimage1@sha256:81b6f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e788b
121-
myregistry.azurecr.io/devimage1@sha256:3ded859790e68bd02791a972ab0bae727231dc8746f233a7949e40f8ea90c8b3
122-
Deleting tags for repository: devimage2
123-
myregistry.azurecr.io/devimage2:5e788ba
124-
myregistry.azurecr.io/devimage2:f336b7c
125-
Deleting manifests for repository: devimage2
126-
myregistry.azurecr.io/devimage2@sha256:8d2527cde610e1715ad095cb12bc7ed169b60c495e5428eefdf336b7cb7c0371
127-
myregistry.azurecr.io/devimage2@sha256:ca86b078f89607bc03ded859790e68bd02791a972ab0bae727231dc8746f233a
134+
Deleting tags for repository: samples/devimage1
135+
myregistry.azurecr.io/samples/devimage1:232889b
136+
myregistry.azurecr.io/samples/devimage1:a21776a
137+
Deleting manifests for repository: samples/devimage1
138+
myregistry.azurecr.io/samples/devimage1@sha256:81b6f9c92844bbbb5d0a101b22f7c2a7949e40f8ea90c8b3bc396879d95e788b
139+
myregistry.azurecr.io/samples/devimage1@sha256:3ded859790e68bd02791a972ab0bae727231dc8746f233a7949e40f8ea90c8b3
140+
Deleting tags for repository: samples/devimage2
141+
myregistry.azurecr.io/samples/devimage2:5e788ba
142+
myregistry.azurecr.io/samples/devimage2:f336b7c
143+
Deleting manifests for repository: samples/devimage2
144+
myregistry.azurecr.io/samples/devimage2@sha256:8d2527cde610e1715ad095cb12bc7ed169b60c495e5428eefdf336b7cb7c0371
145+
myregistry.azurecr.io/samples/devimage2@sha256:ca86b078f89607bc03ded859790e68bd02791a972ab0bae727231dc8746f233a
128146

129147
Number of deleted tags: 4
130148
Number of deleted manifests: 4
@@ -136,11 +154,17 @@ Number of deleted manifests: 4
136154
After you've verified the dry run, create a scheduled task to automate the purge. The following example schedules a weekly task on Sunday at 1:00 UTC to run the previous purge command:
137155

138156
```azurecli
157+
# Environment variable for container command line
158+
PURGE_CMD="mcr.microsoft.com/acr/acr-cli:0.1 purge \
159+
--registry {{.Run.Registry}} \
160+
--filter \"samples/devimage1:.*\" --filter \"samples/devimage2:.*\" \
161+
--ago 0d --untagged --dry-run"
162+
139163
az acr task create --name weeklyPurgeTask \
140-
--cmd "mcr.microsoft.com/acr/acr-cli:0.1 purge --registry {{.Run.Registry}} --filter "devimage1:.*" --filter "devimage2:.*" --ago 0d --untagged" \
141-
--context /dev/null \
164+
--cmd "$PURGE_CMD" \
142165
--schedule "0 1 * * Sun" \
143-
--registry myregistry
166+
--registry myregistry \
167+
--context /dev/null
144168
```
145169

146170
Run the [az acr task show][az-acr-task-show] command to see that the timer trigger is configured.

0 commit comments

Comments
 (0)