From 35502d41bbef550eaac43c87fe2c520223b7c257 Mon Sep 17 00:00:00 2001 From: Sebastian <sebastian.karius@informatik.uni-halle.de> Date: Mon, 23 Sep 2024 11:17:21 +0200 Subject: [PATCH] Add conditional inputs for Docker build configurations --- templates/docker-compose/template.yml | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/templates/docker-compose/template.yml b/templates/docker-compose/template.yml index 1303b0c..780f13c 100644 --- a/templates/docker-compose/template.yml +++ b/templates/docker-compose/template.yml @@ -2,6 +2,19 @@ spec: inputs: stage: default: build + build_main: + type: boolean + default: true + description: "Build a container with the 'latest' container tag from the default (main) branch." + build_branch: + type: boolean + default: true + description: "Build a container with the branch name (except for default branch) as container tag." + build_tag: + type: boolean + default: true + description: "Build a container with the git tag name as container tag." + --- docker-compose-build: # Use the official docker image. @@ -21,7 +34,7 @@ docker-compose-build: - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: - | - if [[ "$CI_COMMIT_BRANCH" == 'main' ]]; then + if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then export DOCKER_IMAGE_TAG=latest elif [[ "$CI_COMMIT_TAG" != '' ]]; then export DOCKER_IMAGE_TAG=$CI_COMMIT_TAG @@ -30,9 +43,12 @@ docker-compose-build: - docker compose push # Run this job in a branch where a docker-compose.yml exists rules: - - if: $CI_COMMIT_BRANCH + - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH && $[[ inputs.build_main ]] exists: - docker-compose.yml - - if: $CI_COMMIT_TAG + - if: $CI_COMMIT_BRANCH && $[[ inputs.build_branch ]] + exists: + - docker-compose.yml + - if: $CI_COMMIT_TAG && $[[ inputs.build_tag ]] exists: - docker-compose.yml \ No newline at end of file -- GitLab