version: "3.3"

services:
  db:
    image: mysql:latest
    container_name: "db"
    restart: always
    env_file: .env
    command: ["mysqld", "--authentication-policy=mysql_native_password"]
    healthcheck: 
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      interval: 10s
      timeout: 1s
      retries: 3
    ports:
      - 3306:3306
    volumes:
      - mysql-db:/var/lib/mysql

  app:
    build: 
      context: .
      dockerfile: Dockerfile-app
    container_name: "app"
    depends_on:
      db: 
        condition: service_healthy
    restart: always
    ports:
      - 8000:80
    env_file: .env
    environment:
      DB_HOST: db
      MODEL_HOST: model
    links:
      - model
      - db

  model:
    build: 
      context: .
      dockerfile: Dockerfile-model
    container_name: "model"
    restart: always
    ports:
      - 8501:8501
    environment:
      MODEL_NAME: "model"

volumes:
  mysql-db: