

services:
  # MySQL 数据库
  mysql:
    image: mysql:8.0
    container_name: ai-cs-mysql
    environment:
      MYSQL_ROOT_PASSWORD: ${MYSQL_ROOT_PASSWORD}
      MYSQL_DATABASE: ${DB_NAME}
      MYSQL_USER: ${DB_USER}
      MYSQL_PASSWORD: ${DB_PASSWORD}
    ports:
      - "${MYSQL_PORT}:3306"
    volumes:
      - mysql_data:/var/lib/mysql
    command: --character-set-server=utf8mb4 --collation-server=utf8mb4_unicode_ci
    healthcheck:
      test: ["CMD", "mysqladmin", "ping", "-h", "localhost", "-u", "root", "-p${MYSQL_ROOT_PASSWORD}"]
      interval: 10s
      timeout: 5s
      retries: 5
      start_period: 30s
    networks:
      - ai-cs-network
    restart: unless-stopped

  # 后端服务（本地构建）
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    env_file:
      - ./.env
    container_name: ai-cs-backend
    environment:
      DB_HOST: ${DB_HOST}
      DB_PORT: ${DB_PORT}
      DB_USER: ${DB_USER}
      DB_PASSWORD: ${DB_PASSWORD}
      DB_NAME: ${DB_NAME}
      ADMIN_USERNAME: ${ADMIN_USERNAME}
      ADMIN_PASSWORD: ${ADMIN_PASSWORD}
      SERVER_HOST: ${SERVER_HOST}
      SERVER_PORT: ${SERVER_PORT}
      GIN_MODE: ${GIN_MODE}
      ENCRYPTION_KEY: ${ENCRYPTION_KEY}
      SERPER_MCP_URL: ${SERPER_MCP_URL}
      SERPER_API_KEY: ${SERPER_API_KEY}
      MILVUS_HOST: ${MILVUS_HOST}
      MILVUS_PORT: ${MILVUS_PORT}
      MILVUS_USERNAME: ${MILVUS_USERNAME}
      MILVUS_PASSWORD: ${MILVUS_PASSWORD}
      MILVUS_DISABLED: ${MILVUS_DISABLED}
      VECTOR_STORE_DISABLED: ${VECTOR_STORE_DISABLED}
      MILVUS_REQUIRED: ${MILVUS_REQUIRED}
    ports:
      - "${BACKEND_PORT}:${SERVER_PORT}"
    volumes:
      - ./backend/uploads:/app/uploads
      - ./.env:/app/.env:ro
    depends_on:
      mysql:
        condition: service_healthy
    networks:
      - ai-cs-network
    restart: unless-stopped

  # 前端服务（本地构建）
  frontend:
    build:
      context: ./frontend
      dockerfile: Dockerfile
      args:
        NEXT_PUBLIC_API_BASE_URL: ${NEXT_PUBLIC_API_BASE_URL}
        NEXT_PUBLIC_BACKEND_HOST: ${NEXT_PUBLIC_BACKEND_HOST}
        NEXT_PUBLIC_BACKEND_PORT: ${NEXT_PUBLIC_BACKEND_PORT}
        NEXT_PUBLIC_MATOMO_CONTAINER_URL: ${NEXT_PUBLIC_MATOMO_CONTAINER_URL}
    container_name: ai-cs-frontend
    ports:
      - "${FRONTEND_PORT}:3000"
    depends_on:
      - backend
    networks:
      - ai-cs-network
    restart: unless-stopped

volumes:
  mysql_data:
    driver: local

networks:
  ai-cs-network:
    driver: bridge