Monorepo Pipeline Template
The docker-monorepo.yml pipeline template builds and deploys several
applications that live in one repository. Everything else (branches, versions,
environments, Argo CD) works as in docker.yml.
Monorepo or multirepo
| Multirepo (default) | Monorepo | |
|---|---|---|
| Repository | one application | several applications (e.g. api, web, worker) |
| Pipeline template | node.yml, docker.yml, ... | docker-monorepo.yml |
| Images | $CI_REGISTRY_IMAGE:<version> | $CI_REGISTRY_IMAGE/<app>:<version> |
| Tenant values | .image.tag | .apps.<app>.image.tag |
| Helm chart | node, app, craft, ... | apps |
| Argo CD | one Application | one Application for all the apps |
Use the monorepo template when the applications share code and are released
together (one release/x.y.z for all of them). If an application has its own
lifecycle and its own team, keep it in its own repository.
Usage
.gitlab-ci.yml:
include:
- project: 'welance/platform/pipelines/templates/pipeline/git-flow'
ref: release/1.2.0
file: 'docker-monorepo.yml'
variables:
PROJECT_ID: 'r001-11'
welance.yaml at the root of the repository lists the applications:
apps:
api:
target: api-runtime # Dockerfile target (optional)
web:
context: apps/web # default .
dockerfile: apps/web/Dockerfile # default <context>/Dockerfile
tools:
target: tools-runtime
deploy: false # built and pushed, not deployed
The manifest is the only place where the applications are declared: the
pipeline reads it, the .gitlab-ci.yml stays an include. Set WELANCE_MANIFEST
to use a different path.
What the pipeline does
- build (
ci-jobs/build/docker-build-apps.yml): onedocker buildx buildper application, pushed as$CI_REGISTRY_IMAGE/<app>:<version>, with a BuildKit layer cache in the registry ($CI_REGISTRY_IMAGE/cache:<app>), so multi-stage builds only rebuild the layers that changed. - deploy (
ci-jobs/deploy/gitops-apps-and-value-sync.yml): in the tenantvalues.yamlit writes.apps.<app>.image.tagfor every application withoutdeploy: falseand.image.commit.*once, writesenv.yamlfrom the environment file, commits and syncs the Argo CD Application. - release: as in the other templates.
Every application gets its own tag key, so each Deployment only ever runs its own image. Today all the applications of a pipeline share the same version.
Tenant
The tenant uses the apps chart: one
Application, one values.yaml with an entry per application under apps.