stagex/packages/python/Containerfile
2024-04-11 13:09:20 -07:00

52 lines
1.2 KiB
Docker

FROM scratch as base
ENV VERSION=3.11.8
ENV SRC_HASH=9e06008c8901924395bc1da303eac567a729ae012baa182ab39269f650383bb3
ENV SRC_FILE=Python-${VERSION}.tar.xz
ENV SRC_SITE=https://www.python.org/ftp/python/${VERSION}/${SRC_FILE}
FROM base as fetch
ADD --checksum=sha256:${SRC_HASH} ${SRC_SITE} .
FROM fetch as build
COPY --from=stagex/busybox . /
COPY --from=stagex/gcc . /
COPY --from=stagex/binutils . /
COPY --from=stagex/make . /
COPY --from=stagex/musl . /
COPY --from=stagex/openssl . /
COPY --from=stagex/zlib . /
COPY --from=stagex/bzip2 . /
COPY --from=stagex/sqlite3 . /
COPY --from=stagex/libffi . /
RUN tar -xf ${SRC_FILE}
WORKDIR Python-${VERSION}
ENV SOURCE_DATE_EPOCH=1
ENV PYTHONHASHSEED=0
ENV PYTHONDONTWRITEBYTECODE=1
RUN --network=none <<-EOF
set -eux
./configure \
--prefix=/usr \
--enable-shared \
--with-computed-gotos \
--without-ensurepip
make -j "$(nproc)"
EOF
FROM build as install
RUN --network=none <<-EOF
set -eux
make DESTDIR=/rootfs install
ln -s /usr/bin/python3 /rootfs/usr/bin/python
EOF
FROM scratch as test
COPY --from=install /rootfs/. /
COPY --from=stagex/musl . /
COPY <<-EOF test.py
print("Success")
EOF
RUN python test.py | grep "Success"
FROM stagex/filesystem as package
COPY --from=install /rootfs/. /