docker - Google Cloud Build - 摘要状态显示失败,所有步骤均成功

标签 docker google-cloud-build google-container-registry

我已经设置了一个 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

如果所有步骤都标记为 SUCCESSgcloud 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/

相关文章:

docker - Docker保存问题

从主机远程安装卷时,Mongodb 不会在 Docker 容器中启动

kubernetes - 如何编写kubernetes部署以获取使用GCP cloudbuild构建的最新镜像

docker - 使用哪个GCP Compute Engine实例来构建Docker镜像?

docker - 如何覆盖/发现基本图像的 CMD/ENTRYPOINT

docker - Google App Engine 标准 Python 云构建

google-cloud-storage - 当我们在云构建上拉取 docker 镜像时如何避免高额下载费用

google-app-engine - 执行 : "gcc": executable file not found in $PATH

kubernetes - 复制 Controller 文件中的图像标记

django - 如何配置docker以将redis与celery一起使用