# CI Build Template
.build:
    variables:
        CAPO_BUILD_ARG: "docker"
    script:
        - echo "Building branch or tag -- ${IMAGE_TAG}"
        - NAME="${REGISTRY_URL}/${PROJECT_NAME}/${SERVICE_NAME}"
        - docker build -t ${NAME}:${CI_COMMIT_SHORT_SHA} -f ${PATH_PREFIX}${SERVICE_NAME}/Dockerfile.dev . --build-arg capo_env=${CAPO_BUILD_ARG}
        - docker tag ${NAME}:${CI_COMMIT_SHORT_SHA} ${NAME}:${IMAGE_TAG}
        - echo "TAG=${IMAGE_TAG}" >> build.env
    artifacts:
        reports:
            dotenv: build.env
    rules:
        - if: $CI_COMMIT_BRANCH == $CI_DEFAULT_BRANCH
          variables:
            IMAGE_TAG: $CI_COMMIT_BRANCH
        - if: '$CI_PIPELINE_SOURCE == "merge_request_event"'
          variables:
            IMAGE_TAG: $CI_MERGE_REQUEST_SOURCE_BRANCH_NAME
        - if: '$CI_COMMIT_TAG =~ /^end-of-sprint-[0-9]+/'
          variables:
            IMAGE_TAG: $CI_COMMIT_TAG
            # override DEPLOY_ENV
            DEPLOY_ENV: "test"
        # - if: '$CI_COMMIT_TAG =~ /^test_[0-9]+\.[0-9]+.[0-9]+$/'
        #   variables:
        #     IMAGE_TAG: $CI_COMMIT_TAG
        #     # override DEPLOY_ENV
        #     DEPLOY_ENV: "test"