# Stage 1: Build — install all MCP libs
FROM python:3.12-slim AS builder

WORKDIR /build

COPY pyproject.toml README.md ./
COPY kernelmcp/ kernelmcp/

# Install kernelmcp + its real dependencies from pyproject. The [api] extra brings
# fastapi/uvicorn (the kernelmcp-api HTTP server) and [metrics] brings prometheus-client
# (the /metrics endpoint). Sister libs (memory/rag/sandbox/...) are optional extras —
# add them here (e.g. ".[all]") to bundle the full governed tool suite.
RUN pip install --no-cache-dir --prefix=/install ".[api,metrics]"

# Stage 2: Slim runtime
FROM python:3.12-slim

WORKDIR /app

COPY --from=builder /install /usr/local
COPY kernelmcp/ kernelmcp/

RUN useradd --create-home appuser
USER appuser

EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --retries=3 \
    CMD python -c "import urllib.request; urllib.request.urlopen('http://localhost:8080/health')"

ENTRYPOINT ["kernelmcp", "start", "--mode", "agent"]
