# syntax=docker/dockerfile:1.7
FROM python:3.13-slim AS build

ENV PIP_NO_CACHE_DIR=1 \
    PIP_DISABLE_PIP_VERSION_CHECK=1

WORKDIR /src
COPY pyproject.toml README.md ./
COPY src/ src/
RUN python -m pip wheel --wheel-dir /wheels .

FROM python:3.13-slim

RUN groupadd --system app \
    && useradd --system --gid app --home-dir /app app \
    && apt-get update \
    && apt-get install --yes --no-install-recommends tini \
    && rm -rf /var/lib/apt/lists/*

COPY --from=build /wheels /wheels
RUN python -m pip install --no-index --find-links=/wheels inventory \
    && rm -rf /wheels

RUN <<EOF
set -eu
mkdir -p /app/data
chown app:app /app/data
EOF

USER app
WORKDIR /app
EXPOSE 8000
HEALTHCHECK --interval=30s --timeout=3s CMD ["python", "-m", "inventory.health"]
ENTRYPOINT ["tini", "--"]
CMD ["python", "-m", "inventory.server", "--port", "8000"]
