version: '3.8'

networks:
  ai-services-network:
    driver: bridge

volumes:
  postgres-data:
  redis-data:
  minio-data:
  gitea-data:
  algorithm-logs:

services:
  # API 网关
  api-gateway:
    build:
      context: ./api-gateway
      dockerfile: Dockerfile
    ports:
      - "80:80"
    networks:
      - ai-services-network
    depends_on:
      - backend
      - text-classification
      - image-recognition
      - speech-to-text
      - openai-proxy
    restart: always

  # 后端服务
  backend:
    build:
      context: ./backend
      dockerfile: Dockerfile
    ports:
      - "8001:8000"
    networks:
      - ai-services-network
    depends_on:
      - postgres
      - redis
      - minio
    environment:
      - DATABASE_URL=postgresql://admin:password@postgres:5432/algorithm_db
      - REDIS_URL=redis://redis:6379/0
      - MINIO_URL=http://minio:9000
      - MINIO_ACCESS_KEY=minioadmin
      - MINIO_SECRET_KEY=minioadmin
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - DEPLOYMENT_MODE=docker
    volumes:
      - algorithm-logs:/app/logs
    restart: always

  # 算法服务1：文本分类
  text-classification:
    build:
      context: ./services/text-classification
      dockerfile: Dockerfile
    ports:
      - "8010:8000"
    networks:
      - ai-services-network
    environment:
      - SERVICE_NAME=text-classification
      - LOG_LEVEL=info
    volumes:
      - algorithm-logs:/app/logs
    restart: always

  # 算法服务2：图像识别
  image-recognition:
    build:
      context: ./services/image-recognition
      dockerfile: Dockerfile
    ports:
      - "8011:8000"
    networks:
      - ai-services-network
    environment:
      - SERVICE_NAME=image-recognition
      - LOG_LEVEL=info
    volumes:
      - algorithm-logs:/app/logs
    restart: always

  # 算法服务3：语音转文字
  speech-to-text:
    build:
      context: ./services/speech-to-text
      dockerfile: Dockerfile
    ports:
      - "8012:8000"
    networks:
      - ai-services-network
    environment:
      - SERVICE_NAME=speech-to-text
      - LOG_LEVEL=info
    volumes:
      - algorithm-logs:/app/logs
    restart: always

  # OpenAI 代理服务
  openai-proxy:
    build:
      context: ./services/openai-proxy
      dockerfile: Dockerfile
    ports:
      - "8013:8000"
    networks:
      - ai-services-network
    environment:
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - LOG_LEVEL=info
    volumes:
      - algorithm-logs:/app/logs
    restart: always

  # 数据库
  postgres:
    image: postgres:15
    ports:
      - "5432:5432"
    networks:
      - ai-services-network
    environment:
      - POSTGRES_DB=algorithm_db
      - POSTGRES_USER=admin
      - POSTGRES_PASSWORD=password
    volumes:
      - postgres-data:/var/lib/postgresql/data
    restart: always

  # 缓存
  redis:
    image: redis:7
    ports:
      - "6379:6379"
    networks:
      - ai-services-network
    volumes:
      - redis-data:/data
    restart: always

  # 对象存储
  minio:
    image: minio/minio:latest
    ports:
      - "9000:9000"
      - "9001:9001"
    networks:
      - ai-services-network
    environment:
      - MINIO_ROOT_USER=minioadmin
      - MINIO_ROOT_PASSWORD=minioadmin
    command: server /data --console-address ":9001"
    volumes:
      - minio-data:/data
    restart: always

  # 代码管理
  gitea:
    image: gitea/gitea:latest
    ports:
      - "3000:3000"
      - "222:22"
    networks:
      - ai-services-network
    environment:
      - GITEA__database__TYPE=postgres
      - GITEA__database__HOST=postgres:5432
      - GITEA__database__NAME=gitea_db
      - GITEA__database__USER=admin
      - GITEA__database__PASSWD=password
    volumes:
      - gitea-data:/data
    depends_on:
      - postgres
    restart: always
