gpt4 book ai didi

google-cloud-platform - 如何在构建步骤中从 shell 脚本调用 gcloud 命令?

转载 作者:行者123 更新时间:2023-12-01 21:45:06 24 4
gpt4 key购买 nike

我在 Google Cloud 中设置了自动构建,因此每次我推送到存储库的 master 分支时,都会构建一个新镜像并将其推送到 Google Container Registry。

这些图像堆积得很快,我不需要所有旧的。所以我想添加一个运行 bash 脚本的构建步骤,该脚本调用 gcloud container images list-tags,循环结果,并使用 gcloud container images delete 删除旧的>.

我已经编写了脚本,它可以在本地运行。我无法弄清楚如何将它作为 Cloud Builder 中的一个步骤运行。

似乎有两种选择:

- name: 'ubuntu'
args: ['bash', './container-registry-cleanup.sh']

cloudbuild.yml 的上述步骤中,我尝试在 ubuntu 图像中运行 bash 命令。这不起作用,因为此图像中不存在 gcloud 命令。

- name: 'gcr.io/cloud-builders/gcloud'
args: [what goes here???]

cloudbuild.yml 的上述步骤中,我尝试使用 gcloud 图像,但由于“传递给此构建器的参数将传递给 gcloud 直接”,我不知道如何在这里调用我的 bash 脚本。

我能做什么?

最佳答案

您可以自定义构建步骤的入口点。如果您需要安装 gcloud,请使用 gcloud cloud builder 并执行此操作

step:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: "bash"
args:
- "-c"
- |
echo "enter 1 bash command per line"
ls -la
gcloud version
...

关于google-cloud-platform - 如何在构建步骤中从 shell 脚本调用 gcloud 命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60825651/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com