@@ -13,12 +13,10 @@ ENV PATH="/app/venv/bin":$PATH
1313# Comment out or remove if specified system-level packages do not need to be present during the build stage
1414RUN apk add --no-cache ${APK_LIST}
1515
16- # Build a script used to install packages during the distroless stage
17- # The find commands allow us to avoid hardcoding the version number of libapk.so
18- RUN echo "cp /lib/libapk.so $(find /lib -name 'libapk.so*')" > /add_apks.sh
19- RUN echo "apk add --no-cache ${APK_LIST}" >> /add_apks.sh
20- RUN echo "rm $(find /lib -name 'libapk.so*')" >> /add_apks.sh
21- RUN cp $(find /lib -name 'libapk.so*' ) /lib/libapk.so
16+ # Install the packages into a root derived from the distroless image.
17+ COPY --from=cgr.dev/chainguard/python:latest / /base-chroot
18+ RUN apk add --no-commit-hooks --no-cache --root /base-chroot ${APK_LIST}
19+
2220USER 0
2321
2422# Install desired Python packages
@@ -32,27 +30,15 @@ RUN pip install --upgrade pip setuptools wheel && \
3230
3331FROM cgr.dev/chainguard/python:latest
3432
33+ # Replace the filesystem with the one containing the additional packages.
34+ COPY --from=dev /base-chroot /
35+
3536WORKDIR /app
3637
3738COPY --from=dev /app/__pycache__ /app/__pycache__
38- COPY --from=dev add_apks.sh add_apks.sh
3939COPY --from=dev /app/venv /app/venv
4040COPY main.py main.py
41- USER root
4241
43- # Mount resources needed to install apks and run the install script
44- RUN --mount=type=bind,from=dev,target=/sbin/apk,source=/sbin/apk \
45- --mount=type=bind,from=dev,target=/bin/busybox,source=/bin/busybox \
46- --mount=type=bind,from=dev,target=/bin/sh,source=/bin/sh \
47- --mount=type=bind,from=dev,target=/bin/cp,source=/bin/cp \
48- --mount=type=bind,from=dev,target=/bin/rm,source=/bin/rm \
49- --mount=type=bind,from=dev,target=/etc/apk/keys,source=/etc/apk/keys,rw \
50- --mount=type=bind,from=dev,target=/etc/apk/repositories,source=/etc/apk/repositories,rw \
51- --mount=type=bind,from=dev,target=/etc/apk/protected_paths.d,source=/etc/apk/protected_paths.d,rw \
52- --mount=type=bind,from=dev,target=/lib/libapk.so,source=/lib/libapk.so,rw \
53- --mount=type=bind,from=dev,target=/add_apks.sh,source=/add_apks.sh,rw \
54- /bin/sh /add_apks.sh
55-
56- USER 0
5742ENV PATH="/app/venv/bin:$PATH"
58- ENTRYPOINT ["python" , "__pycache__/main.cpython-312.pyc" ]
43+
44+ ENTRYPOINT ["python" , "__pycache__/main.cpython-313.pyc" ]
0 commit comments