gpt4 book ai didi

Azure 容器注册表保留策略

转载 作者:行者123 更新时间:2023-12-02 23:05:55 25 4
gpt4 key购买 nike

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

ACR Usage

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

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

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

最佳答案

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

它使用 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 Container Registry - delete all images except 2 - Stack Overflow

(或)

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}

引用:How to delete image from Azure Container Registry - Stack Overflow

<小时/>

引用资料 - 跳过最后 x 张图像:

  1. Cleaning up (ACR) | Andrew Kelleher
  2. powershell script to delete old ACR image - MicrosoftQ&A

其他引用:

  1. acr-cleanup:(github.com)
  2. SO reference
  3. (ACR): Tags, Manifests and Cleanup | by Anant Vardhan | Medium

关于Azure 容器注册表保留策略,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70360107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com