FROM python:3.11-slim

# 设置工作目录
WORKDIR /app

# 安装系统依赖与 Node.js (prisma需要)
RUN apt-get update && apt-get install -y \
    curl \
    nodejs \
    npm && \
    rm -rf /var/lib/apt/lists/*

# 安装LiteLLM和prisma (使用国内源)
# 注意：Prisma Python 客户端 0.12.0 需要 Prisma CLI 5.8.0
# 需要同时安装 Prisma CLI 和 Python 客户端
RUN pip install --no-cache-dir -i https://pypi.tuna.tsinghua.edu.cn/simple \
    litellm[proxy]==1.17.0 \
    redis==5.0.1 \
    prometheus-client==0.19.0 \
    prisma==0.12.0 && \
    (rm -f /usr/local/bin/prisma || true) && \
    npm install -g prisma@5.8.0

# 复制配置文件
COPY config/ ./config/

# 创建logs目录
RUN mkdir -p logs

# 设置环境变量
ENV LITELLM_MASTER_KEY=sk-taiji-master-key
ENV LITELLM_CONFIG_PATH=/app/config/litellm.yaml

# 暴露端口
EXPOSE 4000

# 健康检查（使用 API key，增加超时时间因为health端点需要检查所有模型）
HEALTHCHECK --interval=60s --timeout=30s --start-period=30s --retries=3 \
  CMD curl -f -H "Authorization: Bearer sk-taiji-master-key" --max-time 25 http://localhost:4000/health || exit 1

# 启动LiteLLM代理
CMD ["litellm", "--config", "/app/config/litellm_simple.yaml", "--port", "4000", "--host", "0.0.0.0"]

