# Linux container image (Debian slim). Build and run it with Podman:
#   podman build -t biogrounder .
#   podman run --rm -p 8000:8000 biogrounder
#
# Dependencies come from uv.lock, so the image has exactly the versions CI tested.

# ---- build: resolve nothing, install the locked environment into /app/.venv
FROM docker.io/library/python:3.15-slim AS build
COPY --from=ghcr.io/astral-sh/uv:0.13.13 /uv /bin/uv
ENV UV_COMPILE_BYTECODE=1 \
    UV_LINK_MODE=copy \
    UV_PYTHON_DOWNLOADS=0 \
    UV_PYTHON=/usr/local/bin/python3
WORKDIR /app
# Dependencies first (cached until uv.lock changes), then the project itself.
COPY pyproject.toml uv.lock README.md LICENSE ./
RUN uv sync --locked --no-dev --no-install-project
COPY src ./src
COPY knowledge ./knowledge
RUN uv sync --locked --no-dev --no-editable

# ---- run: the environment and the knowledge folder, no build tools
FROM docker.io/library/python:3.15-slim
ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PATH="/app/.venv/bin:$PATH"

# Run as an unprivileged user, never as root.
RUN useradd --create-home --uid 1000 --shell /usr/sbin/nologin app

WORKDIR /app
COPY --from=build /app/.venv /app/.venv
COPY --chown=app:app knowledge ./knowledge

USER app
# Examples, guidelines, the learning dictionary and saved runs live here; mount a volume to keep them.
ENV BIOGROUNDER_KNOWLEDGE_DIR=/app/knowledge
VOLUME /app/knowledge

# 8000: REST API (default command). 8765: MCP over streamable HTTP.
EXPOSE 8000 8765
CMD ["biogrounder", "api", "--host", "0.0.0.0", "--port", "8000"]
