问题描述
GitHub 的
您可以通过在存储库的根目录中添加一个 cloudbuild.yaml
并使用一个 gcr.io/cloud-builders/gcloud
步骤.这一步应该:
- 遍历每个子目录或使用
find
来定位其他cloudbuild.yaml
文件. - 对于每个找到的
cloudbuild.yaml
,通过运行gcloud builds submit
fork 并提交构建. - 等待所有分叉的
gcloud
命令完成.
中有一个很好的例子说明了一种方法可以做到这一点cloudbuild.yaml
位于 GoogleCloudPlatform/cloud-builders-community
repo.
如果我们去掉非必要的部分,基本上你会有这样的东西:
步骤:- 名称:'gcr.io/cloud-builders/gcloud'入口点:'bash'参数:- '-C'- |对于 d 在 */;做config="${d}cloudbuild.yaml"如果 [[ !-f "${config}" ]];然后继续菲echo "正在建造 $d ... "(gcloud 构建提交 $d --config=${config}) &完毕等待
GitHub's Google Cloud Build integration does not detect a cloudbuild.yaml
or Dockerfile
if it is not in the root of the repository.
When using a monorepo that contains multiple cloudbuild.yamls
, how can GitHub's Google Cloud Build integration be configured to detect the correct cloudbuild.yaml
?
File paths:
services/api/cloudbuild.yaml
services/nginx/cloudbuild.yaml
services/websocket/cloudbuild.yaml
Cloud Build integration output:
You can do this by adding a cloudbuild.yaml
in the root of your repository with a single gcr.io/cloud-builders/gcloud
step. This step should:
- Traverse each subdirectory or use
find
to locate additionalcloudbuild.yaml
files. - For each found
cloudbuild.yaml
, fork and submit a build by runninggcloud builds submit
. - Wait for all the forked
gcloud
commands to complete.
There's a good example of one way to do this in the root cloudbuild.yaml
within the GoogleCloudPlatform/cloud-builders-community
repo.
If we strip out the non-essential parts, basically you have something like this:
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
这篇关于GitHub Cloud Build 与 monorepo 中的多个 cloudbuild.yaml 集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!