FROM python:3.12-slim AS base

WORKDIR /app

# System deps for pymupdf
RUN apt-get update && apt-get install -y --no-install-recommends \
    libmupdf-dev gcc && \
    rm -rf /var/lib/apt/lists/*

COPY pyproject.toml README.md ./
COPY src/ src/

# Install with web extras
RUN pip install --no-cache-dir ".[web]"

EXPOSE 8000

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8000/health')" || exit 1

# Non-loopback bind requires AGENTFORGE_API_TOKEN at runtime
# (or AGENTFORGE_API_TOKEN=disabled for explicit opt-out).
ENTRYPOINT ["agentforge"]
CMD ["serve", "--host", "0.0.0.0", "--no-open"]
