[英]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.