image: tiangolo/docker-with-compose

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

stages:
  - test
  - build
  - deploy

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:
    - master
  tags:
    - build
    - test
    
build-prod:
  stage: build
  script:
    - TAG=prod FRONTEND_ENV=production sh ./scripts/build-push.sh
  only:
    - production
  tags:
    - build
    - test

deploy-stag:
  stage: deploy
  script: 
    - >
      DOMAIN=stag.ai-anchor.com
      TRAEFIK_TAG=stag.ai-anchor.com
      STACK_NAME=stag-ai-anchor-com
      TAG=stag
      sh ./scripts/deploy.sh
  environment:
    name: staging
    url: https://stag.ai-anchor.com
  only:
    - master
  tags:
    - swarm
    - stag

deploy-prod:
  stage: deploy
  script:
    - >
      DOMAIN=ai-anchor.com
      TRAEFIK_TAG=ai-anchor.com
      STACK_NAME=ai-anchor-com
      TAG=prod
      sh ./scripts/deploy.sh
  environment:
    name: production
    url: https://ai-anchor.com
  only:
    - production
  tags:
    - swarm
    - prod