|
| 1 | +# syntax=docker/dockerfile:1 |
| 2 | +############################################################## |
| 3 | +# This Dockerfile builds a base image with a free-threaded |
| 4 | +# build of Python 3.13. |
| 5 | +# |
| 6 | +# This is EXPERIMENTAL and intended for development and |
| 7 | +# testing purposes only. |
| 8 | +############################################################## |
| 9 | + |
| 10 | +ARG FROM_IMAGE=ubuntu:22.04 |
| 11 | + |
| 12 | +# Builder stage: build Python 3.13 from source with the GIL disabled |
| 13 | +FROM $FROM_IMAGE AS builder |
| 14 | + |
| 15 | +ARG DEBIAN_FRONTEND=noninteractive |
| 16 | + |
| 17 | +# Install build dependencies for Python |
| 18 | +RUN apt-get update && apt-get install -y \ |
| 19 | + build-essential \ |
| 20 | + git \ |
| 21 | + libffi-dev \ |
| 22 | + libssl-dev \ |
| 23 | + zlib1g-dev |
| 24 | + |
| 25 | +# Clone CPython repository at the 3.13 branch |
| 26 | +RUN git clone --depth 1 --branch 3.13 https://github.com/python/cpython.git /usr/src/cpython |
| 27 | + |
| 28 | +WORKDIR /usr/src/cpython |
| 29 | + |
| 30 | +# Configure, compile, and install Python with the free-threaded build |
| 31 | +# --disable-gil: The key flag to enable the free-threaded build |
| 32 | +# --enable-optimizations: Apply profile-guided optimizations for better performance |
| 33 | +RUN ./configure --prefix=/opt/python3 --disable-gil --enable-optimizations |
| 34 | +RUN make -j$(nproc) |
| 35 | +RUN make install |
| 36 | + |
| 37 | +# Base runtime stage |
| 38 | +FROM $FROM_IMAGE |
| 39 | + |
| 40 | +ARG DEBIAN_FRONTEND=noninteractive |
| 41 | + |
| 42 | +# Copy our Python build from the builder stage |
| 43 | +COPY --from=builder /opt/python3/ /opt/python3/ |
| 44 | + |
| 45 | +# Set the PATH to include our custom Python build |
| 46 | +ENV PATH="/opt/python3/bin:${PATH}" |
| 47 | + |
| 48 | +# Install essential runtime dependencies. |
| 49 | +# Downstream images are responsible for installing Devito-specific |
| 50 | +# dependencies such as compilers/MPI. |
| 51 | +RUN apt-get update && apt-get install -y \ |
| 52 | + libnuma-dev && \ |
| 53 | + rm -rf /var/lib/apt/lists/* |
| 54 | + |
| 55 | +RUN python3 -m pip install --upgrade pip && \ |
| 56 | + python3 -m pip cache purge |
| 57 | + |
0 commit comments