如何解决如何在 Cloud Build 中运行测试版 gcloud 组件,例如“gcloud beta artifacts docker images scan”?
我正在尝试将 Container Analyis API link 包含在 Cloud Build 管道中。这是一个测试版组件,我需要先使用命令行安装它:
gcloud components install beta local-extract
然后我可以运行按需容器分析(如果容器在本地存在):
gcloud beta artifacts docker images scan ubuntu:latest
我的问题是如何在 Cloud Build 中使用 beta local-extract 之类的组件?
我尝试迈出第一步并安装缺少的组件L
## Update components
- name: 'gcr.io/cloud-builders/gcloud'
args: ['components','install','beta','local-extract','-q']
id: Update component
但是一旦我进入下一步,更新就会消失(因为它不在容器中)
我也尝试安装该组件,然后使用 (& 或 ;) 运行扫描,但它失败了:
## Run vulnerability scan
- name: 'gcr.io/cloud-builders/gcloud'
args: ['components','-q',';','gcloud','artifacts','docker','images','scan','ubuntu:latest','--location=europe']
id: Run vulnaribility scan
我得到:
Already have image (with digest): gcr.io/cloud-builders/gcloud
ERROR: (gcloud.components.install) unrecognized arguments:
;
gcloud
beta
artifacts
docker
images
scan
ubuntu:latest
--location=europe (did you mean '--project'?)
To search the help text of gcloud commands,run:
gcloud help -- SEARCH_TERMS
所以我的问题是:
- 如何在 Cloud Build 中运行“gcloud beta artifacts docker images scan ubuntu:latest”?
- 奖励:从上一个命令中,我如何获得需要作为参数传递给下一步的“扫描”输出值? (我想它应该是带有 --format 的东西)
解决方法
您应该尝试使用 cloud-sdk
docker 镜像:
https://github.com/GoogleCloudPlatform/cloud-sdk-docker
Cloud Build 团队(暗示?)推荐它:
https://github.com/GoogleCloudPlatform/cloud-builders/tree/master/gcloud
使用 cloud-sdk-docker
容器,您可以将入口点更改为 bash
管道 gcloud
命令。这是一个(丑陋的)例子:
关于你的奖金问题。是的,--format=value(the.name.of.the.field)
可能就是您想要的。诀窍是知道字段的名称。我通常在我的开发工作站上以 --format=json
开头来找出名称。
问题来自 Cloud Build。它会缓存一些经常使用的图像,如果您想在 GCLOUD CLI 中使用全新功能,缓存可能会太旧。
我今晚做了一个测试,缓存中的版本是326。 328刚刚发布。因此,缓存版本已经使用了 2 周,对于您的功能来说可能太旧了。您所在地区的情况可能更糟!
解决此问题的解决方案是明确请求最新版本。
副作用是构建时间更长。事实上,因为这个最新的镜像没有被缓存,所以必须在 Cloud Build 中下载。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。