build-oci:
  stage: build
  image: registry.gitplac.si/cts/build-oci:1.0.3
  script: [ "/build.sh" ]
  variables:
      CTS_BUILD_DOCKERFILE: Dockerfile
  rules:
    - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH
      variables:
        CTS_BUILD_TAG: latest
    - if: $CI_COMMIT_TAG != null
      variables:
        CTS_BUILD_TAG: $CI_COMMIT_TAG
    - if: $CI_COMMIT_REF_NAME != $CI_DEFAULT_BRANCH
      variables:
        CTS_BUILD_TAG: $CI_COMMIT_SHORT_SHA

deploy:
  stage: deploy
  needs: ["build-oci"]
  resource_group: deploy-to-prod
  image:
    name: bitnami/kubectl:latest
    entrypoint: [""]
  environment:
    name: production
  variables:
    WAIT: "false"
    # IF FORCE true, NOW MUST BE false
    FORCE: "true"
    NOW: "false"
    TIMEOUT: "300s"
  script:
  - kubectl config use-context aljaxus/upn-qr:upn-qr-agent
  - kubectl delete --force=$FORCE --wait=$WAIT --now=$NOW --ignore-not-found=true --timeout=$TIMEOUT -f ./manifests/upn-qr.yaml
  - kubectl create -f ./manifests/upn-qr.yaml
  rules:
  - if: $CI_COMMIT_REF_NAME == $CI_DEFAULT_BRANCH && $CI_PROJECT_PATH == "aljaxus/upn-qr"
    when: on_success
  - when: manual
