pytest-dev-pytest
SUCCESS
46m 46s
History Source
SummaryIterations3Transcript59Dockerfile
Dockerfile54 lines · 1430 chars
# syntax=docker/dockerfile:1

# Multi-stage build: build from source, then ship a minimal runtime image
FROM python:3.12-slim as builder

ENV PYTHONUNBUFFERED=1

# Build dependencies
RUN apt-get update \
    && apt-get install -y --no-install-recommends \
        build-essential \
        libffi-dev \
        libssl-dev \
        ca-certificates \
        git \
    && rm -rf /var/lib/apt/lists/*

# Allow overriding a pretend version for setuptools_scm (needed when not in a git repo)
ARG PRETEND_VERSION=0.0.0
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYTEST=${PRETEND_VERSION}
ENV SETUPTOOLS_SCM_PRETEND_VERSION_FOR_PYPI=${PRETEND_VERSION}

WORKDIR /workspace

# Copy the entire source tree
COPY . .

# Ensure build tools are available
RUN python -m pip install --upgrade pip setuptools wheel && \
    python -m pip install --upgrade build

# Create a simple health check script to verify the image at runtime without relying on shell quoting
RUN printf 'print("ok")' > /health.py

# Build a wheel from the source
RUN python -m build --wheel .

# Final runtime image
FROM python:3.12-slim

ENV PYTHONUNBUFFERED=1

# Copy built wheel into the runtime image
COPY --from=builder /workspace/dist /dist
COPY --from=builder /health.py /health.py

# Install the built wheel (no cache)
RUN python -m pip install --no-cache-dir /dist/*.whl

WORKDIR /workspace

# Smoke test: verify Python runs and prints OK
CMD ["python", "/health.py"]