version: '3'
name: zeppelin-prod
services:
  nginx:
    build:
      context: .
      dockerfile: docker/production/nginx/Dockerfile
      args:
        API_PORT: ${API_PORT:?Missing API_PORT}
        DOCKER_PROD_DOMAIN: ${DOCKER_PROD_DOMAIN:?Missing DOCKER_PROD_DOMAIN}
    ports:
      - "${DOCKER_PROD_WEB_PORT:?Missing DOCKER_PROD_WEB_PORT}:443"
    volumes:
      - ./:/zeppelin

  mysql:
    image: mysql:8.0
    environment:
      MYSQL_ROOT_PASSWORD: ${DOCKER_PROD_MYSQL_ROOT_PASSWORD?:Missing DOCKER_PROD_MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: zeppelin
      MYSQL_USER: zeppelin
      MYSQL_PASSWORD: ${DOCKER_PROD_MYSQL_PASSWORD?:Missing DOCKER_PROD_MYSQL_PASSWORD}
    ports:
      - ${DOCKER_PROD_MYSQL_PORT:?Missing DOCKER_PROD_MYSQL_PORT}:3306
    volumes:
      - ./docker/production/data/mysql:/var/lib/mysql
    command: --authentication-policy=mysql_native_password
    healthcheck:
      test: "/usr/bin/mysql --user=root --password=\"${DOCKER_PROD_MYSQL_ROOT_PASSWORD}\" --execute \"SHOW DATABASES;\""
      interval: 5s
      timeout: 300s
      retries: 60

  migrate:
    depends_on:
      mysql:
        condition: service_healthy
    build:
      context: .
      dockerfile: docker/production/backend/Dockerfile
    command: ["npm", "run", "migrate-prod"]

  api:
    depends_on:
      migrate:
        condition: service_completed_successfully
    build:
      context: .
      dockerfile: docker/production/backend/Dockerfile
    restart: on-failure
    environment:
      DEBUG: ${DEBUG-}
    command: ["npm", "run", "start-api-prod"]

  bot:
    depends_on:
      migrate:
        condition: service_completed_successfully
    build:
      context: .
      dockerfile: docker/production/backend/Dockerfile
    restart: on-failure
    environment:
      DEBUG: ${DEBUG-}
    command: ["/bin/bash", "/zeppelin/docker/production/start-bot.sh"]