Dockerfile53 lines · 1476 chars FROM python:3.11-slim
LABEL maintainer="chaostoolkit <contact@chaostoolkit.org>"
ARG PDM_BUILD_SCM_VERSION=0.0.0
# Create non-root user
RUN groupadd -g 1001 svc && useradd -m -u 1001 -g svc svc
WORKDIR /home/svc
# Copy build configuration first to utilize Docker cache
COPY pyproject.toml pdm.lock /home/svc/
# Install build dependencies and Python tooling
RUN apt-get update && \
apt-get install -y --no-install-recommends \
curl \
ca-certificates \
libffi-dev \
gcc \
build-essential && \
rm -rf /var/lib/apt/lists/* && \
python -m pip install --no-cache-dir --upgrade pip setuptools wheel && \
python -m pip install --no-cache-dir pdm
# Create and configure the project virtual environment via PDM
RUN pdm config build-system.requirements-python 3.11 || true
RUN pdm venv create python3.11
RUN pdm use .venv
# Expose PDM SCM version to the build process
ENV PDM_BUILD_SCM_VERSION=${PDM_BUILD_SCM_VERSION}
# Copy the rest of the source code (including README.md)
COPY --chown=svc:svc . /home/svc/
# Ensure the venv is used in PATH
ENV PATH="/home/svc/.venv/bin:${PATH}"
# Install project dependencies from lock file in production mode
RUN pdm update --no-editable --prod --frozen-lockfile
# Remove build dependencies to shrink the final image
RUN apt-get purge -y --auto-remove gcc build-essential && \
rm -rf /var/lib/apt/lists/*
# Run as non-root user
USER 1001
ENTRYPOINT ["chaos"]
CMD ["--help"]