Last active
August 19, 2021 08:44
-
-
Save Dirnei/f06039ba2f6746f4a31c380d5e54aedd to your computer and use it in GitHub Desktop.
Azure ACR image cleanup
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
[string]$repo, | |
[string]$image, | |
[int]$keep | |
) | |
az acr login -n $repo | |
$keep += 1; | |
$response = az acr repository show-tags -n hugin --repository $image | |
$tags = @() | |
$skipped = $False | |
foreach($entry in $response){ | |
$entry = $entry.Trim() | |
if($skipped -ne $True) { | |
$skipped = $True | |
continue; | |
} | |
if($entry.length -lt 4){ | |
continue; | |
} | |
$n = 3; | |
if(-not $entry.contains(",")){ | |
$n -= 1; | |
} | |
$tag = $entry.Substring(1, $entry.length-$n) | |
$tags += $tag | |
} | |
for($i = $tags.length-$keep; $i -ge 0; $i--) { | |
$tag = $tags[$i] | |
$fullname = "${image}:$tag" | |
Write-Host "[$i] Deleting image $fullname" | |
az acr repository delete -y --name hugin --image $fullname | |
} | |
Write-Host "Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment