使用GCloud SDK CLI的GCR图像标签列表 [英] GCR Image Tag Listing using GCloud SDK CLI
问题描述
我正在尝试获取我的私人GCR存储库中所有标签的列表.我可以使用" gcloud容器映像列表标记"来完成此操作命令如下:
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
不过,我需要将列表弄平,以便我可以将标签"0.0.4"添加到和最新的"在单独的行中.我尝试了以下命令.
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'
这给了我输出,令我惊讶的是重复了" latest ".标记,但省略了" 0.0.4 "
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?
推荐答案
我能够复制您的观察结果,并认为这是一个错误.
I am able to repro your observation and think it's a bug.
-flatten
似乎正确枚举了 tags
,但错误地返回了列表中的最后一个值作为每个条目的值.
The --flatten
appears to correctly enumerate tags
but incorrectly returns the last value in the list as each entry's value.
在我的情况下,如果标签是 v1,v2,v3
,我得到:
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
我建议您在Google的问题跟踪器上针对>> Cloud SDK
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}'
或者:
gcloud container images list-tags gcr.io/${PROJECT}/${IMAGE} \
--format=json |\
jq -r '.[] | .digest as $D | .timestamp.datetime as $T | .tags[]| [$D,.,$T] | @csv'
这篇关于使用GCloud SDK CLI的GCR图像标签列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!