# AI Knowledge Link — Backend Dockerfile
FROM python:3.12-slim AS base

WORKDIR /app

# 系统依赖（PyMuPDF 需要）
RUN apt-get update && apt-get install -y --no-install-recommends \
    gcc g++ \
    && rm -rf /var/lib/apt/lists/*

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

# data/ 通过 volume 挂载，不进镜像
VOLUME /app/data

EXPOSE 8000

# 启动：先跑迁移，再起服务
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 2"]