Search code examples
gcloudgcloud-cli

GCR Image Tag Listing using GCloud SDK CLI


I'm trying to get list of all the tags in my private GCR repository. I could do that using "gcloud container images list-tags" command as follows:

gcloud container images list-tags gcr.io/project-id/REPONAME

DIGEST        TAGS          TIMESTAMP
6b5727be962a  0.0.4,latest  2020-06-25T14:14:48
4b8c3f9c6ab7  0.0.3         2020-06-22T08:56:01

However I need the list to be flatten so that i can get tags "0.0.4" and "latest" in separate rows. I tried following command.

gcloud container images list-tags gcr.io/project-id/REPONAME --flatten='[].tags'

This gave me output which is to my surprise repeating "latest" tag but ommiting "0.0.4"

DIGEST        TAGS    TIMESTAMP
6b5727be962a  latest  2020-06-25T14:14:48
6b5727be962a  latest  2020-06-25T14:14:48
4b8c3f9c6ab7  0.0.3   2020-06-22T08:56:01

What am I doing wrong, and how can I fix this?


Solution

  • I am able to repro your observation and think it's a bug.

    The --flatten appears to correctly enumerate tags but incorrectly returns the last value in the list as each entry's value.

    In my case, if the tags are v1,v2,v3, I get:

    gcloud container images list-tags gcr.io/${PROJECT}/${IMAGE} \
    --flatten="[].tags[]" \
    --format="value(tags)" \
    --filter="digest=${DIGEST}"
    v3
    v3
    v3
    

    I recommend you file a bug on Google's Issue Tracker for Cloud SDK

    jq

    If you have jq, perhaps:

    gcloud container images list-tags gcr.io/${PROJECT}/${IMAGE} \
    --format=json |\
     jq -r '.[] | .digest as $D | .timestamp.datetime as $T | .tags[]| {"digest":$D,"tag":.,"timestamp":$T}'
    

    Or:

    gcloud container images list-tags gcr.io/${PROJECT}/${IMAGE} \
    --format=json |\
     jq -r '.[] | .digest as $D | .timestamp.datetime as $T | .tags[]| [$D,.,$T] | @csv'