FROM python:3.12-slim

ARG SOURCE_COMMIT
LABEL org.opencontainers.image.source="https://github.com/fourblocks2020/trex-core" \
      org.opencontainers.image.revision="${SOURCE_COMMIT}"

WORKDIR /opt/trex-core

RUN test "${#SOURCE_COMMIT}" -eq 40 \
    && case "${SOURCE_COMMIT}" in \
         *[!0-9a-f]*) false ;; \
         *) true ;; \
       esac \
    || { echo "SOURCE_COMMIT must be a 40-character lowercase commit" >&2; exit 1; }

COPY pyproject.toml ./
COPY trex_core/ ./trex_core/

RUN python -m pip install --no-cache-dir . \
    && useradd --create-home --uid 10001 trex

USER 10001:10001

ENTRYPOINT ["trex-core-daemon"]
