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

variables:
  SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
  DB_HOST: "postgres"
  RABBIT_HOST: "rabbitmq"

build:
  stage: build
  tags:
    - main
  script:
    - docker login -u mathwave -p $DOCKERHUB_PASSWORD
    - docker build -t mathwave/sprint-repo:sprint .
    - docker push mathwave/sprint-repo:sprint

.deploy:
  script:
    - docker login -u mathwave -p $DOCKERHUB_PASSWORD
    - docker pull mathwave/sprint-repo:sprint
    - docker-compose up -d

deploy-dev:
  extends:
    - .deploy
  stage: deploy-dev
  tags:
    - main
  rules:
    - if: '$CI_COMMIT_BRANCH == "master"'
      when: on_success
    - when: manual
  variables:
    PORT: 80
    SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
    DB_HOST: "postgres"
    RABBIT_HOST: "rabbitmq"
    FS_HOST: "http://storage"

deploy-prod:
  extends:
    - .deploy
  stage: deploy-prod
  tags:
    - prod
  only:
    - master
  when: manual
  variables:
    PORT: 443
    SOLUTIONS_ROOT_EXTERNAL: "/sprint-data/data/solutions"
    DB_HOST: "postgres"
    RABBIT_HOST: "rabbitmq"
