How to get the latest 20 or so image versions(tags) of an image pushed to google container registry?

1k views Asked by At

I need a list of the 20-30 latest image versions that have been pushed to the gcr using APIs.

I know that we can use https://cloud.google.com/sdk/gcloud/reference/container/images/list. But I want it using apis. I have used client.tags() from the registry-client api mentioned in https://github.com/google/nodejs-container-image-builder#registry-client-api. It provides all the image tags, but I need a list of recent image versions pushed, starting from most recent to least recent. Is there any module or API to accomplish this?

1

There are 1 answers

0
DazWilkin On

I'm unfamiliar with the specific SDK but familiar with GCR and the Registry API.

Is your issue that the client.tags() does not return timestamps?

One useful trick with gcloud is that you can append --log-http to any command to see what underlying API calls are being made by the command:

Here's an example using one of my public registries:

gcloud container images list-tags gcr.io/image-transparency/server \
--project=image-transparency \
--log-http

Results:

...
==== request start ====
uri: https://gcr.io/v2/image-transparency/server/tags/list
method: GET
== headers start ==
Authorization: --- Token Redacted ---
...
== headers end ==
==== request end ====
---- response start ----
...
-- body start --
{"child":[],"manifest":{"sha256:0e0a9839dcd8a6ab45fd62c0b70eb13b11af7258239be4114afa516bb7508172":{"imageSizeBytes":"8723924","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["7692bab2a81a9f1028387e07aa8b81c6a03eb92e"],"timeCreatedMs":"1563309309184","timeUploadedMs":"1563309938603"},"sha256:1d84df6f23968ea23ae1fa6ba47981931b0e8076598fffacfa275abdf94148dd":{"imageSizeBytes":"8227740","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["551904f38ccf2a1bfd45aac16a2c1ce4037975f2"],"timeCreatedMs":"1563400894425","timeUploadedMs":"1563400943736"},"sha256:4f762b4c9979fdbad84e07368ef1efef95c8f7e9cccb2bed96bfd95df42efac8":{"imageSizeBytes":"8611114","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["c9afbd4b428ad6dc8af291234bbe94f605cdbcd4"],"timeCreatedMs":"1562791496351","timeUploadedMs":"1562791551281"},"sha256:51fa2c1f378266ef5ee6f1f5137f16ff0bbde4c14585dae444dfc7923c1a4ed9":{"imageSizeBytes":"8611115","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["6b79683a1a3a3b83f314b4585e04b9e14e28081d"],"timeCreatedMs":"1562790199324","timeUploadedMs":"1562790247774"},"sha256:6e159709d9fe9e1bcfaccb1b7ceaad72b20da8ee8cfc2444cf617417c2e006e9":{"imageSizeBytes":"8722781","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":[],"timeCreatedMs":"1563305927430","timeUploadedMs":"1563305976876"},"sha256:8a2c0acf0fc06a45a5b04fc3411732bfa50f2115e60793d2d7f64ae9107253aa":{"imageSizeBytes":"8229487","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["034ca01c8d599dd8ef704986fee631ca3462a912"],"timeCreatedMs":"1563394435023","timeUploadedMs":"1563394483433"},"sha256:8b777848e959fc64c30a6e3f534c9a92f47418bd1e708364971b75c24d2a87ad":{"imageSizeBytes":"8611968","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["bcdc26eb174dca7cb44b2e5d8e958df7c5a04ba6"],"timeCreatedMs":"1562791134937","timeUploadedMs":"1562791306243"},"sha256:c5e1288b68bc941c9544123210e62e2ab1f66d44768116be8757b45e4cbf1b76":{"imageSizeBytes":"8611114","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["184fb77a23aa3a4a3a7d5f4ebcc9f398b012952e"],"timeCreatedMs":"1562795024694","timeUploadedMs":"1562795072187"},"sha256:d125cdfbf8b0a4db6b8043d51362bd20ce079b376bc28062a8a498d2edd79e82":{"imageSizeBytes":"8722781","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["d2be230c73035576ea3d802cdb49afbc7838f383"],"timeCreatedMs":"1563383711328","timeUploadedMs":"1563383757204"},"sha256:fd5d26d3a69772fbf590df11138d9599d9d71e269e068f8af136097fa2dd9095":{"imageSizeBytes":"8611115","layerId":"","mediaType":"application/vnd.docker.distribution.manifest.v2+json","tag":["8336372726d1489bdf6e48ae675a09d795ff8223"],"timeCreatedMs":"1562794705526","timeUploadedMs":"1562794752708"}},"name":"image-transparency/server","tags":["034ca01c8d599dd8ef704986fee631ca3462a912","184fb77a23aa3a4a3a7d5f4ebcc9f398b012952e","551904f38ccf2a1bfd45aac16a2c1ce4037975f2","6b79683a1a3a3b83f314b4585e04b9e14e28081d","7692bab2a81a9f1028387e07aa8b81c6a03eb92e","8336372726d1489bdf6e48ae675a09d795ff8223","bcdc26eb174dca7cb44b2e5d8e958df7c5a04ba6","c9afbd4b428ad6dc8af291234bbe94f605cdbcd4","d2be230c73035576ea3d802cdb49afbc7838f383"]}
-- body end --
total round trip time (request+response): 0.191 secs
---- response end ----
----------------------
DIGEST        TAGS                                      TIMESTAMP
1d84df6f2396  551904f38ccf2a1bfd45aac16a2c1ce4037975f2  2019-07-17T15:01:34
8a2c0acf0fc0  034ca01c8d599dd8ef704986fee631ca3462a912  2019-07-17T13:13:55
d125cdfbf8b0  d2be230c73035576ea3d802cdb49afbc7838f383  2019-07-17T10:15:11
0e0a9839dcd8  7692bab2a81a9f1028387e07aa8b81c6a03eb92e  2019-07-16T13:35:09
6e159709d9fe                                            2019-07-16T12:38:47
c5e1288b68bc  184fb77a23aa3a4a3a7d5f4ebcc9f398b012952e  2019-07-10T14:43:45
fd5d26d3a697  8336372726d1489bdf6e48ae675a09d795ff8223  2019-07-10T14:38:26
4f762b4c9979  c9afbd4b428ad6dc8af291234bbe94f605cdbcd4  2019-07-10T13:44:56
8b777848e959  bcdc26eb174dca7cb44b2e5d8e958df7c5a04ba6  2019-07-10T13:38:55
51fa2c1f3782  6b79683a1a3a3b83f314b4585e04b9e14e28081d  2019-07-10T13:23:19

GCR uses Docker's Registry API v2 (and, in my experience, implements the API correctly|fully). I recommend you consider exploring using it if the SDK is insufficient.

But please also file a feature request against the SDK.

I wrote about my experiences grokking the registry API here and include examples curl'ing GCR:

https://medium.com/google-cloud/adventures-w-docker-manifests-78f255d662ff