Skip to content

Commit

Permalink
Update purge.ps1
Browse files Browse the repository at this point in the history
  • Loading branch information
Plabick committed Aug 5, 2021
1 parent 993075e commit 8ddd7aa
Showing 1 changed file with 27 additions and 23 deletions.
50 changes: 27 additions & 23 deletions purge.ps1
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
param (
[Parameter(Mandatory = $false)]$registry = $env:registry,
[Parameter(Mandatory = $false)]$username = $env:username ,
[Parameter(Mandatory = $false)]$tenant = $env:tenant,
[Parameter(Mandatory = $false)]$password = $env:password,
[Parameter(Mandatory = $false)]$repoTarget = $env:repo,
[Parameter(Mandatory = $false)]$tagRegex = $env:tagRegex,
[Parameter(Mandatory = $false)]$repoRegex = $env:repoRegex ,
[Parameter(Mandatory = $false)]$daysToKeep = $env:daysToKeep,
[Parameter(Mandatory = $false)]$keep = $env:keep,
[Parameter(Mandatory = $false)]$dryRun = $env:dryRun
[Parameter(Mandatory = $false)]$registry = $env:registry,
[Parameter(Mandatory = $false)]$username = $env:username ,
[Parameter(Mandatory = $false)]$tenant = $env:tenant,
[Parameter(Mandatory = $false)]$password = $env:password,
[Parameter(Mandatory = $false)]$repoTarget = $env:repo,
[Parameter(Mandatory = $false)]$tagRegex = $env:tagRegex,
[Parameter(Mandatory = $false)]$repoRegex = $env:repoRegex ,
[Parameter(Mandatory = $false)]$daysToKeep = $env:daysToKeep,
[Parameter(Mandatory = $false)]$keep = $env:keep,
[Parameter(Mandatory = $false)]$dryRun = $env:dryRun,
[Parameter(Mandatory = $false)]$deleteUntagged = $env:deleteUntagged
)
az login --service-principal -u $username -p $password --tenant $tenant
Write-Host "-----Logged In -----"
If ($dryRun -eq $true) {
echo "----- Conducting Dry Run -----"
$dryRunCommand = "--dry-run"
} Else {
$dryRunCommand = ""}
Write-Output "-----Dry Run-----"
$dryRunCommand = "--dry-run"
}
Else {
$dryRunCommand = ""
}
$deleteUntaggedCommand = If ($deleteUntagged -eq $true) { "--untagged" } { "" }
if ($repoTarget -eq "all") {
$REPOS = az acr repository list -n $registry | Where-Object { ($_ –ne "[") -and ($_ –ne "]") }
foreach ($REPO in $REPOS) {
if ($REPO -match $repoRegex) {
$REPO = $REPO.Replace(" ", "").Replace(",", "")
Write-Output "----- Purging $REPO -----"
az acr run --registry $registry --cmd "acr purge --ago ${daysToKeep}d --keep $keep --filter '${REPO}:$tagRegex' $dryRunCommand" /dev/null
}
}
$REPOS = az acr repository list -n $registry | Where-Object { ($_ –ne "[") -and ($_ –ne "]") }
foreach ($REPO in $REPOS) {
if ($REPO -match $repoRegex) {
$REPO = $REPO.Replace(" ", "").Replace(",", "")
Write-Output "----- Purging $REPO -----"
az acr run --registry $registry --cmd "acr purge --ago ${daysToKeep}d --keep $keep --filter '${REPO}:$tagRegex' $dryRunCommand $deleteUntaggedCommand" /dev/null
}
}
}
else {
az acr run --registry $registry --cmd "acr purge --ago ${daysToKeep}d --keep $keep --filter '${repoTarget}:$tagRegex' $dryRunCommand" /dev/null
az acr run --registry $registry --cmd "acr purge --ago ${daysToKeep}d --keep $keep --filter '${repoTarget}:$tagRegex' $dryRunCommand $deleteUntaggedCommand" /dev/null
}

0 comments on commit 8ddd7aa

Please sign in to comment.