# 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 -i https://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com -r requirements.txt

COPY . .

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

EXPOSE 8000

# 启动：先跑迁移，再起服务
# 注意：单 worker —— Session 存在进程内存中，多 worker 会导致登录态随机丢失
CMD ["sh", "-c", "alembic upgrade head && uvicorn app.main:app --host 0.0.0.0 --port 8000 --workers 1"]