include:
  - project: 'klass-devops/ci-templates'
    ref: main
    file:
      - 'build-push-template.yml'
      - 'portainer-deploy-template.yml'

stages:
  - build-push
  - deploy

variables:
  # Git submodule handling - set to 'none' because submodules use SSH URLs
  # and the SSH key is only available after before_script runs.
  # Submodules are initialized manually in the before_script of build-push-template.yml
  GIT_SUBMODULE_STRATEGY: none
  # Docker build variables
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""
  DOCKER_HOST: tcp://docker:2375
  PROJECT_PATH: dandelion/fr-in-the-cloud

build-push:
  extends: .build-push-template
  stage: build-push
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: on_success
    - when: manual
  variables:
    IMAGE_NAME: 'klnxrepo01.klass.dev/$PROJECT_PATH/api'
    DOCKERFILE: docker/api.Dockerfile
    BUILD_CONTEXT: .

deploy:
  extends: .portainer-deploy-template
  stage: deploy
  needs: []
  rules:
    - if: '$CI_COMMIT_BRANCH == "main"'
      when: on_success
    - when: manual
  variables:
    PORTAINER_BASE_URL: 'https://kluster.klass.dev/portainer/api'
    PORTAINER_ENDPOINT_ID: '1'
    STACK_NAME: 'fr-in-the-cloud'
    STACK_PATH: 'docker/stack.yml'
    DEPLOY_ENV_VARS: |
      REGISTRY=klnxrepo01.klass.dev
      PROJECT_PATH=$PROJECT_PATH
      TAG=latest
