Skip to content
Commits on Source (17)
# variables in the GitLab CI/CD variables:
# GITLAB_TOKEN to support the semantic-release
# DOCKER_AUTH_CONFIG to support the usage of private docker images as job docker image
# TMPL_RELEASE_ENABLED to enable the semantic-release job
# TBC_NAMESPACE: smartdatalab/public/ci-cd-components
include:
- project: "to-be-continuous/tools/gitlab-ci"
ref: "master"
file: "/templates/extract.yml"
- project: "to-be-continuous/tools/gitlab-ci"
ref: "master"
file: "/templates/validation.yml"
- project: "to-be-continuous/kicker"
ref: "master"
file: "/templates/validation.yml"
- component: $CI_SERVER_FQDN/to-be-continuous/bash/gitlab-ci-bash@3.6
- component: $CI_SERVER_FQDN/$TBC_NAMESPACE/gitlab-ci/extract@master
inputs:
extract-script-job-tags: ["docker"]
- component: $CI_SERVER_FQDN/$TBC_NAMESPACE/gitlab-ci/validation@master
inputs:
check-links-job-tags: ["docker"]
tbc-check-job-tags: ["docker"]
tbc-check-image: cicd-docker-dev.artifact.tecnalia.dev/tbc-check:master
gitlab-ci-lint-job-tags: ["docker"]
- component: $CI_SERVER_FQDN/$TBC_NAMESPACE/kicker/validation@master
inputs:
kicker-validation-job-tags: ["docker"]
schema-base-url: "https://git.code.tecnalia.dev/api/v4/projects/smartdatalab%2Fpublic%2Fci-cd-components%2Fkicker/repository/files"
- component: $CI_SERVER_FQDN/$TBC_NAMESPACE/bash/gitlab-ci-bash@master
inputs:
bash-shellcheck-job-tags: ["docker"]
shellcheck-files: "*.sh"
- component: $CI_SERVER_FQDN/to-be-continuous/semantic-release/gitlab-ci-semrel@3.12
- component: $CI_SERVER_FQDN/$TBC_NAMESPACE/semantic-release/gitlab-ci-semrel@master
inputs:
semantic-release-job-tags: ["docker"]
variables:
GITLAB_CI_FILES: "templates/gitlab-ci-docker-compose.yml"
GIT_STRATEGY: clone
semantic-release:
rules:
......
......@@ -8,8 +8,8 @@ Closes #999
## Checklist
* General:
* [ ] use [rules](https://docs.gitlab.com/ee/ci/yaml/#rules) instead of [only/except](https://docs.gitlab.com/ee/ci/yaml/#onlyexcept-advanced)
* [ ] optimized [cache](https://docs.gitlab.com/ee/ci/caching/) configuration (wherever applicable)
* [ ] use [rules](https://docs.gitlab.com/ci/yaml/#rules) instead of [only/except](https://docs.gitlab.com/ci/yaml/#onlyexcept-advanced)
* [ ] optimized [cache](https://docs.gitlab.com/ci/caching/) configuration (wherever applicable)
* Publicly usable:
* [ ] untagged runners
* [ ] no proxy configuration but support `http_proxy`/`https_proxy`/`no_proxy`
......
......@@ -19,4 +19,5 @@ plugins: [
]
branches:
- "main"
- "master"
tagFormat: "${version}"
\ No newline at end of file
## [1.2.2](https://git.code.tecnalia.dev/smartdatalab/public/ci-cd-components/docker-compose/compare/1.2.1...1.2.2) (2025-05-07)
### Bug Fixes
* **envsubst:** leave lines with '# nosubst' unchanged when substituting (used to be simply dropped) ([392e60d](https://git.code.tecnalia.dev/smartdatalab/public/ci-cd-components/docker-compose/commit/392e60d69d47130f7f1a249ef8001c1fe6b234d0))
## [1.2.2](https://gitlab.com/to-be-continuous/docker-compose/compare/1.2.1...1.2.2) (2025-04-11)
### Bug Fixes
* **envsubst:** leave lines with '# nosubst' unchanged when substituting (used to be simply dropped) ([392e60d](https://gitlab.com/to-be-continuous/docker-compose/commit/392e60d69d47130f7f1a249ef8001c1fe6b234d0))
## [1.2.1](https://gitlab.com/to-be-continuous/docker-compose/compare/1.2.0...1.2.1) (2025-02-01)
......@@ -10,7 +24,19 @@
### Features
* disable tracking service by default ([0b801d2](https://gitlab.com/to-be-continuous/docker-compose/commit/0b801d2394924c6df9143c16137a0f6e74aa2117))
* disable tracking service by default ([0b801d2](https://git.code.tecnalia.dev/smartdatalab/public/ci-cd-components/docker-compose/commit/0b801d2394924c6df9143c16137a0f6e74aa2117))
# [1.1.0](https://git.code.tecnalia.dev/smartdatalab/public/ci-cd-components/docker-compose/compare/1.0.2...1.1.0) (2025-01-20)
### Bug Fixes
* boolean value in yaml ([b1df497](https://git.code.tecnalia.dev/smartdatalab/public/ci-cd-components/docker-compose/commit/b1df4975f45c102cd1bc566347d7c536b854ab6b))
### Features
* add Docker Swarm support ([6c9b90f](https://git.code.tecnalia.dev/smartdatalab/public/ci-cd-components/docker-compose/commit/6c9b90f3a36ef3db20dbe32530bce6ccd8094487))
# [1.1.0](https://gitlab.com/to-be-continuous/docker-compose/compare/1.0.2...1.1.0) (2024-12-30)
......
......@@ -61,7 +61,7 @@ To contribute:
1. Create an issue describing the bug or enhancement you want to propose (select the right issue template).
2. Make sure the issue has been reviewed and agreed.
3. Create a Merge Request, from your **own** fork (see [forking workflow](https://docs.gitlab.com/ee/user/project/repository/forking_workflow.html) documentation).
3. Create a Merge Request, from your **own** fork (see [forking workflow](https://docs.gitlab.com/user/project/repository/forking_workflow/) documentation).
Don't hesitate to mark your MR as `Draft` as long as you think it's not ready to be reviewed.
### Git Commit Conventions
......
......@@ -4,8 +4,8 @@ This project implements a GitLab CI/CD template to deploy your application with
## Usage
This template can be used both as a [CI/CD component](https://docs.gitlab.com/ee/ci/components/#use-a-component)
or using the legacy [`include:project`](https://docs.gitlab.com/ee/ci/yaml/index.html#includeproject) syntax.
This template can be used both as a [CI/CD component](https://docs.gitlab.com/ci/components/#use-a-component)
or using the legacy [`include:project`](https://docs.gitlab.com/ci/yaml/#includeproject) syntax.
### Use as a CI/CD component
......@@ -14,7 +14,7 @@ Add the following to your `.gitlab-ci.yml`:
```yaml
include:
# 1: include the component
- component: $CI_SERVER_FQDN/to-be-continuous/docker-compose/gitlab-ci-docker-compose@1.2.1
- component: $CI_SERVER_FQDN/to-be-continuous/docker-compose/gitlab-ci-docker-compose@1.2.2
# 2: set/override component inputs
inputs:
# ⚠ this is only an example
......@@ -32,7 +32,7 @@ Add the following to your `.gitlab-ci.yml`:
include:
# 1: include the template
- project: 'to-be-continuous/docker-compose'
ref: '1.2.1'
ref: '1.2.2'
file: '/templates/gitlab-ci-docker-compose.yml'
variables:
......@@ -67,7 +67,7 @@ _ongoing developments_ (a.k.a. _feature_ or _topic_ branches).
When enabled, it deploys the result from upstream build stages to a dedicated and temporary environment.
It is only active for non-production, non-integration branches.
It is a strict equivalent of GitLab's [Review Apps](https://docs.gitlab.com/ee/ci/review_apps/) feature.
It is a strict equivalent of GitLab's [Review Apps](https://docs.gitlab.com/ci/review_apps/) feature.
It also comes with a _cleanup_ job (accessible either from the _environments_ page, or from the pipeline view).
......@@ -244,8 +244,8 @@ Part of this complexity can be handled by the lookup strategies described above
* `${environment_type}`: the current environment type (`review`, `integration`, `staging` or `production`)
* `${environment_name}`: the application name to use for the current environment (ex: `myproject-review-fix-bug-12` or `myproject-staging`)
* `${hostname}`: the environment hostname, extracted from the current environment url (after late variable expansion - see below)
2. any [GitLab CI variable](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)
3. any [custom variable](https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-docker-host)
2. any [GitLab CI variable](https://docs.gitlab.com/ci/variables/predefined_variables/)
3. any [custom variable](https://docs.gitlab.com/ci/variables/#add-a-cicd-variable-to-a-docker-host)
(ex: `${SECRET_TOKEN}` that you have set in your project CI/CD variables)
Be aware that environment variables may be freely used and substituted in [dotenv files](https://docs.docker.com/compose/environment-variables/env-file/)
......@@ -256,7 +256,7 @@ using the appropriate [interpolation syntax](https://docs.docker.com/compose/env
The Docker Compose template supports two ways of providing your environments url:
* a **static way**: when the environments url can be determined in advance, probably because you're exposing your routes through a DNS you manage,
* a [**dynamic way**](https://docs.gitlab.com/ee/ci/environments/#set-a-dynamic-environment-url): when the url cannot be known before the
* a [**dynamic way**](https://docs.gitlab.com/ci/environments/#set-a-dynamic-environment-url): when the url cannot be known before the
deployment job is executed.
The **static way** can be implemented simply by setting the appropriate configuration variable(s) depending on the environment (see environments configuration chapters):
......@@ -285,7 +285,7 @@ the dynamically generated url. When detected by the template, it will use it as
### Deployment output variables
Each deployment job produces _output variables_ that are propagated to downstream jobs (using [dotenv artifacts](https://docs.gitlab.com/ee/ci/yaml/artifacts_reports.html#artifactsreportsdotenv)):
Each deployment job produces _output variables_ that are propagated to downstream jobs (using [dotenv artifacts](https://docs.gitlab.com/ci/yaml/artifacts_reports/#artifactsreportsdotenv)):
* `$environment_type`: set to the type of environment (`review`, `integration`, `staging` or `production`),
* `$environment_name`: the application name (see below),
......@@ -301,12 +301,12 @@ You may also add and propagate your own custom variables, by pushing them to the
Here are some advices about your **secrets** (variables marked with a :lock:):
1. Manage them as [project or group CI/CD variables](https://docs.gitlab.com/ee/ci/variables/#add-a-cicd-variable-to-a-docker-host):
* [**masked**](https://docs.gitlab.com/ee/ci/variables/#mask-a-cicd-variable) to prevent them from being inadvertently
1. Manage them as [project or group CI/CD variables](https://docs.gitlab.com/ci/variables/#add-a-cicd-variable-to-a-docker-host):
* [**masked**](https://docs.gitlab.com/ci/variables/#mask-a-cicd-variable) to prevent them from being inadvertently
displayed in your job logs,
* [**protected**](https://docs.gitlab.com/ee/ci/variables/#protected-cicd-variables) if you want to secure some secrets
* [**protected**](https://docs.gitlab.com/ci/variables/#protected-cicd-variables) if you want to secure some secrets
you don't want everyone in the project to have access to (for instance production secrets).
2. In case a secret contains [characters that prevent it from being masked](https://docs.gitlab.com/ee/ci/variables/#mask-a-cicd-variable),
2. In case a secret contains [characters that prevent it from being masked](https://docs.gitlab.com/ci/variables/#mask-a-cicd-variable),
simply define its value as the [Base64](https://en.wikipedia.org/wiki/Base64) encoded value prefixed with `@b64@`:
it will then be possible to mask it and the template will automatically decode it prior to using it.
3. Don't forget to escape special characters (ex: `$` -> `$$`).
......@@ -317,9 +317,9 @@ The Docker Compose template uses some global configuration used throughout all j
| Input / Variable | Description | Default value |
| ------------------------ |-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| ----------------- |
| `image` / `DCMP_IMAGE` | The Docker image used to run Docker Compose CLI commands | `registry.hub.docker.com/library/docker:latest` |
| `image` / `DCMP_IMAGE` | The Docker image used to run Docker Compose CLI commands | `registry.hub.docker.com/library/docker:latest` <br/>[![Trivy Badge](https://to-be-continuous.gitlab.io/doc/secu/trivy-badge-DCMP_IMAGE.svg)](https://to-be-continuous.gitlab.io/doc/secu/trivy-DCMP_IMAGE) |
| `cmd` / `DCMP_CMD` | The docker compose or stack command (`docker compose`, `docker-compose` or `docker stack`) | _none_ (auto) |
| `base-app-name` / `DCMP_BASE_APP_NAME`| Base application name | `$CI_PROJECT_NAME` ([see GitLab doc](https://docs.gitlab.com/ee/ci/variables/predefined_variables.html)) |
| `base-app-name` / `DCMP_BASE_APP_NAME`| Base application name | `$CI_PROJECT_NAME` ([see GitLab doc](https://docs.gitlab.com/ci/variables/predefined_variables/)) |
| `environment-url` / `DCMP_ENVIRONMENT_URL`| Default environments url _(only define for static environment URLs declaration)_<br/>_supports late variable expansion (ex: `https://%{environment_name}.docker-compose.acme.com`)_ | _none_ |
| `scripts-dir` / `DCMP_SCRIPTS_DIR`| Directory where Compose files, dotenv files and hook scripts are located | `.` _(root project dir)_ |
| `up-opts` / `DCMP_UP_OPTS` | [`compose up` options](https://docs.docker.com/reference/cli/docker/compose/up/#options) (only when using Docker Compose) | `--no-build --remove-orphans --wait --wait-timeout 180` |
......@@ -344,6 +344,7 @@ Here are variables supported to configure review environments:
| `review-app-name` / `DCMP_REVIEW_APP_NAME` | Application name for `review` env | `"${DCMP_BASE_APP_NAME}-${CI_ENVIRONMENT_SLUG}"` (ex: `myproject-review-fix-bug-12`) |
| `review-environment-url` / `DCMP_REVIEW_ENVIRONMENT_URL`| The review environments url _(only define for static environment URLs declaration and if different from default)_ | `$DCMP_ENVIRONMENT_URL` |
| `review-autostop-duration` / `DCMP_REVIEW_AUTOSTOP_DURATION`| The amount of time before GitLab will automatically stop `review` environments | `4 hours` |
| `compose-review-job-tags` / `COMPOSE_REVIEW_JOB_TAGS` | Tags to be used for selecting runners for the job | [] |
### Integration environment configuration
......@@ -359,6 +360,7 @@ Here are variables supported to configure the integration environment:
| :lock: `DCMP_INTEG_SSH_PRIVATE_KEY` | `integration` env specific SSH key to use when connecting to Docker Host over SSH | `$DCMP_SSH_PRIVATE_KEY` |
| `integ-app-name` / `DCMP_INTEG_APP_NAME` | Application name for `integration` env | `${DCMP_BASE_APP_NAME}-integration` |
| `integ-environment-url` / `DCMP_INTEG_ENVIRONMENT_URL`| The integration environment url _(only define for static environment URLs declaration and if different from default)_ | `$DCMP_ENVIRONMENT_URL` |
| `compose-integration-job-tags` / `COMPOSE_INTEGRATION_JOB_TAGS` | Tags to be used for selecting runners for the job | [] |
### Staging environment configuration
......@@ -375,6 +377,7 @@ Here are variables supported to configure the staging environment:
| :lock: `DCMP_STAGING_SSH_PRIVATE_KEY` | `staging` env specific SSH key to use when connecting to Docker Host over SSH | `$DCMP_SSH_PRIVATE_KEY` |
| `staging-app-name` / `DCMP_STAGING_APP_NAME` | Application name for `staging` env | `${DCMP_BASE_APP_NAME}-staging` |
| `staging-environment-url` / `DCMP_STAGING_ENVIRONMENT_URL`| The staging environment url _(only define for static environment URLs declaration and if different from default)_ | `$DCMP_ENVIRONMENT_URL` |
| `compose-staging-job-tags` / `COMPOSE_STAGING_JOB_TAGS` | Tags to be used for selecting runners for the job | [] |
### Production environment configuration
......@@ -391,6 +394,7 @@ Here are variables supported to configure the production environment:
| `prod-app-name` / `DCMP_PROD_APP_NAME` | Application name for `production` env | `$DCMP_BASE_APP_NAME` |
| `prod-environment-url` / `DCMP_PROD_ENVIRONMENT_URL`| The production environment url _(only define for static environment URLs declaration and if different from default)_ | `$DCMP_ENVIRONMENT_URL` |
| `prod-deploy-strategy` / `DCMP_PROD_DEPLOY_STRATEGY`| Defines the deployment to production strategy. One of `manual` (i.e. _one-click_) or `auto`. | `manual` |
| `compose-production-job-tags` / `COMPOSE_PRODUCTION_JOB_TAGS` | Tags to be used for selecting runners for the job | [] |
### Compose Config job
......@@ -404,5 +408,9 @@ Here are its parameters:
| ----------------------- | ----------------------------------------- | ----------------------------- |
| `config-disabled` / `DCMP_CONFIG_DISABLED` | Set to `true` to disable `compose config` | _none_ (enabled) |
| `config-opts` / `DCMP_CONFIG_OPTS` | [`compose config` options](https://docs.docker.com/reference/cli/docker/compose/config/#options) | `--quiet` _(to avoid displaying secrets inadvertently)_ |
<<<<<<< HEAD
| `compose-config-job-tags` / `COMPOSE_CONFIG_JOB_TAGS` | Tags to be used for selecting runners for the job | [] |
=======
| `stack-config-opts` / `DCMP_STACK_CONFIG_OPTS` | [`stack config` options](https://docs.docker.com/reference/cli/docker/stack/config/) | "" |
| `stack-config-silent` / `DCMP_STACK_CONFIG_SILENT` | Silences standard output of `stack config` command | `true` (standard output silenced) |
>>>>>>> upstream/main
......@@ -58,6 +58,13 @@
{
"name": "DCMP_SSH_KNOWN_HOSTS",
"description": "SSH `known_hosts` (file or text variable)"
},
{
"name": "COMPOSE_CLEANUP_REVIEW_JOB_TAGS",
"description": "Tags to be used for selecting runners for the job",
"type": "array",
"default": [],
"advanced": true
}
],
"features": [
......@@ -73,6 +80,13 @@
"default": "--quiet",
"advanced": true
},
{
"name": "COMPOSE_CONFIG_JOB_TAGS",
"description": "Tags to be used for selecting runners for the job",
"type": "array",
"default": [],
"advanced": true
},
{
"name": "DCMP_STACK_CONFIG_OPTS",
"description": "[`stack config` options](https://docs.docker.com/reference/cli/docker/stack/config/)",
......@@ -90,7 +104,7 @@
{
"id": "review",
"name": "Review",
"description": "Dynamic review environments for your topic branches (see GitLab [Review Apps](https://docs.gitlab.com/ee/ci/review_apps/))",
"description": "Dynamic review environments for your topic branches (see GitLab [Review Apps](https://docs.gitlab.com/ci/review_apps/))",
"variables": [
{
"name": "DCMP_REVIEW_DOCKER_HOST",
......@@ -117,6 +131,13 @@
"type": "url",
"description": "The `review` environments url _(only define for static environment URLs declaration and if different from default)_",
"advanced": true
},
{
"name": "COMPOSE_REVIEW_JOB_TAGS",
"description": "Tags to be used for selecting runners for the job",
"type": "array",
"default": [],
"advanced": true
}
]
},
......@@ -145,6 +166,13 @@
"type": "url",
"description": "The `integration` environment url _(only define for static environment URLs declaration and if different from default)_",
"advanced": true
},
{
"name": "COMPOSE_INTEGRATION_JOB_TAGS",
"description": "Tags to be used for selecting runners for the job",
"type": "array",
"default": [],
"advanced": true
}
]
},
......@@ -173,6 +201,13 @@
"type": "url",
"description": "The `staging` environment url _(only define for static environment URLs declaration and if different from default)_",
"advanced": true
},
{
"name": "COMPOSE_STAGING_JOB_TAGS",
"description": "Tags to be used for selecting runners for the job",
"type": "array",
"default": [],
"advanced": true
}
]
},
......@@ -208,6 +243,13 @@
"type": "enum",
"values": ["manual", "auto"],
"default": "manual"
},
{
"name": "COMPOSE_PRODUCTION_JOB_TAGS",
"description": "Tags to be used for selecting runners for the job",
"type": "array",
"default": [],
"advanced": true
}
]
}
......
......@@ -109,6 +109,30 @@ spec:
- manual
- auto
default: manual
compose-config-job-tags:
description: tags to filter applicable runners for compose-config job
type: array
default: []
compose-review-job-tags:
description: tags to filter applicable runners for compose-review job
type: array
default: []
compose-cleanup-review-job-tags:
description: tags to filter applicable runners for compose-cleanup-review job
type: array
default: []
compose-integration-job-tags:
description: tags to filter applicable runners for compose-integration job
type: array
default: []
compose-staging-job-tags:
description: tags to filter applicable runners for compose-staging job
type: array
default: []
compose-production-job-tags:
description: tags to filter applicable runners for compose-production job
type: array
default: []
---
# default workflow rules: Merge Request pipelines
workflow:
......@@ -470,7 +494,11 @@ stages:
}
return enc
}
!/# *nosubst/ {
/# *nosubst/ {
print $0
next
}
{
orig_line = $0
line = $0
count_repl_in_line = 0
......@@ -846,7 +874,7 @@ stages:
image: $DCMP_IMAGE
services:
- name: "$TBC_TRACKING_IMAGE"
command: ["--service", "docker-compose", "1.2.1"]
command: ["--service", "docker-compose", "1.2.2"]
before_script:
- !reference [.compose-scripts]
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
......@@ -944,7 +972,7 @@ compose-config:
when: never
# test policy rules must come last
- !reference [.test-policy, rules]
tags: $[[ inputs.compose-config-job-tags ]]
# deploy to review env (only on feature branches)
# disabled by default, enable this job by setting $DCMP_REVIEW_DOCKER_HOST.
compose-review:
......@@ -969,6 +997,7 @@ compose-review:
when: never
# only on non-production, non-integration branches
- if: '$CI_COMMIT_REF_NAME !~ $PROD_REF && $CI_COMMIT_REF_NAME !~ $INTEG_REF'
tags: $[[ inputs.compose-review-job-tags ]]
# cleanup review env (automatically triggered once branches are deleted)
compose-cleanup-review:
......@@ -994,6 +1023,7 @@ compose-cleanup-review:
- if: '$CI_COMMIT_REF_NAME !~ $PROD_REF && $CI_COMMIT_REF_NAME !~ $INTEG_REF'
when: manual
allow_failure: true
tags: $[[ inputs.compose-cleanup-review-job-tags ]]
# deploy to `integration` env (only on develop branch)
compose-integration:
......@@ -1014,6 +1044,7 @@ compose-integration:
when: never
# only on integration branch(es)
- if: '$CI_COMMIT_REF_NAME =~ $INTEG_REF'
tags: $[[ inputs.compose-integration-job-tags ]]
# deploy to `staging` env (only on master branch)
compose-staging:
......@@ -1034,6 +1065,7 @@ compose-staging:
when: never
# only on production branch(es)
- if: '$CI_COMMIT_REF_NAME =~ $PROD_REF'
tags: $[[ inputs.compose-staging-job-tags ]]
# Deploy to production if on branch master and variable DCMP_PROD_DOCKER_HOST defined and AUTODEPLOY_TO_PROD is set
compose-production:
......@@ -1060,3 +1092,4 @@ compose-production:
- if: '$DCMP_PROD_DEPLOY_STRATEGY == "manual"'
when: manual
- if: '$DCMP_PROD_DEPLOY_STRATEGY == "auto"'
tags: $[[ inputs.compose-production-job-tags ]]