Skip to content

Commit 9c58368

Browse files
authored
Merge pull request #156085 from dlepow/acrreten
[ACR] Retention policy/delete updates
2 parents f283b29 + 9394089 commit 9c58368

File tree

3 files changed

+35
-99
lines changed

3 files changed

+35
-99
lines changed

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,17 @@
22
title: Purge tags and manifests
33
description: Use a purge command to delete multiple tags and manifests from an Azure container registry based on age and a tag filter, and optionally schedule purge operations.
44
ms.topic: article
5-
ms.date: 02/19/2021
5+
ms.date: 05/07/2021
66
---
77

88
# Automatically purge images from an Azure container registry
99

1010
When you use an Azure container registry as part of a development workflow, the registry can quickly fill up with images or other artifacts that aren't needed after a short period. You might want to delete all tags that are older than a certain duration or match a specified name filter. To delete multiple artifacts quickly, this article introduces the `acr purge` command you can run as an on-demand or [scheduled](container-registry-tasks-scheduled.md) ACR Task.
1111

12-
The `acr purge` command is currently distributed in a public container image (`mcr.microsoft.com/acr/acr-cli:0.4`), built from source code in the [acr-cli](https://github.com/Azure/acr-cli) repo in GitHub.
12+
The `acr purge` command is currently distributed in a public container image (`mcr.microsoft.com/acr/acr-cli:0.4`), built from source code in the [acr-cli](https://github.com/Azure/acr-cli) repo in GitHub. `acr purge` is currently in preview.
1313

1414
You can use the Azure Cloud Shell or a local installation of the Azure CLI to run the ACR task examples in this article. If you'd like to use it locally, version 2.0.76 or later is required. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli-install].
1515

16-
> [!IMPORTANT]
17-
> This feature is currently in preview. Previews are made available to you on the condition that you agree to the [supplemental terms of use][terms-of-use]. Some aspects of this feature may change prior to general availability (GA).
18-
1916
> [!WARNING]
2017
> Use the `acr purge` command with caution--deleted image data is UNRECOVERABLE. If you have systems that pull images by manifest digest (as opposed to image name), you should not purge untagged images. Deleting untagged images will prevent those systems from pulling the images from your registry. Instead of pulling by manifest, consider adopting a *unique tagging* scheme, a [recommended best practice](container-registry-image-tag-version.md).
2118

articles/container-registry/container-registry-delete.md

Lines changed: 13 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
title: Delete image resources
33
description: Details on how to effectively manage registry size by deleting container image data using Azure CLI commands.
44
ms.topic: article
5-
ms.date: 07/31/2019
5+
ms.date: 05/07/2021
66
---
77

8-
# Delete container images in Azure Container Registry using the Azure CLI
8+
# Delete container images in Azure Container Registry
99

1010
To maintain the size of your Azure container registry, you should periodically delete stale image data. While some container images deployed into production may require longer-term storage, others can typically be deleted more quickly. For example, in an automated build and test scenario, your registry can quickly fill with images that might never be deployed, and can be purged shortly after completing the build and test pass.
1111

@@ -15,10 +15,11 @@ Because you can delete image data in several different ways, it's important to u
1515
* Delete by [tag](#delete-by-tag): Deletes an image, the tag, all unique layers referenced by the image, and all other tags associated with the image.
1616
* Delete by [manifest digest](#delete-by-manifest-digest): Deletes an image, all unique layers referenced by the image, and all tags associated with the image.
1717

18-
Sample scripts are provided to help automate delete operations.
19-
2018
For an introduction to these concepts, see [About registries, repositories, and images](container-registry-concepts.md).
2119

20+
> [!NOTE]
21+
> After you delete image data, Azure Container Registry stops billing you immediately for the associated storage. However, the registry recovers the associated storage space using an asynchronous process. It takes some time before the registry cleans up layers and shows the updated storage usage.
22+
2223
## Delete repository
2324

2425
Deleting a repository deletes all of the images in the repository, including all tags, unique layers, and manifests. When you delete a repository, you recover the storage space used by the images that reference unique layers in that repository.
@@ -102,7 +103,7 @@ The `acr-helloworld:v2` image is deleted from the registry, as is any layer data
102103

103104
To maintain the size of a repository or registry, you might need to periodically delete manifest digests older than a certain date.
104105

105-
The following Azure CLI command lists all manifest digest in a repository older than a specified timestamp, in ascending order. Replace `<acrName>` and `<repositoryName>` with values appropriate for your environment. The timestamp could be a full date-time expression or a date, as in this example.
106+
The following Azure CLI command lists all manifest digests in a repository older than a specified timestamp, in ascending order. Replace `<acrName>` and `<repositoryName>` with values appropriate for your environment. The timestamp could be a full date-time expression or a date, as in this example.
106107

107108
```azurecli
108109
az acr repository show-manifests --name <acrName> --repository <repositoryName> \
@@ -196,85 +197,21 @@ As mentioned in the [Manifest digest](container-registry-concepts.md#manifest-di
196197

197198
As you can see in the output of the last step in the sequence, there is now an orphaned manifest whose `"tags"` property is an empty list. This manifest still exists within the registry, along with any unique layer data that it references. **To delete such orphaned images and their layer data, you must delete by manifest digest**.
198199

199-
## Delete all untagged images
200-
201-
You can list all untagged images in your repository using the following Azure CLI command. Replace `<acrName>` and `<repositoryName>` with values appropriate for your environment.
202-
203-
```azurecli
204-
az acr repository show-manifests --name <acrName> --repository <repositoryName> --query "[?tags[0]==null].digest"
205-
```
206-
207-
Using this command in a script, you can delete all untagged images in a repository.
208-
209-
> [!WARNING]
210-
> Use the following sample scripts with caution--deleted image data is UNRECOVERABLE. If you have systems that pull images by manifest digest (as opposed to image name), you should not run these scripts. Deleting untagged images will prevent those systems from pulling the images from your registry. Instead of pulling by manifest, consider adopting a *unique tagging* scheme, a [recommended best practice](container-registry-image-tag-version.md).
211-
212-
**Azure CLI in Bash**
213-
214-
The following Bash script deletes all untagged images from a repository. It requires the Azure CLI and **xargs**. By default, the script performs no deletion. Change the `ENABLE_DELETE` value to `true` to enable image deletion.
215-
216-
```bash
217-
#!/bin/bash
218-
219-
# WARNING! This script deletes data!
220-
# Run only if you do not have systems
221-
# that pull images via manifest digest.
222-
223-
# Change to 'true' to enable image delete
224-
ENABLE_DELETE=false
225-
226-
# Modify for your environment
227-
REGISTRY=myregistry
228-
REPOSITORY=myrepository
200+
## Automatically purge tags and manifests
229201

230-
# Delete all untagged (orphaned) images
231-
if [ "$ENABLE_DELETE" = true ]
232-
then
233-
az acr repository show-manifests --name $REGISTRY --repository $REPOSITORY --query "[?tags[0]==null].digest" -o tsv \
234-
| xargs -I% az acr repository delete --name $REGISTRY --image $REPOSITORY@% --yes
235-
else
236-
echo "No data deleted."
237-
echo "Set ENABLE_DELETE=true to enable image deletion of these images in $REPOSITORY:"
238-
az acr repository show-manifests --name $REGISTRY --repository $REPOSITORY --query "[?tags[0]==null]" -o tsv
239-
fi
240-
```
241-
242-
**Azure CLI in PowerShell**
243-
244-
The following PowerShell script deletes all untagged images from a repository. It requires PowerShell and the Azure CLI. By default, the script performs no deletion. Change the `$enableDelete` value to `$TRUE` to enable image deletion.
245-
246-
```powershell
247-
# WARNING! This script deletes data!
248-
# Run only if you do not have systems
249-
# that pull images via manifest digest.
250-
251-
# Change to '$TRUE' to enable image delete
252-
$enableDelete = $FALSE
253-
254-
# Modify for your environment
255-
$registry = "myregistry"
256-
$repository = "myrepository"
257-
258-
if ($enableDelete) {
259-
az acr repository show-manifests --name $registry --repository $repository --query "[?tags[0]==null].digest" -o tsv `
260-
| %{ az acr repository delete --name $registry --image $repository@$_ --yes }
261-
} else {
262-
Write-Host "No data deleted."
263-
Write-Host "Set `$enableDelete = `$TRUE to enable image deletion."
264-
az acr repository show-manifests --name $registry --repository $repository --query "[?tags[0]==null]" -o tsv
265-
}
266-
```
202+
Azure Container Registry provides the following automated methods to remove tags and manifests, and their associated unique layer data:
267203

204+
* Create an ACR task that runs the `acr purge` container command to delete all tags that are older than a certain duration or match a specified name filter. Optionally configure `acr purge` to delete untagged manifests.
268205

269-
## Automatically purge tags and manifests (preview)
206+
The `acr purge` container command is currently in preview. For more information, see [Automatically purge images from an Azure container registry](container-registry-auto-purge.md).
270207

271-
As an alternative to scripting Azure CLI commands, run an on-demand or scheduled ACR task to delete all tags that are older than a certain duration or match a specified name filter. For more information, see [Automatically purge images from an Azure container registry](container-registry-auto-purge.md).
208+
* Optionally set a [retention policy](container-registry-retention-policy.md) for each registry, to manage untagged manifests. When you enable a retention policy, image manifests in the registry that don't have any associated tags, and the underlying layer data, are automatically deleted after a set period.
272209

273-
Optionally set a [retention policy](container-registry-retention-policy.md) for each registry, to manage untagged manifests. When you enable a retention policy, image manifests in the registry that don't have any associated tags, and the underlying layer data, are automatically deleted after a set period.
210+
The retention policy is currently a preview feature of **Premium** container registries. The retention policy only applies to untagged manifests created after the policy takes effect.
274211

275212
## Next steps
276213

277-
For more information about image storage in Azure Container Registry see [Container image storage in Azure Container Registry](container-registry-storage.md).
214+
For more information about image storage in Azure Container Registry, see [Container image storage in Azure Container Registry](container-registry-storage.md).
278215

279216
<!-- IMAGES -->
280217
[manifest-digest]: ./media/container-registry-delete/01-manifest-digest.png

articles/container-registry/container-registry-retention-policy.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,32 @@
11
---
22
title: Policy to retain untagged manifests
3-
description: Learn how to enable a retention policy in your Azure container registry, for automatic deletion of untagged manifests after a defined period.
3+
description: Learn how to enable a retention policy in your Premium Azure container registry, for automatic deletion of untagged manifests after a defined period.
44
ms.topic: article
5-
ms.date: 10/02/2019
5+
ms.date: 04/26/2021
66
---
77

88
# Set a retention policy for untagged manifests
99

10-
Azure Container Registry gives you the option to set a *retention policy* for stored image manifests that don't have any associated tags (*untagged manifests*). When a retention policy is enabled, untagged manifests in the registry are automatically deleted after a number of days you set. This feature prevents the registry from filling up with artifacts that aren't needed and helps you save on storage costs. If the `delete-enabled` attribute of an untagged manifest is set to `false`, the manifest can't be deleted, and the retention policy doesn't apply.
10+
Azure Container Registry gives you the option to set a *retention policy* for stored image manifests that don't have any associated tags (*untagged manifests*). When a retention policy is enabled, untagged manifests in the registry are automatically deleted after a number of days you set. This feature prevents the registry from filling up with artifacts that aren't needed and helps you save on storage costs.
1111

1212
You can use the Azure Cloud Shell or a local installation of the Azure CLI to run the command examples in this article. If you'd like to use it locally, version 2.0.74 or later is required. Run `az --version` to find the version. If you need to install or upgrade, see [Install Azure CLI][azure-cli].
1313

14-
A retention policy is a feature of **Premium** container registries. For information about registry service tiers, see [Azure Container Registry service tiers](container-registry-skus.md).
15-
16-
> [!IMPORTANT]
17-
> This feature is currently in preview, and some [limitations apply](#preview-limitations). Previews are made available to you on the condition that you agree to the [supplemental terms of use][terms-of-use]. Some aspects of this feature may change prior to general availability (GA).
14+
A retention policy for untagged manifests is currently a preview feature of **Premium** container registries. For information about registry service tiers, see [Azure Container Registry service tiers](container-registry-skus.md).
1815

1916
> [!WARNING]
2017
> Set a retention policy with care--deleted image data is UNRECOVERABLE. If you have systems that pull images by manifest digest (as opposed to image name), you should not set a retention policy for untagged manifests. Deleting untagged images will prevent those systems from pulling the images from your registry. Instead of pulling by manifest, consider adopting a *unique tagging* scheme, a [recommended best practice](container-registry-image-tag-version.md).
2118
22-
## Preview limitations
23-
24-
* You can only set a retention policy for untagged manifests.
25-
* The retention policy currently applies only to manifests that are untagged *after* the policy is enabled. Existing untagged manifests in the registry aren't subject to the policy. To delete existing untagged manifests, see examples in [Delete container images in Azure Container Registry](container-registry-delete.md).
26-
2719
## About the retention policy
2820

2921
Azure Container Registry does reference counting for manifests in the registry. When a manifest is untagged, it checks the retention policy. If a retention policy is enabled, a manifest delete operation is queued, with a specific date, according to the number of days set in the policy.
3022

3123
A separate queue management job constantly processes messages, scaling as needed. As an example, suppose you untagged two manifests, 1 hour apart, in a registry with a retention policy of 30 days. Two messages would be queued. Then, 30 days later, approximately 1 hour apart, the messages would be retrieved from the queue and processed, assuming the policy was still in effect.
3224

25+
If the `delete-enabled` attribute of an untagged manifest is set to `false`, the manifest is locked and is not deleted by the policy.
26+
27+
> [!IMPORTANT]
28+
> The retention policy applies only to untagged manifests with timestamps *after* the policy is enabled. Untagged manifests in the registry with earlier timestamps aren't subject to the policy. For other options to delete image data, see examples in [Delete container images in Azure Container Registry](container-registry-delete.md).
29+
3330
## Set a retention policy - CLI
3431

3532
The following example shows you how to use the Azure CLI to set a retention policy for untagged manifests in a registry.
@@ -47,7 +44,9 @@ az acr config retention update --registry myregistry --status enabled --days 30
4744
The following example sets a policy to delete any manifest in the registry as soon as it's untagged. Create this policy by setting a retention period of 0 days.
4845

4946
```azurecli
50-
az acr config retention update --registry myregistry --status enabled --days 0 --type UntaggedManifests
47+
az acr config retention update \
48+
--registry myregistry --status enabled \
49+
--days 0 --type UntaggedManifests
5150
```
5251

5352
### Validate a retention policy
@@ -57,13 +56,14 @@ If you enable the preceding policy with a retention period of 0 days, you can qu
5756
1. Push a test image `hello-world:latest` image to your registry, or substitute another test image of your choice.
5857
1. Untag the `hello-world:latest` image, for example, using the [az acr repository untag][az-acr-repository-untag] command. The untagged manifest remains in the registry.
5958
```azurecli
60-
az acr repository untag --name myregistry --image hello-world:latest
59+
az acr repository untag \
60+
--name myregistry --image hello-world:latest
6161
```
6262
1. Within a few seconds, the untagged manifest is deleted. You can verify the deletion by listing manifests in the repository, for example, using the [az acr repository show-manifests][az-acr-repository-show-manifests] command. If the test image was the only one in the repository, the repository itself is deleted.
6363
64-
### Disable a retention policy
64+
### Manage a retention policy
6565
66-
To see the retention policy set in a registry, run the [az acr config retention show][az-acr-config-retention-show] command:
66+
To show the retention policy set in a registry, run the [az acr config retention show][az-acr-config-retention-show] command:
6767
6868
```azurecli
6969
az acr config retention show --registry myregistry
@@ -72,12 +72,14 @@ az acr config retention show --registry myregistry
7272
To disable a retention policy in a registry, run the [az acr config retention update][az-acr-config-retention-update] command and set `--status disabled`:
7373

7474
```azurecli
75-
az acr config retention update --registry myregistry --status disabled --type UntaggedManifests
75+
az acr config retention update \
76+
--registry myregistry --status disabled \
77+
--type UntaggedManifests
7678
```
7779

7880
## Set a retention policy - portal
7981

80-
You can also set a registry's retention policy in the [Azure portal](https://portal.azure.com). The following example shows you how to use the portal to set a retention policy for untagged manifests in a registry.
82+
You can also set a registry's retention policy in the [Azure portal](https://portal.azure.com).
8183

8284
### Enable a retention policy
8385

0 commit comments

Comments
 (0)