diff --git a/templates/docker-compose/template.yml b/templates/docker-compose/template.yml index 1303b0c779618b4b69e7e8f2008ece22c6ef9ae6..780f13ce4bbafe5eb29e720678b9a5437c9ca039 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