Created
March 24, 2020 20:16
-
-
Save adoprog/b4a62593d638aa878548287b1e139b5f to your computer and use it in GitHub Desktop.
Compare local Docker images with the ones in Azure Container Registry (ACR)
This file contains hidden or 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
$registry = "%registry name here, i.e. myregistry%" | |
$repositories = docker images --digests | % { $_ -replace " +", "," } | convertfrom-csv | where { $_.REPOSITORY.StartsWith($registry) } | group REPOSITORY | |
Write-Output "Found $($repositories.Count) local repositories from $($registry) registry" | |
foreach ($group in $repositories) { | |
$repository = $group.Name.Split('/')[1] | |
$remoteData = az acr repository show-tags -n $registry --repository $repository --detail | convertfrom-json | |
foreach ($localRepo in $group.Group) { | |
$localRepo | Add-Member -NotePropertyName REPO -NotePropertyValue $repository | |
$found = $false; | |
foreach ($remoteRepo in $remoteData ) { | |
if ($localRepo.TAG -eq $remoteRepo.Name) { | |
if ($localRepo.DIGEST -eq $remoteRepo.digest) { | |
$localRepo | Add-Member -NotePropertyName STATUS -NotePropertyValue "Up to date" | |
} | |
else { | |
$localRepo | Add-Member -NotePropertyName STATUS -NotePropertyValue "Outdated" | |
} | |
$found = $true; | |
} | |
} | |
if(!$found){ | |
$localRepo | Add-Member -NotePropertyName STATUS -NotePropertyValue "Not found" | |
} | |
} | |
Write-Output $group.Group | select REPO, TAG,@{ | |
Label = "STATUS" | |
Expression = | |
{ | |
switch ($_.Status) | |
{ | |
'Not found' { $color = "93"; break } | |
'Up to date' { $color = "32"; break } | |
'Outdated' { $color = "31"; break } | |
default { $color = "0" } | |
} | |
$e = [char]27 | |
"$e[${color}m$($_.Status)${e}[0m" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Example: