首页 > 解决方案 > GitHub Cloud Build 与 monorepo 中的多个 cloudbuild.yamls 集成

问题描述

GitHub 的Google Cloud Build 集成未检测到cloudbuild.yamlDockerfile不在存储库的根目录中。

当使用包含多个的 monorepo 时cloudbuild.yamls,如何配置 GitHub 的 Google Cloud Build 集成以检测正确的cloudbuild.yaml

文件路径:

services/api/cloudbuild.yaml
services/nginx/cloudbuild.yaml
services/websocket/cloudbuild.yaml

Cloud Build 集成输出:

构建失败

标签: google-cloud-platformmonorepogoogle-cloud-build

解决方案


您可以通过一个步骤cloudbuild.yaml在存储库的根目录中添加 a 来完成此操作gcr.io/cloud-builders/gcloud。此步骤应:

  1. 遍历每个子目录或用于find查找其他cloudbuild.yaml文件。
  2. 对于每个找到cloudbuild.yaml的,通过运行 fork 并提交一个构建gcloud builds submit
  3. 等待所有分叉的gcloud命令完成。

repo的根目录cloudbuild.yamlGoogleCloudPlatform/cloud-builders-community有一个很好的例子。

如果我们去掉非必要的部分,基本上你有这样的东西:

steps:
- name: 'gcr.io/cloud-builders/gcloud'
  entrypoint: 'bash'
  args:
  - '-c'
  - |
    for d in */; do
      config="${d}cloudbuild.yaml"
      if [[ ! -f "${config}" ]]; then
        continue
      fi

      echo "Building $d ... "
      (
        gcloud builds submit $d --config=${config}
      ) &
    done
    wait

推荐阅读