简体   繁体   English

在多个 GitHub 项目之间共享(参数化)cloudbuild.yaml?

[英]Share (parameterized) cloudbuild.yaml between multiple GitHub projects?

I've managed to trigger a Google Cloud Build on every commit to GitHub successfully.我成功地在每次提交 GitHub 时触发了 Google Cloud Build。 However, we have many different source code repositories (projects) on GitHub, that all use Maven and Spring Boot, and I would like all of these projects to use the same cloudbuild.yaml (or a shared template). However, we have many different source code repositories (projects) on GitHub, that all use Maven and Spring Boot, and I would like all of these projects to use the same cloudbuild.yaml (or a shared template). This way we don't need to duplicate the cloudbuild.yaml in all projects (it'll be essentially the same in most projects).这样我们就不需要在所有项目中复制cloudbuild.yaml (在大多数项目中基本相同)。

For example, let's just take two different projects on GitHub, A and B. Their cloudbuild.yaml files could look something like this (but much more complex in our actual projects):例如,让我们在 GitHub、A 和 B 上进行两个不同的项目。它们的cloudbuild.yaml文件可能看起来像这样(但在我们的实际项目中要复杂得多):

Project A:项目一:

steps:
  - name: maven:3.8.6-eclipse-temurin-17-alpine
    entrypoint: mvn
    args: [ 'test' ]
  - name: maven:3.8.6-eclipse-temurin-17-alpine
    entrypoint: mvn
    args: [ 'package', '-Dmaven.test.skip=true' ]
  - name: gcr.io/cloud-builders/docker
    args: [ "build", "-t", "europe-west1-docker.pkg.dev/projectname/repo/project-a", "--build-arg=JAR_FILE=target/project-a.jar", "." ]
images: [ "europe-west1-docker.pkg.dev/projectname/repo/project-a" ]

Project B:项目B:

steps:
  - name: maven:3.8.6-eclipse-temurin-17-alpine
    entrypoint: mvn
    args: [ 'test' ]
  - name: maven:3.8.6-eclipse-temurin-17-alpine
    entrypoint: mvn
    args: [ 'package', '-Dmaven.test.skip=true' ]
  - name: gcr.io/cloud-builders/docker
    args: [ "build", "-t", "europe-west1-docker.pkg.dev/projectname/repo/project-a", "--build-arg=JAR_FILE=target/project-b.jar", "." ]
images: [ "europe-west1-docker.pkg.dev/projectname/repo/project-b" ]

The only thing that is different is the jar file and image name, the steps are the same.唯一不同的是jar文件和镜像名称,步骤相同。 Now imagine having hundreds of such projects, it can become a maintenance nightmare if we need to change or add a build step for each project.现在想象一下拥有数百个这样的项目,如果我们需要为每个项目更改或添加构建步骤,这可能会成为维护的噩梦。

A better approach, in my mind, would be to have a template file that could be shared:在我看来,更好的方法是拥有一个可以共享的模板文件:

steps:
  - name: maven:3.8.6-eclipse-temurin-17-alpine
    entrypoint: mvn
    args: [ 'test' ]
  - name: maven:3.8.6-eclipse-temurin-17-alpine
    entrypoint: mvn
    args: [ 'package', '-Dmaven.test.skip=true' ]
  - name: gcr.io/cloud-builders/docker
    args: [ "build", "-t", "europe-west1-docker.pkg.dev/projectname/repo/${PROJECT_NAME}", "--build-arg=JAR_FILE=target/${PROJECT_NAME}.jar", "." ]
images: [ "europe-west1-docker.pkg.dev/projectname/repo/${PROJECT_NAME}" ]

It would then be great if such a template file could be uploaded to GCS and then reused in the cloudbuild.yaml file in each project:如果可以将这样的模板文件上传到 GCS,然后在每个项目的cloudbuild.yaml文件中重复使用,那就太好了:

Project A:项目一:

steps:
  import:
    gcs: gs:/my-build-bucket/cloudbuild-template.yaml
    parameters: 
      PROJECT_NAME: project-a

Project B:项目B:

steps:
  import:
    gcs: gs:/my-build-bucket/cloudbuild-template.yaml
    parameters: 
      PROJECT_NAME: project-b

Does such a thing exists for Google Cloud Build? Google Cloud Build 是否存在这样的事情? How do you import/reuse build steps in different builds as I described above?如上所述,您如何在不同的构建中导入/重用构建步骤? What's the recommended way to achieve this?实现这一目标的推荐方法是什么?

I contacted Google Cloud support and they told me that this is not currently available.我联系了 Google Cloud 支持,他们告诉我这目前不可用。 They are aware of the issue and it's something that they're working on (no eta on when it's going to be available).他们意识到了这个问题,这是他们正在努力的事情(没有关于何时可用的 eta)。

Their recommendation, in the meantime, is to use Tekton .与此同时,他们的建议是使用Tekton

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Google App 引擎不读取 cloudbuild.yaml 文件 - Google App engine dosen't read the cloudbuild.yaml file 为什么 Cloud Code 不尊重我的 cloudbuild.yaml 文件,但 gcloud beta 构建提交是? - Why isn't Cloud Code honoring my cloudbuild.yaml file but gcloud beta builds submit is? 您知道配置云运行以从 cloudbuild.yaml 设置 cloudsql 的任何方法吗? - Do you know any way of configuring cloud run to set a cloudsql from a cloudbuild.yaml? 从工件注册表中删除图像时如何忽略 cloudbuild.yaml 中的“找不到图像”错误? - How to ignore "image not found" error in cloudbuild.yaml when deleting images from the artifact registry? Cloud Build 不会将我的 Docker 图像推送到带有 cloudbuild.yaml 图像字段的 Artifact Registry - Cloud Build does not push my Docker image to Artifact Registry with images field in cloudbuild.yaml 如何使用 Google Ko 构建和推送 Go 映像?你能告诉我 cloudbuild.yaml 创建映像并使用 Google 推送 go 映像的步骤吗? - How to build and push Go image using Google Ko?Could you tell me the steps for cloudbuild.yaml to create the image and push go image using Google ko? 使用 CloudBuild 创建 GitHub 版本 - Create GitHub release using CloudBuild 通过 Cloudbuild 将整数替换为 Dataflow yaml - Substitute ints into Dataflow via Cloudbuild yaml 使用 YAML 管道构建和部署多个 azure function 项目 - Build and Deploy multiple azure function projects using YAML pipeline 如何使用 cloudbuild 将秘密管理器秘密传递给 app.yaml 中的应用引擎环境变量 - How Can I pass secret manager secret using cloudbuild to app engine environment variable in app.yaml
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM