我已经设置了一个 Google Cloud Build 管道,该管道将从 Dockerfile 构建一个 docker 镜像,测试该镜像并将该镜像推送到 Google Container Registry。
在运行管道时,我注意到所有定义的步骤都以 SUCCESS
状态通过,但构建摘要本身以 FAILURE
状态返回,即使我可以看到正在生成的图像Google 容器注册表。
我使用下面的命令来构建图像
gcloud builds submit --config cloudbuild.yml --gcs-log-dir 'gs://<bucket>' .
下面是返回的错误信息:
ERROR: (gcloud.builds.submit) build www-xxxx-yyyy-zzzz completed with status "FAILURE"
🚨 Error: The command exited with status 1
如果所有步骤都标记为 SUCCESS
,gcloud builds submit
命令是否有任何理由以代码 1
退出?
下面是针对该特定构建从 gcloud builds describe
命令中获取的一些过滤日志数据。
steps:
- args:
- build
- -t
- <host>/<project/<image>:<tag>
- .
name: gcr.io/cloud-builders/docker
status: SUCCESS
- args:
- test
- --image
- <host>/<project/<image>:<tag>
- --config
- test_config.yml
- -o
- json
name: gcr.io/gcp-runtimes/container-structure-test
status: SUCCESS
以下是 Google Cloud Build 设置:
# cloudbuild.yml
steps:
# Build the image
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build', '-t', '<host>/<project/<image>:<tag>', '.' ]
# Test the image
- name: 'gcr.io/gcp-runtimes/container-structure-test'
args: [
'test',
'--image',
'<host>/<project/<image>:<tag>',
'--config',
'test_config.yml',
'-o',
'json'
]
# Push the image
images: [ '<host>/<project/<image>:<tag>' ]
最佳答案
在 Google Cloud 支持团队的帮助下,我终于解决了这个问题。
他们发现 403 Permission Denied
错误,因为 Cloud Build 容器试图访问 Google Cloud Storage 以删除存储在存储桶中的某个日志对象,此错误消息是在后台系统中找到的用户/客户无法访问的云构建。 403 Permission Denied
错误是应用于存储桶的对象保留策略的结果。
在我的例子中,我用生命周期策略替换了保留策略来解决这个问题并且它奏效了。我们这样做是因为我们认为控制 Cloud Build 日志大小是我们的主要目标,并且为了防止对日志文件的任何意外删除/修改,我们最终设置了对日志存储桶中资源的只读访问权限,除了Cloud Build 使用的服务帐户。
关于docker - Google Cloud Build - 摘要状态显示失败,所有步骤均成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67631058/