@@ -6,7 +6,8 @@ ARG PYTHON_VERSION=3.12
66ARG SOURCE_IMAGE=docker.io/python:${PYTHON_VERSION}-alpine${ALPINE_VERSION}
77ARG BASE_IMAGE_DIGEST
88
9- FROM ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} AS buildroot
9+ FROM ${SOURCE_IMAGE}@${BASE_IMAGE_DIGEST} AS source
10+ FROM source AS buildroot
1011ARG PYTHON_VERSION=3.12
1112ARG TARGETARCH
1213ARG TARGETVARIANT
@@ -23,6 +24,7 @@ ENV BUILD_ROOT=$BUILD_ROOT \
2324 _ln="chroot $BUILD_ROOT /bin/ln" \
2425 _chroot="chroot $BUILD_ROOT"
2526
27+ COPY --from=source /dev /$BUILD_ROOT/dev
2628ADD --chmod=0755 chroot-apk.sh /usr/local/bin/chroot-apk
2729ADD --chmod=0755 chroot-pip.sh /usr/local/bin/chroot-pip
2830ADD --chmod=0755 chroot-ln.sh /usr/local/bin/chroot-ln
4749 $BUILD_ROOT/usr/local/lib/python$PYTHON_VERSION/site-packages \
4850 $BUILD_ROOT/usr/local/bin \
4951 $BUILD_ROOT/proc \
52+ $BUILD_ROOT/sys \
53+ $BUILD_ROOT/dev \
5054 ; \
51- cp -R /dev $BUILD_ROOT/dev ; \
5255 # copy the apk related confs
5356 cp -R /etc/apk $BUILD_ROOT/etc/apk ; \
5457 $_apk_add --initdb ; \
6366
6467RUN --security=insecure \
6568 set -eu ; \
66- mount --bind /proc /$BUILD_ROOT/proc ; \
69+ mount -t proc none $BUILD_ROOT/proc ; \
70+ mount -t sysfs none $BUILD_ROOT/sys ; \
71+ mount --rbind /dev /$BUILD_ROOT/dev ; \
6772 $_apk_add \
6873 busybox \
6974 dash \
@@ -97,15 +102,6 @@ RUN \
97102 # compile all py to an adjacent pyc and remove the original, leaving only the bytecode
98103 python -m compileall -q -b /usr/local/lib/python$PYTHON_VERSION ; \
99104 find -type f -name '*.py' -exec sh -c "remove-py-if-pyc-exists -q {}" \; ;\
100- # copy dash into the container so we can use it as the default bin/sh
101- # tar -C / -cpf - $(\
102- # apk info -L \
103- # dash \
104- # dash-binsh \
105- # ca-certificates \
106- # | grep -vE ':$' \
107- # ) | tar -C $BUILD_ROOT -xpf - ; \
108- # $_ln -sf /usr/bin/dash /bin/sh ; \
109105 (\
110106 cd /usr/local/lib && \
111107 tar -C /usr/local/lib -cpf - python$PYTHON_VERSION/lib-dynload libpython* | tar -C $BUILD_ROOT/usr/local/lib -xpf - ; \
0 commit comments