File size: 2,880 Bytes
1ea875f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Docker Compose 配置 - 生产环境部署 (优化版: 2核2G服务器)
# 包含: FastAPI 应用 + Qdrant Server

version: '3.8'

services:
  # ============================================================
  # Qdrant 向量数据库 (限制内存 512MB)
  # ============================================================
  qdrant:
    image: qdrant/qdrant:latest
    container_name: github-rag-qdrant
    restart: unless-stopped
    ports:
      - "6333:6333"  # REST API
      - "6334:6334"  # gRPC
    volumes:
      - qdrant_data:/qdrant/storage
    environment:
      - QDRANT__SERVICE__GRPC_PORT=6334
      - QDRANT__STORAGE__ON_DISK_PAYLOAD=true  # Payload 存磁盘,省内存
    deploy:
      resources:
        limits:
          memory: 512M
        reservations:
          memory: 256M
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:6333/health"]
      interval: 30s
      timeout: 10s
      retries: 3

  # ============================================================
  # FastAPI 应用 (2 Workers, 限制内存 1GB)
  # ============================================================
  app:
    build:
      context: .
      dockerfile: Dockerfile
    container_name: github-rag-app
    restart: unless-stopped
    ports:
      - "8000:8000"
    environment:
      # Qdrant Server 模式
      - QDRANT_MODE=server
      - QDRANT_URL=http://qdrant:6333
      
      # Worker 数量 (2核服务器建议2个)
      - GUNICORN_WORKERS=2
      
      # 文件锁 (多 Worker)
      - LOCK_BACKEND=file
      - LOCK_DIR=/app/data/locks
      
      # LLM 配置 (从 .env 读取)
      - LLM_PROVIDER=${LLM_PROVIDER:-deepseek}
      - DEEPSEEK_API_KEY=${DEEPSEEK_API_KEY}
      - OPENAI_API_KEY=${OPENAI_API_KEY}
      - ANTHROPIC_API_KEY=${ANTHROPIC_API_KEY}
      - GEMINI_API_KEY=${GEMINI_API_KEY}
      - SILICON_API_KEY=${SILICON_API_KEY}
      - GITHUB_TOKEN=${GITHUB_TOKEN}
    volumes:
      - app_data:/app/data
      - app_logs:/app/logs
    deploy:
      resources:
        limits:
          memory: 1G
        reservations:
          memory: 512M
    depends_on:
      qdrant:
        condition: service_healthy
    healthcheck:
      test: ["CMD", "curl", "-f", "http://localhost:8000/health"]
      interval: 30s
      timeout: 10s
      retries: 3

volumes:
  qdrant_data:
    driver: local
  app_data:
    driver: local
  app_logs:
    driver: local

# ============================================================
# 使用说明
# ============================================================
# 1. 复制 .env.example 为 .env 并配置 API Keys
# 2. 启动服务: docker-compose up -d
# 3. 查看日志: docker-compose logs -f app
# 4. 停止服务: docker-compose down
# 
# 扩展到多 Worker:
# 修改 Dockerfile 中的 gunicorn workers 数量,或使用:
# docker-compose up -d --scale app=3
# 配合 Nginx/Traefik 做负载均衡