我可以使用多个 "to be continuous" 构建模板吗?
Can I use several "to be continuous" build templates?
我有一个 Git 存储库,其中有几个独立的应用程序,用多种语言开发 (a.k.a monorepo)。
在此存储库中,我可以使用多个 to be continuous 模板并行构建我的所有项目吗?
当然可以。
一些构建模板也支持parallel matrix jobs,允许您使用同一个模板处理多个项目。
例子
假设一个 GitLab 项目由以下内容组成:
app/
:前端应用程序,开发于 Angular
users-srv/
:第一个后端服务,在 Node 中开发,打包为 Docker 图像
orders-srv/
:第二个后端服务,在 Node 中开发,打包为 Docker 图像
tools/
:一些工具,在 Python 中开发
您的 .gitlab-ci.yml
文件应如下所示:
# included templates
include:
# Angular template
- project: "to-be-continuous/angular"
ref: "1.2.0"
file: "templates/gitlab-ci-angular.yml"
# Node.js template
- project: "to-be-continuous/node"
ref: "1.2.0"
file: "templates/gitlab-ci-node.yml"
# Python template
- project: "to-be-continuous/python"
ref: "1.2.0"
file: "templates/gitlab-ci-python.yml"
# Docker template
- project: "to-be-continuous/docker"
ref: "1.2.0"
file: "templates/gitlab-ci-docker.yml"
# variables
variables:
# path of the Angular project
NG_WORKSPACE_DIR: "app"
# path of the Python project
PYTHON_PROJECT_DIR: "tools"
# parallel matrix jobs for Node template
.node-base:
parallel:
matrix:
# path of the "users-srv" Node project
- NODE_PROJECT_DIR: "users-srv"
# path of the "orders-srv" Node project
- NODE_PROJECT_DIR: "orders-srv"
# parallel matrix jobs for Docker template
.docker-base:
parallel:
matrix:
# Docker config for project "users-srv"
- DOCKER_FILE: "users-srv/Dockerfile"
DOCKER_SNAPSHOT_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/users-srv/snapshot:$CI_COMMIT_REF_SLUG"
DOCKER_RELEASE_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/users-srv:$CI_COMMIT_REF_NAME"
# Docker config for project "orders-srv"
- DOCKER_FILE: "orders-srv/Dockerfile"
DOCKER_SNAPSHOT_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/orders-srv/snapshot:$CI_COMMIT_REF_SLUG"
DOCKER_RELEASE_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/orders-srv:$CI_COMMIT_REF_NAME"
# your pipeline stages
stages:
- build
- test
- package-build
- package-test
- deploy
- acceptance
- publish
- production
我有一个 Git 存储库,其中有几个独立的应用程序,用多种语言开发 (a.k.a monorepo)。
在此存储库中,我可以使用多个 to be continuous 模板并行构建我的所有项目吗?
当然可以。
一些构建模板也支持parallel matrix jobs,允许您使用同一个模板处理多个项目。
例子
假设一个 GitLab 项目由以下内容组成:
app/
:前端应用程序,开发于 Angularusers-srv/
:第一个后端服务,在 Node 中开发,打包为 Docker 图像orders-srv/
:第二个后端服务,在 Node 中开发,打包为 Docker 图像tools/
:一些工具,在 Python 中开发
您的 .gitlab-ci.yml
文件应如下所示:
# included templates
include:
# Angular template
- project: "to-be-continuous/angular"
ref: "1.2.0"
file: "templates/gitlab-ci-angular.yml"
# Node.js template
- project: "to-be-continuous/node"
ref: "1.2.0"
file: "templates/gitlab-ci-node.yml"
# Python template
- project: "to-be-continuous/python"
ref: "1.2.0"
file: "templates/gitlab-ci-python.yml"
# Docker template
- project: "to-be-continuous/docker"
ref: "1.2.0"
file: "templates/gitlab-ci-docker.yml"
# variables
variables:
# path of the Angular project
NG_WORKSPACE_DIR: "app"
# path of the Python project
PYTHON_PROJECT_DIR: "tools"
# parallel matrix jobs for Node template
.node-base:
parallel:
matrix:
# path of the "users-srv" Node project
- NODE_PROJECT_DIR: "users-srv"
# path of the "orders-srv" Node project
- NODE_PROJECT_DIR: "orders-srv"
# parallel matrix jobs for Docker template
.docker-base:
parallel:
matrix:
# Docker config for project "users-srv"
- DOCKER_FILE: "users-srv/Dockerfile"
DOCKER_SNAPSHOT_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/users-srv/snapshot:$CI_COMMIT_REF_SLUG"
DOCKER_RELEASE_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/users-srv:$CI_COMMIT_REF_NAME"
# Docker config for project "orders-srv"
- DOCKER_FILE: "orders-srv/Dockerfile"
DOCKER_SNAPSHOT_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/orders-srv/snapshot:$CI_COMMIT_REF_SLUG"
DOCKER_RELEASE_IMAGE: "$CI_REGISTRY/$CI_PROJECT_PATH/orders-srv:$CI_COMMIT_REF_NAME"
# your pipeline stages
stages:
- build
- test
- package-build
- package-test
- deploy
- acceptance
- publish
- production