# ── Build image for ulogger-cloud ──────────────────────────────────────────
# ulogger-cloud is pure Python, so a single build produces a py3-none-any
# wheel that works on every Python version, OS, and CPU architecture.
#
# The version is derived from the git tag via setuptools-scm.  Because the
# Docker build context contains only source files (no .git directory), the
# version must be supplied explicitly via --build-arg:
#
#   VERSION=$(git describe --tags --abbrev=0 | sed 's/^v//')
#   docker build --build-arg VERSION=$VERSION -t ulogger-cloud-build .
#   docker run --rm -v "$(pwd)/dist:/dist" ulogger-cloud-build
#
# If VERSION is omitted the build defaults to "0.0.0.dev0".

ARG VERSION=0.0.0.dev0
FROM python:3.12-slim

# Make the version available to the build step below
ARG VERSION
ENV SETUPTOOLS_SCM_PRETEND_VERSION=${VERSION}

LABEL org.opencontainers.image.title="ulogger-cloud build"
LABEL org.opencontainers.image.description="Builds universal py3-none-any wheel + sdist"

WORKDIR /src


# ── Python build toolchain ─────────────────────────────────────────────────
RUN pip install --no-cache-dir --upgrade pip build twine

# ── Copy source ────────────────────────────────────────────────────────────
COPY pyproject.toml README.md ./
COPY ulogger_cloud/ ulogger_cloud/

# ── Build ──────────────────────────────────────────────────────────────────
# Output lands in /src/dist/
RUN python -m build --outdir /src/dist

# ── Verify the distributions look correct ─────────────────────────────────
RUN twine check /src/dist/*

# ── Runtime: copy artefacts out to /dist (bind-mounted by caller) ──────────
CMD ["sh", "-c", \
     "cp -v /src/dist/* /dist/ && echo 'Build artefacts copied to /dist'"]
