Azure 容器注册表存储库映像自定义清理

问题描述 投票:0回答:1

有没有办法为Azure ACR存储库启用保留策略,其中只需要保留最后3个标签,其余的可以删除。此外,我们还必须从这些存储库中排除某些图像(可以使用正则表达式过滤器进行过滤,例如:图像具有前缀“base-image”)

bash shell azure-cli azure-container-registry
1个回答
0
投票

您可以使用删除操作来删除之前的标签。

Acr 删除标签

检查以下 Azure

CLI
脚本是否提供了满足您的功能的见解。

$reg = 'xxxx'
$skipLastTags = 3
$repositories = (az acr repository list --name $reg --output json | ConvertFrom-Json)
foreach ($repo in $repositories)
{
    $tags = (az acr repository show-tags --name $reg --repository $repo --orderby time_asc --output json | ConvertFrom-Json ) | Select-Object -SkipLast $skipLastTags
    foreach($tag in $tags)
    {
            az acr repository delete --name $reg --image $repo":"$tag --yes
 
    }
}

请参阅 SO 了解有关您的要求的更多相关信息。

© www.soinside.com 2019 - 2024. All rights reserved.