FROM public.ecr.aws/docker/library/python:3.12-slim-trixie AS base
WORKDIR /usr/app

# hadolint ignore=DL3008
RUN apt-get update && apt-get install -y --no-install-recommends \
      git \
  && rm -rf /var/lib/apt/lists/*

COPY pyproject.toml LICENSE /usr/app/
COPY flexpose /usr/app/flexpose

ARG SETUPTOOLS_SCM_PRETEND_VERSION
ENV SETUPTOOLS_SCM_PRETEND_VERSION=$SETUPTOOLS_SCM_PRETEND_VERSION

# ===========================
# Builder WITHOUT spekpy
# ===========================
FROM base AS builder-nospek
# hadolint ignore=DL3013
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel && \
    python -m pip wheel --no-deps --wheel-dir /wheels .

# ===========================
# Builder WITH spekpy (extra)
# ===========================
FROM base AS builder-spek
# hadolint ignore=DL3013
RUN python -m pip install --no-cache-dir --upgrade pip setuptools wheel && \
    python -m pip wheel --no-deps --wheel-dir /wheels ".[spek]"

# ===========================
# Final runtime WITHOUT spekpy
# ===========================
FROM public.ecr.aws/docker/library/python:3.12-slim-trixie AS flexpose-nospek
WORKDIR /usr/app
COPY --from=builder-nospek /wheels /wheels
RUN python -m pip install --no-cache-dir /wheels/*.whl
ENTRYPOINT ["flexpose"]
CMD ["-h"]

# ===========================
# Final runtime WITH spekpy
# ===========================
FROM public.ecr.aws/docker/library/python:3.12-slim-trixie AS flexpose-spek
WORKDIR /usr/app
COPY --from=builder-spek /wheels /wheels
RUN python -m pip install --no-cache-dir /wheels/*.whl
ENTRYPOINT ["flexpose"]
CMD ["-h"]