FROM python:3.12-slim

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

WORKDIR /app

COPY requirements.txt /app/requirements.txt
RUN pip install --no-cache-dir -r /app/requirements.txt

COPY src/ /app/src/
RUN chmod -R a+rX /app/src

ENV PYTHONPATH=/app/src

ARG INSPECTOR_UID=1000
ARG INSPECTOR_GID=1000
RUN groupadd --gid ${INSPECTOR_GID} inspector \
 && useradd  --uid ${INSPECTOR_UID} --gid inspector --home-dir /app --shell /usr/sbin/nologin inspector \
 && mkdir -p /app/config /app/logs /app/data \
 && chown -R inspector:inspector /app/config /app/logs /app/data

COPY docker-entrypoint.sh /usr/local/bin/docker-entrypoint.sh
RUN chmod 755 /usr/local/bin/docker-entrypoint.sh

# Starts as root only to detect the Docker socket's group and fix mounted
# folder ownership, then drops to PUID:PGID (default 1000:1000).
# See docker-entrypoint.sh.
ENTRYPOINT ["/usr/local/bin/docker-entrypoint.sh"]
CMD ["python", "-m", "inspector.main"]
