From a968b58c91f53bc219b7d4894eeeea43ae7e2ce4 Mon Sep 17 00:00:00 2001 From: "Benguria Elguezabal, Gorka" <gorka.benguria@tecnalia.com> Date: Fri, 13 Sep 2024 12:55:33 +0200 Subject: [PATCH] adds job tags --- .gitlab-ci.yml | 37 ++++++++++++++++------- .releaserc.yml | 1 + README.md | 7 ++++- kicker.json | 42 ++++++++++++++++++++++++++ templates/gitlab-ci-docker-compose.yml | 31 ++++++++++++++++++- 5 files changed, 105 insertions(+), 13 deletions(-) diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 6366542..6f1b8e7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,20 +1,35 @@ +# 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.5 + - 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/to-be-continuous/semantic-release/gitlab-ci-semrel@3.11 + - 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: diff --git a/.releaserc.yml b/.releaserc.yml index 0f4d6d6..ae78ec7 100644 --- a/.releaserc.yml +++ b/.releaserc.yml @@ -19,4 +19,5 @@ plugins: [ ] branches: - "main" + - "master" tagFormat: "${version}" \ No newline at end of file diff --git a/README.md b/README.md index caba2de..b24946a 100644 --- a/README.md +++ b/README.md @@ -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 | [] | diff --git a/kicker.json b/kicker.json index 1de91f8..bc69b79 100644 --- a/kicker.json +++ b/kicker.json @@ -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 } ] } diff --git a/templates/gitlab-ci-docker-compose.yml b/templates/gitlab-ci-docker-compose.yml index 5faf4bc..01b028e 100644 --- a/templates/gitlab-ci-docker-compose.yml +++ b/templates/gitlab-ci-docker-compose.yml @@ -98,6 +98,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: @@ -838,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: @@ -863,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: @@ -888,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: @@ -908,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: @@ -928,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: @@ -954,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 ]] -- GitLab