@@ -243,7 +243,7 @@ that you might use in your hook scripts, deployment manifests, and other deploym
#### Generated environment name
The `${environment_name}` variable is generated to designate each deployment environment with a unique and meaningful application name.
By construction, it is suitable for inclusion in DNS, URLs, Kubernetes labels...
By construction, it is suitable for inclusion in DNS, URLs, {{cookiecutter.template_name}} labels...
It is built from:
* the application _base name_ (defaults to `$CI_PROJECT_NAME` but can be overridden globally and/or per deployment environment - _see configuration variables_)
@@ -331,6 +331,43 @@ The **static way** can be implemented simply by setting the appropriate configur
To implement the **dynamic way**, your deployment script shall simply generate a `environment_url.txt` file in the working directory, containing only
the dynamically generated url. When detected by the template, it will use it as the newly deployed environment url.
### Multiple environments support
The {{cookiecutter.template_name}} template allows deploying multiple environments in parallel. Use cases of this include:
- monorepo, where a single Git repository might host several separate deployable components or apps,
- multi-instances deployment of the same application.
This feature can be enabled using the [parallel matrix jobs](https://docs.gitlab.com/ee/ci/yaml/#parallelmatrix)
pattern at the `.{{cookiecutter.template_prefix}}-base` job level (the template's base job).
Environments namespacing is ensured by the `{{cookiecutter.template_PREFIX}}_ENVIRONMENT_NAMESPACE` variable (must start with a slash `/`).
Here is the example of the `.gitlab-ci.yml` file for a project deploying both a frontend and a backend applications:
The above configuration will deploy 2 environments on each pipeline:
- on feature branches: `review/front/$CI_COMMIT_REF_NAME` and `review/back/$CI_COMMIT_REF_NAME`
- on the integration branch: `integration/front` and `integration/back`
- on the production branch: `staging/front` and `staging/back` (and finally `production/front` and `production/back`)
### Deployment output variables
Each deployment job produces _output variables_ that are propagated to downstream jobs (using [dotenv artifacts](https://docs.gitlab.com/ci/yaml/artifacts_reports/#artifactsreportsdotenv)):
@@ -343,6 +380,16 @@ Those variables may be freely used in downstream jobs (for instance to run accep
You may also add and propagate your own custom variables, by pushing them to the `{{ cookiecutter.project_slug }}.env` file in your [deployment scripts or hooks](#deployment-and-cleanup).
> [!important]
> If [multiple environments](#multiple-environments-support) are configured, the output variables are prefixed with a
> sluggified value of the `{{cookiecutter.template_PREFIX}}_ENVIRONMENT_NAMESPACE` variable (stripped of punctuation characters and converted to lowercase):
>
> * `<namespace_slug>_environment_type`: set to the type of environment (`review`, `integration`, `staging` or `production`),
> * `<namespace_slug>_environment_name`: the application name (see below),
> * `<namespace_slug>_environment_url`: set to the environment URL (whether determined statically or dynamically).
>
> The output dotenv file will be `{{cookiecutter.project_slug}}.env.<namespace_slug>` instead, and the dynamic variable `${environment_namespace}` can be used in your scripts and manifests to access the contextual value of `<namespace_slug>`.
## Configuration reference
### Secrets management
@@ -370,6 +417,7 @@ The {{cookiecutter.template_name}} template uses some global configuration used
| `environment-namespace` / `{{cookiecutter.template_PREFIX}}_ENVIRONMENT_NAMESPACE` | Extra [GitLab environments](https://docs.gitlab.com/ci/environments/) namespace _(only required when deploying [multiple environments](#multiple-environments-support))_<br/>:warning: must start with a slash `/` | _none_ |
| `scripts-dir` / `{{cookiecutter.template_PREFIX}}_SCRIPTS_DIR` | Directory where deploy & cleanup scripts are located | `.` _(root project dir)_ |
"description":"Extra [GitLab environments](https://docs.gitlab.com/ci/environments/) namespace _(only required when deploying multiple environments)_\n\n:warning: must start with a slash `/`",