# Description: Docker Compose file for running the Django application with MySQL and Nginx

services:
  mysql:
    image: mysql:latest
    platform: linux/amd64
    container_name: kb_mysql
    restart: always
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    volumes:
        - ./mysql_data:/var/lib/mysql
    healthcheck:
      test: [ "CMD", "mysqladmin", "ping", "-h", "localhost" ]
      interval: 10s
      timeout: 5s
      retries: 5
  web:
    container_name: kb_web
    build: .
    environment:
      DJANGO_SECRET_KEY: ${DJANGO_SECRET_KEY}
      PRODUCTION: ${PRODUCTION}
      DEBUG: ${DEBUG}
      PUBLIC_URL: ${PUBLIC_URL}
      EMAIL_HOST: ${EMAIL_HOST}
      EMAIL_PORT: ${EMAIL_PORT}
      EMAIL_USE_TLS: ${EMAIL_USE_TLS}
      EMAIL_HOST_USER: ${EMAIL_HOST_USER}
      EMAIL_HOST_PASSWORD: ${EMAIL_HOST_PASSWORD}
      MYSQL_HOST: mysql
      MYSQL_PORT: 3306
      MYSQL_DATABASE: ${MYSQL_DATABASE}
      MYSQL_USER: ${MYSQL_USER}
      MYSQL_PASSWORD: ${MYSQL_PASSWORD}
    command: bash -c 'cd /app && ./run.sh'
    depends_on:
      mysql:
        condition: service_healthy
    restart: "always"
  nginx:
    image: nginx:latest
    platform: linux/amd64
    container_name: kb_nginx
    ports:
      - ${NGINX_PUBLIC_PORT}:80
    volumes:
      - ./nginx/nginx.conf:/etc/nginx/conf.d/default.conf
      - ./staticfiles:/code/static
      - ./mediafiles:/code/media
    depends_on:
      - web
    restart: "always"