services:
  # ── MySQL 데이터베이스 ──
  db:
    image: mysql:8.0
    container_name: sg-db
    restart: unless-stopped
    env_file:
      - .env
    ports:
      - "3308:3306"
    volumes:
      - db_data:/var/lib/mysql
      - ./back/init-db:/docker-entrypoint-initdb.d

  # ── FastAPI 백엔드 ──
  api:
    build: ./back
    container_name: sg-api
    restart: unless-stopped
    ports:
      - "5330:5330"
    env_file:
      - ./back/.env
    command: uvicorn main:app --host 0.0.0.0 --port 5330 --reload
    volumes:
      - ./back:/app
      - ./front:/front
      - ./front/PPT:/front/PPT
      - ./front/curriculum_PDF:/front/curriculum_PDF
      - ./front/progress_PDF:/front/progress_PDF
    extra_hosts:
      - "host.docker.internal:host-gateway"
    depends_on:
      - db

  # ── Nginx 프론트엔드 ──
  web:
    build: ./front
    container_name: sg-web
    restart: unless-stopped
    ports:
      - "81:80"
    environment:
      - APP_PREFIX=${APP_PREFIX}
      - API_PORT=${API_PORT}
    volumes:
      - ./front:/usr/share/nginx/html
    depends_on:
      - api

volumes:
  db_data:
