FROM python:3.10-slim

# 安装系统依赖
RUN apt-get update && apt-get install -y gcc libglib2.0-0 && rm -rf /var/lib/apt/lists/*

# 设置工作目录
WORKDIR /app

# 安装 Python 依赖
COPY requirements.txt .
RUN pip install --upgrade pip && pip install -r requirements.txt

# 安装本地 FlagEmbedding 源码
COPY FlagEmbedding /opt/FlagEmbedding
RUN pip install --no-deps --upgrade -e /opt/FlagEmbedding

# 拷贝应用代码和模型权重
COPY app /app/app
COPY model/bge-m3 /app/model/bge-m3

# 暴露端口
EXPOSE 8001

# # 启动 FastAPI 服务
# CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8001"]

# 新增：给 PT 显存分段配置，减少碎片 (可选但推荐)
ENV PYTORCH_CUDA_ALLOC_CONF=max_split_size_mb:32

# 启动：Gunicorn + 1 worker，每个 worker 一个独立进程
CMD ["gunicorn", "app.main:app", \
     "-k", "uvicorn.workers.UvicornWorker", \
     "-w", "1", \
     "-b", "0.0.0.0:8001"]