FROM python:3.12-slim-bookworm

LABEL org.opencontainers.image.title="S57AI Customer Company Server"
LABEL org.opencontainers.image.description="OpenAI-compatible gateway for the S57AI Copilot"

ENV PYTHONDONTWRITEBYTECODE=1 \
    PYTHONUNBUFFERED=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1 \
    PIP_NO_CACHE_DIR=1

WORKDIR /app

RUN groupadd --system --gid 10001 s57ai \
    && useradd --system --uid 10001 --gid s57ai --home-dir /app --shell /usr/sbin/nologin s57ai

COPY requirements.txt /app/requirements.txt
RUN python -m pip install --upgrade pip \
    && python -m pip install --requirement /app/requirements.txt

COPY --chown=s57ai:s57ai server.py /app/server.py

USER 10001:10001

EXPOSE 5100

HEALTHCHECK --interval=30s --timeout=5s --start-period=10s --retries=3 \
    CMD ["python", "-c", "import urllib.request; urllib.request.urlopen('http://127.0.0.1:5100/health', timeout=3).read()"]

CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "5100"]
