image: tiangolo/docker-with-compose:2021-09-18

before_script:
  - docker login -u gitlab-ci-token -p $CI_JOB_TOKEN $CI_REGISTRY
#  - pip install docker-auto-labels

stages:
  - build
  - deploy
#  - test

#tests:
#  stage: test
#  script:
#    - sh ./scripts/test.sh
#  tags:
#    - build
#    - test

build-stag:
  stage: build
  script:
    - TAG=stag FRONTEND_ENV=staging sh ./scripts/build-push.sh
  only:
    - development
  tags:
    - build
    - test

build-tms:
  stage: build
  script:
    - TAG=tms FRONTEND_ENV=tms sh ./scripts/build-push.sh
  only:
    - tms
  tags:
    - build
    - test

build-prod:
  stage: build
  script:
    - TAG=prod FRONTEND_ENV=production sh ./scripts/build-push.sh
  only:
    - master
  tags:
    - build
    - test

deploy-stag:
  stage: deploy
  script:
    - >
      DOMAIN=stag.petra-prototyping.de
      TRAEFIK_TAG=stag.petra-prototyping.de
      STACK_NAME=stag-petra-prototyping-de
      TAG=stag
      sh ./scripts/deploy.sh
  environment:
    name: staging
    url: https://stag.petra-prototyping.de
  only:
    - development
  tags:
    - swarm
    - stag

deploy-tms:
  stage: deploy
  script:
    - >
      DOMAIN=tms.petra-prototyping.de
      TRAEFIK_TAG=tms.petra-prototyping.de
      STACK_NAME=tms-petra-prototyping-de
      TAG=tms
      sh ./scripts/deploy.sh
  environment:
    name: tms
    url: https://tms.petra-prototyping.de
  only:
    - tms
  tags:
    - swarm
    - stag

deploy-prod:
  stage: deploy
  script:
    - >
      DOMAIN=petra-prototyping.de
      TRAEFIK_TAG=petra-prototyping.de
      STACK_NAME=petra-prototyping-de
      TAG=prod
      sh ./scripts/deploy.sh
  environment:
    name: production
    url: https://petra-prototyping.de
  only:
    - master
  tags:
    - swarm
    - prod
