Azure 容器注册表保留策略

2024-01-10

我有一个 ACR,它包含适用于我的生产和开发环境的 docker 映像。由于每天都有新的图像被推送,我正在尝试设置保留策略。我的具体用例如下,

根据该图像,假设我在 ACR 中有 100 个图像,第 100 个图像由开发环境消耗。然而,生产运行的是第 40 个图像。话虽这么说,我需要保留生产环境和开发环境的当前和最后 2 个映像。例如,我需要保留第38、39和40张图像以及第98、99和100张图像。

我尝试使用acr purge。不幸的是,我不能在我的用例中使用保留策略或 acr 清除(根据我的理解,也许我是错的)。

任何人都可以帮助我解决这种情况吗?如果您需要更多信息或要求含糊,请告诉我!


请检查使用 azure CLI 命令的以下脚本是否可以工作:

哪个使用按标签删除 https://learn.microsoft.com/en-us/azure/container-registry/container-registry-delete#delete-by-tag方法。为此,您需要在系统上安装 azure cli。

$registryName = 'registryName'
$doNotDeleteTags = ''
$skipLastTags = 3

$repoArray = (az acr repository list --name $registryName --output json | ConvertFrom-Json)

foreach ($repo in $repoArray)
{
    $tagsArray = (az acr repository show-tags --name $registryName --repository $repo --orderby time_asc --output json | ConvertFrom-Json ) | Select-Object -SkipLast $skipLastTags

    foreach($tag in $tagsArray)
    {

        if ($donotdeletetags -contains $tag)
        {
            Write-Output ("This tag is not deleted $tag")
        }
        else
        {
            az acr repository delete --name $registryName --image $repo":"$tag --yes
        }
 
    }
}

参考:Azure容器注册表-删除除2之外的所有图像 - VoidCC https://stackoverflow.com/questions/57579940/azure-container-registry-delete-all-images-except-2

(Or)

az acr repository show-tags -n MyRegistry --repository MyRepository
 | ConvertFrom-String 
| %{$_.P2 -replace "[",]",""} 
| where {$_ -notin "skipthistag","andthistag" } 
| % {az acr repository delete --name MyRegistry --image MyRepository:$_ --yes}

参考:如何从Azure容器注册表中删除图像 - Thinbug https://stackoverflow.com/questions/41446962/how-to-delete-image-from-azure-container-registry/48660339#48660339


参考资料 - 跳过最后 x 张图像:

  1. 清理(​​ACR)|安德鲁·凯莱赫 https://medium.com/azure-architects/cleaning-up-azure-container-registry-acr-5409b41fea1a
  2. 用于删除旧 ACR 映像的 powershell 脚本 - Microsoft 问答 https://learn.microsoft.com/en-us/answers/questions/186849/schedule-powershell-script-to-delete-old-acr-image.html

其他参考:

  1. acr-cleanup:(github.com) https://github.com/goyalmohit/acr-cleanup
  2. 所以参考 https://stackoverflow.com/questions/57655112/script-to-delete-old-images-from-azure-container-registry
  3. (ACR):标签、清单和清理 |作者:阿南特·瓦尔丹 (Anant Vardhan)中等的 https://medium.com/@anantvardhan.04/azure-container-registry-acr-cleanup-dfeb8a8bb6a9
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Azure 容器注册表保留策略 的相关文章

随机推荐