Skip to content

Commit a53ff7f

Browse files
committed
feat: add missing mounts to privileged layer, remove useless copy
1 parent 9015f0d commit a53ff7f

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

buildroot/Dockerfile.alpine

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ ARG PYTHON_VERSION=3.12
66
ARG SOURCE_IMAGE=docker.io/python:${PYTHON_VERSION}-alpine${ALPINE_VERSION}
77
ARG 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
1011
ARG PYTHON_VERSION=3.12
1112
ARG TARGETARCH
1213
ARG 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
2628
ADD --chmod=0755 chroot-apk.sh /usr/local/bin/chroot-apk
2729
ADD --chmod=0755 chroot-pip.sh /usr/local/bin/chroot-pip
2830
ADD --chmod=0755 chroot-ln.sh /usr/local/bin/chroot-ln
@@ -47,8 +49,9 @@ RUN \
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 ; \
@@ -63,7 +66,9 @@ RUN \
6366

6467
RUN --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 - ; \

runtime/Dockerfile.alpine

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
# syntax=docker/dockerfile:1.20-labs
2-
1+
# syntax=docker/dockerfile:1
32

43
ARG ALPINE_VERSION=3.20
54
ARG PYTHON_VERSION=3.12
@@ -15,7 +14,6 @@ ARG BUILD_ROOT='/dest'
1514
ENV BUILD_ROOT=$BUILD_ROOT \
1615
PYTHON_VERSION=$PYTHON_VERSION \
1716
ALPINE_VERSION=$ALPINE_VERSION
18-
COPY --from=buildroot /dev /dev
1917
COPY --from=buildroot $BUILD_ROOT /
2018
LABEL \
2119
org.opencontainers.image.authors="distroless-python image developers <[email protected]>" \

0 commit comments

Comments
 (0)