chaostoolkit-chaostoolkit
SUCCESS
31m 21s
History Source
SummaryIterations1Transcript23Dockerfile
Dockerfile56 lines · 1747 chars
FROM python:3.11 AS build-venv

ARG DEBIAN_FRONTEND=noninteractive

# Prepare a non-root user for the final image
RUN groupadd -g 1001 svc && useradd -m -u 1001 -g svc svc

# Install build-time dependencies
RUN apt-get update && \
    apt-get install -y --no-install-recommends curl ca-certificates build-essential gcc python3-dev python3-venv && \
    rm -rf /var/lib/apt/lists/*

WORKDIR /home/svc

# Copy project manifest and repository for building from source
COPY pyproject.toml pdm.lock README.md /home/svc/
COPY . /home/svc/

# Install PDM and prepare Python virtual environment for building from source
RUN curl -sSL https://raw.githubusercontent.com/pdm-project/pdm/main/install-pdm.py | python3.11 -

ENV PATH="/root/.local/bin:${PATH}"
ENV PDM_BUILD_SCM_VERSION=0.0.0

RUN pdm self update && \
    cd /home/svc && \
    pdm venv create python3.11 && \
    pdm use .venv && \
    pdm update --no-editable --no-self --dev --frozen-lockfile -G extensions && \
    /home/svc/.venv/bin/python -m ensurepip --upgrade && \
    /home/svc/.venv/bin/python -m pip install -U pip setuptools wheel && \
    /home/svc/.venv/bin/pip install . && \
    chown -R --recursive svc:svc /home/svc/.venv

# Clean up build tools to reduce image size
RUN apt-get remove -y build-essential gcc python3-dev && \
    apt-get autoremove -y && \
    apt-get clean && rm -rf /var/lib/apt/lists/*

FROM python:3.11

ARG DEBIAN_FRONTEND=noninteractive

# Create the same non-root user in the final image
RUN groupadd -g 1001 svc && useradd -m -u 1001 -g svc svc

# Copy the built venv from the build stage
COPY --from=build-venv /home/svc/.venv /home/svc/.venv

WORKDIR /home/svc
USER 1001
ENV PATH="/home/svc/.venv/bin:${PATH}"

ENTRYPOINT ["chaos"]
CMD ["--help"]