【问题标题】:GCR Image Tag Listing using GCloud SDK CLI使用 GCloud SDK CLI 列出 GCR 图像标签
【发布时间】:2020-07-15 14:44:23
【问题描述】:

我正在尝试获取我的私有 GCR 存储库中所有标签的列表。我可以使用“gcloud container images list-tags”命令来做到这一点,如下所示:

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”和“最新”。我尝试了以下命令。

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

这给了我输出,令我惊讶的是重复“latest”标签但省略了“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

我做错了什么,我该如何解决?

【问题讨论】:

    标签: gcloud gcloud-cli


    【解决方案1】:

    我能够重现您的观察并认为这是一个错误。

    --flatten 似乎正确枚举了tags,但错误地将列表中的最后一个值作为每个条目的值返回。

    在我的例子中,如果标签是v1,v2,v3,我得到:

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

    我建议您在 Google 的问题跟踪器上为 Cloud SDK 提交错误

    jq

    如果你有jq,也许:

    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 问题跟踪器上打开了问题,link 让我们看看。
    • 更新:@DazWilkin Google 已修复此问题,并计划成为 GCloud SDK 版本 325.0.0 的一部分,将于 2021 年 1 月 26 日星期二发布。
    猜你喜欢
    • 2018-03-17
    • 2019-06-19
    • 2021-06-17
    • 1970-01-01
    • 2020-03-01
    • 1970-01-01
    • 2018-11-21
    • 2016-05-13
    • 1970-01-01
    相关资源
    最近更新 更多