# QYLAW 法律法规知识库 Dockerfile
# 基于 python:3.11-slim,纯 CPU(FAISS 不需 GPU)
FROM python:3.11-slim

LABEL maintainer="qy123"
LABEL description="QYLAW 法律法规知识库 — FAISS 语义检索 + RAG 问答"

# 设置工作目录
WORKDIR /app

# 安装系统依赖(faiss-cpu 需要 libgomp)
RUN apt-get update && apt-get install -y --no-install-recommends \
    libgomp1 \
    && rm -rf /var/lib/apt/lists/*

# 先复制 requirements 利用 Docker 缓存
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

# 复制应用代码
COPY app/ ./app/
COPY scripts/ ./scripts/

# 环境变量默认值(容器内通过 --network host 访问 localhost)
ENV LAW_PACK_DIR=/data/law-pack-2026-07-01-markdown \
    LAW_KB_DATA_DIR=/data/law-kb-data \
    EMBEDDING_URL=http://localhost:8003/v1 \
    LLM_URL=http://localhost:7000/v1 \
    APP_PORT=8090

# 暴露端口(--network host 模式下仅作记录)
EXPOSE 8090

# 健康检查
HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8090/health')" || exit 1

# 启动命令
CMD ["python", "-m", "uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8090"]
