FROM python:3.12-slim

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    LLM_CONNECT_HOST=0.0.0.0 \
    LLM_CONNECT_PORT=8080 \
    LLM_CONNECT_PROVIDER=mock

WORKDIR /app

RUN groupadd -g 10001 llmconnect \
    && useradd -u 10001 -g 10001 -m -s /usr/sbin/nologin llmconnect

COPY pyproject.toml README.md ./
COPY llm_connect ./llm_connect
COPY fixtures ./fixtures
COPY scripts ./scripts

RUN pip install --no-cache-dir .

USER 10001:10001
EXPOSE 8080

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD python -c "import json, urllib.request; r=urllib.request.urlopen('http://127.0.0.1:8080/health', timeout=3); raise SystemExit(0 if json.load(r).get('status') == 'ok' else 1)"

CMD ["python", "-m", "llm_connect.server"]
