version: '3.8'

services:
  # MySQL 数据库
  mysql:
    image: mysql:8.0
    container_name: cursorpro-mysql
    restart: unless-stopped
    environment:
      MYSQL_ROOT_PASSWORD: ${DB_PASSWORD:-root123456}
      MYSQL_DATABASE: ${DB_NAME:-cursorpro}
      MYSQL_CHARSET: utf8mb4
      MYSQL_COLLATION: utf8mb4_unicode_ci
    ports:
      - "${DB_PORT:-3306}:3306"
    volumes:
      - mysql_data:/var/lib/mysql
      - ./init.sql:/docker-entrypoint-initdb.d/init.sql:ro
    command:
      - --character-set-server=utf8mb4
      - --collation-server=utf8mb4_unicode_ci
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost"]
      timeout: 5s
      retries: 10

  # CursorPro 后台服务
  backend:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: cursorpro-backend
    restart: unless-stopped
    ports:
      - "${PORT:-8000}:8000"
    environment:
      - DB_HOST=mysql
      - DB_PORT=3306
      - DB_USER=root
      - DB_PASSWORD=${DB_PASSWORD:-root123456}
      - DB_NAME=${DB_NAME:-cursorpro}
      - JWT_SECRET_KEY=${JWT_SECRET_KEY:-change-this-secret-key}
      - ADMIN_USERNAME=${ADMIN_USERNAME:-admin}
      - ADMIN_PASSWORD=${ADMIN_PASSWORD:-admin123}
    depends_on:
      mysql:
        condition: service_healthy
    volumes:
      - ./app:/app/app:ro
      - ./templates:/app/templates:ro

volumes:
  mysql_data:
