Skip to content

Instantly share code, notes, and snippets.

@qlikq
Last active July 20, 2021 09:44
Show Gist options
  • Save qlikq/734c47d0f742bcacfd74b1fe6da5cf22 to your computer and use it in GitHub Desktop.
Save qlikq/734c47d0f742bcacfd74b1fe6da5cf22 to your computer and use it in GitHub Desktop.
Obtain docker image tags list
function Get-DockerImageTag {
[CmdletBinding()]
param (
[string]$ImageName,
[switch]$OnlyActive
)
$FetchedRecords = New-Object System.Collections.ArrayList
try {
$fetchResult = (Invoke-WebRequest -Uri "https://registry.hub.docker.com/v2/repositories/library/$ImageName/tags/").Content | convertfrom-json
if ($fetchResult.count -gt 0) {
$FetchedRecords+= $fetchResult.results | select name, tag_status, tag_last_pushed
$url = $fetchResult.next
if ($url) {
do {
Write-Verbose "Processing next page $url"
$fetchResult = (Invoke-WebRequest -Uri $url).Content | convertfrom-json
$FetchedRecords+= $fetchResult.results | select name, tag_status, tag_last_pushed
$url = $fetchResult.next
} until ($null -eq $url)
}
}
else {
Throw "There are no tags present for $ImageName"
}
}
catch {
"Could not fetch tags for $imageName docker image. :: $_"
}
return ( $OnlyActive ) ? ($FetchedRecords | ?{$_.tag_status -eq 'active'}) : $FetchedRecords
}
<#
PS /home/greg> Get-DockerImageTag -ImageName 'registrfy'
Could not fetch tags for registrfy docker image. :: There are no tags present for registrfy
Get-DockerImageTag -ImageName registry -OnlyActive
name tag_status tag_last_pushed
---- ---------- ---------------
latest active 16/06/2021 17:06:39
2.7.1 active 16/06/2021 17:06:35
2.7 active 16/06/2021 17:06:34
2 active 16/06/2021 17:06:29
2.6.2 active 24/01/2020 01:38:43
2.6 active 24/01/2020 01:38:41
Get-DockerImageTag -ImageName registry
name tag_status tag_last_pushed
---- ---------- ---------------
latest active 16/06/2021 17:06:39
2.7.1 active 16/06/2021 17:06:35
2.7 active 16/06/2021 17:06:34
2 active 16/06/2021 17:06:29
2.6.2 active 24/01/2020 01:38:43
2.6 active 24/01/2020 01:38:41
2.5.2 inactive 10/05/2019 23:49:56
2.5 inactive 10/05/2019 23:49:53
2.7.0 inactive 04/01/2019 10:44:31
2.6.1 inactive 30/06/2017 01:05:26
2.6.1-rc.2 inactive 21/03/2017 22:49:12
2.6.0 inactive 21/03/2017 22:48:27
2.6.0-rc.2 inactive 27/12/2016 21:39:55
2.5.1 inactive 27/12/2016 21:39:19
2.6.0-rc.1 inactive 14/11/2016 17:36:50
2.5.0 inactive 02/08/2016 00:04:02
2.5.0-rc.2 inactive 06/07/2016 23:05:45
2.4.1 inactive 06/07/2016 23:05:26
2.4 inactive 06/07/2016 23:05:18
2.5.0-rc.1 inactive 23/06/2016 22:02:55
2.4.0 inactive 06/05/2016 22:24:56
2.3.1 inactive 04/04/2016 20:37:56
2.3 inactive 04/04/2016 20:37:49
2.3.0 inactive 03/03/2016 18:14:45
2.2.1 inactive 03/02/2016 00:11:03
2.2 inactive 03/02/2016 00:10:55
0.9.1 inactive 03/02/2016 00:10:36
0.8.1 inactive 03/02/2016 00:10:22
2.2.0 inactive 08/12/2015 07:16:15
0.6.1 inactive 14/11/2015 13:51:30
0.6.6 inactive 14/11/2015 13:49:58
0.6.8 inactive 14/11/2015 13:47:39
0.6.9 inactive 14/11/2015 13:45:06
0.7.1 inactive 14/11/2015 13:42:54
0.7.0 inactive 14/11/2015 13:42:31
0.8.0 inactive 14/11/2015 13:42:06
0.6.0 inactive 14/11/2015 13:40:03
0.9.0 inactive 14/11/2015 13:39:41
0.7.3 inactive 14/11/2015 13:37:49
0.6.2 inactive 14/11/2015 13:35:45
0.7.2 inactive 14/11/2015 13:35:27
0.5.9 inactive 14/11/2015 13:32:58
0.6.5 inactive 14/11/2015 13:30:50
0.6.3 inactive 14/11/2015 13:29:11
0.6.7 inactive 14/11/2015 13:28:37
0.6.4 inactive 14/11/2015 13:26:31
2.1.1 inactive 28/10/2015 10:09:45
2.1 inactive 28/10/2015 10:09:33
2.0 inactive
2.0.0 inactive
2.0.1 inactive
#>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment