stages:
  - build
  - deploy-dev
  - deploy-prod

variables:
  SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"

build:
  stage: build
  tags:
    - demo
  before_script:
    - docker login -u mathwave -p $DOCKERHUB_PASSWORD
  script:
    - docker build -t mathwave/sprint-repo:sprint .
    - docker build -t local_postgres dockerfiles/postgres
    - docker build -t local_rabbitmq dockerfiles/rabbitmq
    - docker push mathwave/sprint-repo:sprint

.deploy:
  before_script:
    - docker login -u mathwave -p $DOCKERHUB_PASSWORD
  script:
    - docker stack deploy -c ./docker-compose-deploy.yaml sprint

deploy-dev:
  extends:
    - .deploy
  stage: deploy-dev
  tags:
    - demo
  rules:
    - if: '$CI_COMMIT_BRANCH == "master"'
      when: on_success
    - when: manual
  variables:
    PORT: 80
    SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
    DB_HOST: "82.146.35.103"
    RABBIT_HOST: "82.146.35.103"
    FS_HOST: "82.146.35.103"
    DB_PASSWORD: "$DB_PASSWORD_DEMO"
    DEBUG: "true"
    TELEGRAM_TOKEN: "$TELEGRAM_TOKEN_DEMO"

deploy-prod:
  extends:
    - .deploy
  stage: deploy-prod
  tags:
    - main
  only:
    - master
  when: manual
  variables:
    PORT: 80
    SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
    DB_HOST: "77.246.159.65"
    RABBIT_HOST: "77.246.159.65"
    FS_HOST: "77.246.159.65"
    DB_PASSWORD: "$DB_PASSWORD_PROD"
    TELEGRAM_TOKEN: "$TELEGRAM_TOKEN_PROD"
