1

我正在使用 Google Cloud build 来构建我的项目,但我想不出一种方法来使 Docker 的输出静音,同时它正在拉取图像以用于给定的构建步骤。例如,假设我有一个cloudbuild.yaml像这样的文件:

steps:
  - name: 'gradle:6.6.1-jdk11'
    entrypoint: bash
    args:
      - -c
      - |
        echo "bla"

当我运行此构建时,构建步骤的前 40(!)行包括:

Starting Step #0
Step #0 - "Build & push container": Pulling image: gradle:6.6.1-jdk11
Step #0 - "Build & push container": 6.6.1-jdk11: Pulling from library/gradle
Step #0 - "Build & push container": 5d9821c94847: Pulling fs layer
Step #0 - "Build & push container": a610eae58dfc: Pulling fs layer
Step #0 - "Build & push container": a40e0eb9f140: Pulling fs layer
Step #0 - "Build & push container": 1854bb447e96: Pulling fs layer
Step #0 - "Build & push container": efdba649c66e: Pulling fs layer
Step #0 - "Build & push container": 5541276c408d: Pulling fs layer
Step #0 - "Build & push container": 38817ec8e266: Pulling fs layer
Step #0 - "Build & push container": db18551b94a0: Pulling fs layer
Step #0 - "Build & push container": 1854bb447e96: Waiting
Step #0 - "Build & push container": efdba649c66e: Waiting
Step #0 - "Build & push container": 5541276c408d: Waiting
Step #0 - "Build & push container": 38817ec8e266: Waiting
Step #0 - "Build & push container": db18551b94a0: Waiting
Step #0 - "Build & push container": a610eae58dfc: Verifying Checksum
Step #0 - "Build & push container": a610eae58dfc: Download complete
Step #0 - "Build & push container": a40e0eb9f140: Verifying Checksum
Step #0 - "Build & push container": a40e0eb9f140: Download complete
Step #0 - "Build & push container": 5d9821c94847: Verifying Checksum
Step #0 - "Build & push container": 5d9821c94847: Download complete
Step #0 - "Build & push container": 1854bb447e96: Verifying Checksum
Step #0 - "Build & push container": 1854bb447e96: Download complete
Step #0 - "Build & push container": 5541276c408d: Verifying Checksum
Step #0 - "Build & push container": 5541276c408d: Download complete
Step #0 - "Build & push container": efdba649c66e: Verifying Checksum
Step #0 - "Build & push container": efdba649c66e: Download complete
Step #0 - "Build & push container": 38817ec8e266: Verifying Checksum
Step #0 - "Build & push container": 38817ec8e266: Download complete
Step #0 - "Build & push container": db18551b94a0: Verifying Checksum
Step #0 - "Build & push container": db18551b94a0: Download complete
Step #0 - "Build & push container": 5d9821c94847: Pull complete
Step #0 - "Build & push container": a610eae58dfc: Pull complete
Step #0 - "Build & push container": a40e0eb9f140: Pull complete
Step #0 - "Build & push container": 1854bb447e96: Pull complete
Step #0 - "Build & push container": efdba649c66e: Pull complete
Step #0 - "Build & push container": 5541276c408d: Pull complete
Step #0 - "Build & push container": 38817ec8e266: Pull complete
Step #0 - "Build & push container": db18551b94a0: Pull complete
Step #0 - "Build & push container": Digest: sha256:c40a882448431c71719d33939ee5418db2333e3380e9940f632cdb597d230dcc
Step #0 - "Build & push container": Status: Downloaded newer image for gradle:6.6.1-jdk11
Step #0 - "Build & push container": docker.io/library/gradle:6.6.1-jdk11

这是我不需要的信息,我想关闭pull进程的日志记录,但我找不到任何配置选项可以这样做。

4

1 回答 1

0

我想出了一个,嗯,不是真正的解决方案,而是更多的解决方法。如果您在实际处理图像的步骤之前使用启用开关的步骤拉动图像,-q您将获得更少的噪音。诀窍是docker pull使用已缓存在 Cloud Build 节点上的 Google 图像(gcr.io/cloud-builders/docker在本例中),因此它也不必获取该图像。YAML 看起来像这样:

steps:
  - name: 'gcr.io/cloud-builders/docker'
    id: "Prefetch Gradle container"
    args: [ "pull", "-q", "gradle:6.6.1-jdk11" ]
  - name: 'gradle:6.6.1-jdk11'
    entrypoint: bash
    args:
      - -c
      - |
        echo "bla"

输出如下所示:

Starting Step #0 - "Prefetch Gradle container"
Step #0 - "Prefetch Gradle container": Already have image (with digest): gcr.io/cloud-builders/docker
Step #0 - "Prefetch Gradle container": docker.io/library/gradle:6.6.1-jdk11
Finished Step #0 - "Prefetch Gradle container"
Starting Step #1 - "Build & push container"
Step #1 - "Build & push container": Already have image: gradle:6.6.1-jdk11

这不是很理想,因为额外的步骤比仅拉取映像花费的 Cloud Build 时间更长(不确定为什么),但它确实消除了许多不必要的日志行。

于 2020-09-30T21:44:20.400 回答