Skip to content
Commits on Source (16)
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'
- project: 'to-be-continuous/bash'
ref: '3.4'
file: '/templates/gitlab-ci-bash.yml'
- project: 'to-be-continuous/semantic-release'
ref: '3.8'
file: '/templates/gitlab-ci-semrel.yml'
# 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
stages:
- build
- publish
include:
- 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.com/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.com/api/v4/projects/smartdatalab%2Fpublic%2Fci-cd-components%2Fkicker/repository/files"
yajsv-image: "cicd-docker-dev.artifact.tecnalia.com/yajsv:latest"
- component: $CI_SERVER_FQDN/$TBC_NAMESPACE/bash/gitlab-ci-bash@master
inputs:
bash-shellcheck-job-tags: ["docker"]
shellcheck-files: "*.sh"
- 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"
BASH_SHELLCHECK_FILES: "*.sh"
GIT_STRATEGY: clone
semantic-release:
rules:
# on production branch(es): auto if SEMREL_AUTO_RELEASE_ENABLED
- if: '$TMPL_RELEASE_ENABLED == "true" && $CI_COMMIT_REF_NAME =~ $PROD_REF'
\ No newline at end of file
- if: '$TMPL_RELEASE_ENABLED == "true" && $CI_COMMIT_REF_NAME =~ $PROD_REF'
......@@ -19,4 +19,5 @@ plugins: [
]
branches:
- "main"
- "master"
tagFormat: "${version}"
\ No newline at end of file
## [1.0.2](https://git.code.tecnalia.com/smartdatalab/public/ci-cd-components/docker-compose/compare/1.0.1...1.0.2) (2024-09-13)
### Bug Fixes
* **workflow:** disable MR pipeline from prod & integ branches ([bedff8b](https://git.code.tecnalia.com/smartdatalab/public/ci-cd-components/docker-compose/commit/bedff8bbf87b5e77e66cbd34fdc08103f2cac8e5))
## [1.0.2](https://gitlab.com/to-be-continuous/docker-compose/compare/1.0.1...1.0.2) (2024-05-05)
### Bug Fixes
* **workflow:** disable MR pipeline from prod & integ branches ([bedff8b](https://gitlab.com/to-be-continuous/docker-compose/commit/bedff8bbf87b5e77e66cbd34fdc08103f2cac8e5))
## [1.0.1](https://gitlab.com/to-be-continuous/docker-compose/compare/1.0.0...1.0.1) (2024-04-27)
......
......@@ -4,17 +4,17 @@ 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-in-a-cicd-configuration)
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.
### Use as a CI/CD component
Add the following to your `gitlab-ci.yml`:
Add the following to your `.gitlab-ci.yml`:
```yaml
include:
# 1: include the component
- component: gitlab.com/to-be-continuous/docker-compose/gitlab-ci-docker-compose@1.0.1
- component: $CI_SERVER_FQDN/to-be-continuous/docker-compose/gitlab-ci-docker-compose@1.0.2
# 2: set/override component inputs
inputs:
# ⚠ this is only an example
......@@ -26,13 +26,13 @@ include:
### Use as a CI/CD template (legacy)
Add the following to your `gitlab-ci.yml`:
Add the following to your `.gitlab-ci.yml`:
```yaml
include:
# 1: include the template
- project: 'to-be-continuous/docker-compose'
ref: '1.0.1'
ref: '1.0.2'
file: '/templates/gitlab-ci-docker-compose.yml'
variables:
......@@ -251,7 +251,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-dynamic-environment-urls-after-a-job-finishes): when the url cannot be known before the
* a [**dynamic way**](https://docs.gitlab.com/ee/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):
......@@ -280,7 +280,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/pipelines/job_artifacts.html#artifactsreportsdotenv)):
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)):
* `$environment_type`: set to the type of environment (`review`, `integration`, `staging` or `production`),
* `$environment_name`: the application name (see below),
......@@ -321,6 +321,7 @@ The Docker Compose template uses some global configuration used throughout all j
| `down-opts`/ `DCMP_DOWN_OPTS` | [`compose down` options](https://docs.docker.com/reference/cli/docker/compose/down/#options) | `--volumes --remove-orphans --rmi all` |
| :lock: `DCMP_SSH_PRIVATE_KEY` | Default SSH key to use when connecting to Docker hosts over SSH (can be overridden per env) | _none_ |
| `ssh-known-hosts` / `DCMP_SSH_KNOWN_HOSTS` | SSH `known_hosts` (file or text variable) | _none_ |
| `compose-cleanup-review-job-tags` / `COMPOSE_CLEANUP_REVIEW_JOB_TAGS` | Tags to be used for selecting runners for the job | [] |
### Review environments configuration
......@@ -338,6 +339,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
......@@ -353,6 +355,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
......@@ -369,6 +372,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
......@@ -385,6 +389,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
......@@ -398,4 +403,4 @@ 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)_ |
| `compose-config-job-tags` / `COMPOSE_CONFIG_JOB_TAGS` | Tags to be used for selecting runners for the job | [] |
......@@ -54,6 +54,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": [
......@@ -68,6 +75,13 @@
"description": "[`compose config` options](https://docs.docker.com/reference/cli/docker/compose/config/#options)",
"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
}
]
},
......@@ -101,6 +115,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
}
]
},
......@@ -129,6 +150,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
}
]
},
......@@ -157,6 +185,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
}
]
},
......@@ -192,6 +227,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
}
]
}
......
......@@ -98,12 +98,39 @@ 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:
rules:
# prevent branch pipeline when an MR is open (prefer MR pipeline)
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS'
# prevent MR pipeline originating from production or integration branch(es)
- if: '$CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ $PROD_REF || $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME =~ $INTEG_REF'
when: never
# on non-prod, non-integration branches: prefer MR pipeline over branch pipeline
- if: '$CI_COMMIT_BRANCH && $CI_OPEN_MERGE_REQUESTS && $CI_COMMIT_REF_NAME !~ $PROD_REF && $CI_COMMIT_REF_NAME !~ $INTEG_REF'
when: never
- if: '$CI_COMMIT_MESSAGE =~ "/\[(ci skip|skip ci) on ([^],]*,)*tag(,[^],]*)*\]/" && $CI_COMMIT_TAG'
when: never
......@@ -746,7 +773,7 @@ stages:
image: $DCMP_IMAGE
services:
- name: "$TBC_TRACKING_IMAGE"
command: ["--service", "docker-compose", "1.0.1"]
command: ["--service", "docker-compose", "1.0.2"]
before_script:
- !reference [.compose-scripts]
- install_ca_certs "${CUSTOM_CA_CERTS:-$DEFAULT_CA_CERTS}"
......@@ -835,7 +862,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:
......@@ -860,6 +887,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:
......@@ -885,6 +913,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:
......@@ -905,6 +934,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:
......@@ -925,6 +955,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:
......@@ -951,3 +982,4 @@ compose-production:
- if: '$DCMP_PROD_DEPLOY_STRATEGY == "manual"'
when: manual
- if: '$DCMP_PROD_DEPLOY_STRATEGY == "auto"'
tags: $[[ inputs.compose-production-job-tags ]]