name: cms

services:
  db:
    image: mysql:8.0
    container_name: cms-db
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    volumes:
      - ./mysql_data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql
    command:
      - --default-authentication-plugin=mysql_native_password
      - --max_connections=100000
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "${DB_USER}", "-p${DB_PASSWORD}"]
      timeout: 20s
      retries: 10
      interval: 10s
    ports:
      - "3307:3306"   # <-- ось тут пробросимо порт (наприклад, 3307 на хості)
    networks:
      - cms-network


  phpmyadmin:
    image: phpmyadmin/phpmyadmin
    container_name: cms-phpmyadmin
    restart: unless-stopped
    environment:
      PMA_HOST: db
      PMA_PORT: 3306
      UPLOAD_LIMIT: 64M
      MEMORY_LIMIT: 512M
      MAX_EXECUTION_TIME: 300
    ports:
      - "${PHPMYADMIN_PORT}:80"
    depends_on:
      db:
        condition: service_healthy
    networks:
      - cms-network

  backend:
    build: .
    container_name: cms-backend
    restart: unless-stopped
    env_file:
      - .env
    environment:
      DB_HOST: db
      DB_PORT: 3306
    volumes:
      - ./src/utils/upload:/app/src/utils/upload
    ports:
      - "${FASTAPI_PORT}:8000"
    depends_on:
      db:
        condition: service_healthy
    networks:
      - cms-network

networks:
  cms-network:
    driver: bridge