Azure 容器注册表保留策略
Azure Container Registry retention policy
我有一个 ACR,它包含 docker 个用于我的生产和开发环境的图像。由于每天都会推送新图像,因此我正在尝试设置保留策略。我的确切用例如下,
根据图片,假设我在ACR中有100张图片,第100张图片被开发环境消耗了。然而,生产运行第 40 个图像。话虽如此,我需要保留生产环境和开发环境的最新和最后两张图片。例如,我需要保留第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}
参考:
参考 - 跳过最后 x 张图片:
其他参考资料:
我有一个 ACR,它包含 docker 个用于我的生产和开发环境的图像。由于每天都会推送新图像,因此我正在尝试设置保留策略。我的确切用例如下,
根据图片,假设我在ACR中有100张图片,第100张图片被开发环境消耗了。然而,生产运行第 40 个图像。话虽如此,我需要保留生产环境和开发环境的最新和最后两张图片。例如,我需要保留第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}
参考:
参考 - 跳过最后 x 张图片:
其他参考资料: