# cortex-graph-worker — L3 code graph (DuckDB + SQLite + sqlite-vec + better-code-review-graph)
# Internal only on :9001. cortex-api proxies /graph/* requests here.

FROM python:3.12-slim@sha256:57cd7c3a7a273101a6485ba99423ee568157882804b1124b4dd04266317710de

RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    git \
    build-essential \
    && rm -rf /var/lib/apt/lists/*

# uv for installing better-code-review-graph (per Phase A pattern)
RUN pip install --no-cache-dir uv==0.11.15

# Pre-install the better-code-review-graph tool so it's available offline
RUN uv tool install better-code-review-graph==3.8.0

# Worker calls use `uv tool run`; forbid a network re-resolution at runtime.
ENV UV_OFFLINE=1

# Worker runtime: FastAPI + DuckDB + sqlite-vec
RUN pip install --no-cache-dir \
    fastapi==0.115.0 \
    uvicorn[standard]==0.32.0 \
    duckdb==1.1.0 \
    sqlite-vec==0.1.6 \
    pydantic==2.9.2

WORKDIR /app
COPY worker.py /app/

ENV CORTEX_GRAPHS_DIR=/var/lib/cortex/graphs
ENV PROJECTS_DIR=/projects

EXPOSE 9001

HEALTHCHECK --interval=10s --timeout=3s --retries=3 \
    CMD curl -fsS http://localhost:9001/health || exit 1

CMD ["uvicorn", "worker:app", "--host", "0.0.0.0", "--port", "9001"]
