@@ -189,77 +189,33 @@ RUN python3 -OO -m compileall -q /app/.venv /app/mcpgateway /app/plugins \
189189 && find /app -type d -name "__pycache__" -exec rm -rf {} + 2>/dev/null || true
190190
191191# ----------------------------------------------------------------------------
192- # Build a minimal, fully-patched rootfs containing only the runtime Python
193- # Include ca-certificates for HTTPS connections
194- # Note: ca-certificates installed separately to avoid scriptlet issues with QEMU
192+ # Build minimal rootfs by copying essential files from builder
193+ # This avoids complex --installroot issues with QEMU emulation
195194# ----------------------------------------------------------------------------
196- # hadolint ignore=DL3041
197195RUN set -euo pipefail \
198- && mkdir -p "${ROOTFS_PATH:?}" \
199- && dnf --installroot="${ROOTFS_PATH:?}" --releasever=10 upgrade -y \
200- && dnf --installroot="${ROOTFS_PATH:?}" \
201- --releasever=10 \
202- --setopt=install_weak_deps=0 \
203- --setopt=tsflags=nodocs \
204- --setopt=skip_if_unavailable=1 \
205- install -y \
206- filesystem \
207- bash \
208- python${PYTHON_VERSION} \
209- procps-ng \
210- && dnf reinstall --downloadonly --downloaddir=. ca-certificates \
211- && rpm --root="${ROOTFS_PATH:?}" --install --nodeps --noscripts ca-certificates-*.rpm \
212- && rm -f ca-certificates-*.rpm \
213- && dnf clean all --installroot="${ROOTFS_PATH:?}"
214-
215- # ----------------------------------------------------------------------------
216- # Create `python3` symlink in the rootfs for compatibility
217- # ----------------------------------------------------------------------------
218- RUN ln -sf /usr/bin/python${PYTHON_VERSION} ${ROOTFS_PATH:?}/usr/bin/python3
196+ && mkdir -p "${ROOTFS_PATH:?}"/{etc,usr,var,tmp,proc,sys,dev,run} \
197+ && cp -a /etc/{passwd,group,nsswitch.conf,pki,ssl} "${ROOTFS_PATH:?}/etc/" \
198+ && cp -a /usr/bin/python${PYTHON_VERSION} "${ROOTFS_PATH:?}/usr/bin/" \
199+ && cp -a /usr/bin/{bash,sh,ps} "${ROOTFS_PATH:?}/usr/bin/" \
200+ && cp -a /usr/lib64/python${PYTHON_VERSION} "${ROOTFS_PATH:?}/usr/lib64/" \
201+ && cp -a /usr/lib64/*.so* "${ROOTFS_PATH:?}/usr/lib64/" \
202+ && ln -sf python${PYTHON_VERSION} "${ROOTFS_PATH:?}/usr/bin/python3" \
203+ && ln -sf bash "${ROOTFS_PATH:?}/usr/bin/sh" \
204+ && chmod 1777 "${ROOTFS_PATH:?}/tmp" "${ROOTFS_PATH:?}/var/tmp"
219205
220206# ----------------------------------------------------------------------------
221- # Clean up unnecessary files from rootfs (if they exist)
222- # - Remove development headers, documentation
223- # - Use ${var:?} to prevent accidental deletion of host directories
207+ # Clean up Python test files to reduce image size
224208# ----------------------------------------------------------------------------
225- RUN set -euo pipefail \
226- && rm -rf ${ROOTFS_PATH:?}/usr/include/* \
227- ${ROOTFS_PATH:?}/usr/share/man/* \
228- ${ROOTFS_PATH:?}/usr/share/doc/* \
229- ${ROOTFS_PATH:?}/usr/share/info/* \
230- ${ROOTFS_PATH:?}/usr/share/locale/* \
231- ${ROOTFS_PATH:?}/var/log/* \
232- ${ROOTFS_PATH:?}/boot \
233- ${ROOTFS_PATH:?}/media \
234- ${ROOTFS_PATH:?}/srv \
235- ${ROOTFS_PATH:?}/usr/games \
236- && find ${ROOTFS_PATH:?}/usr/lib*/python*/ -type d -name "test" -exec rm -rf {} + 2>/dev/null || true \
209+ RUN find ${ROOTFS_PATH:?}/usr/lib*/python*/ -type d -name "test" -exec rm -rf {} + 2>/dev/null || true \
237210 && find ${ROOTFS_PATH:?}/usr/lib*/python*/ -type d -name "tests" -exec rm -rf {} + 2>/dev/null || true \
238211 && find ${ROOTFS_PATH:?}/usr/lib*/python*/ -type d -name "idle_test" -exec rm -rf {} + 2>/dev/null || true \
239212 && find ${ROOTFS_PATH:?}/usr/lib*/python*/ -name "*.mo" -delete 2>/dev/null || true \
240213 && rm -rf ${ROOTFS_PATH:?}/usr/lib*/python*/ensurepip \
241214 ${ROOTFS_PATH:?}/usr/lib*/python*/idlelib \
242- ${ROOTFS_PATH:?}/usr/lib*/python*/tkinter \
243- ${ROOTFS_PATH:?}/usr/lib*/python*/turtle* \
244- ${ROOTFS_PATH:?}/usr/lib*/python*/distutils/command/*.exe
245-
246- # ----------------------------------------------------------------------------
247- # Remove package managers and unnecessary system tools from rootfs
248- # - Keep RPM database for security scanning with Trivy/Dockle
249- # - This keeps the final image size minimal while allowing vulnerability scanning
250- # ----------------------------------------------------------------------------
251- RUN rm -rf ${ROOTFS_PATH:?}/usr/bin/dnf* \
252- ${ROOTFS_PATH:?}/usr/bin/yum* \
253- ${ROOTFS_PATH:?}/usr/bin/rpm* \
254- ${ROOTFS_PATH:?}/usr/bin/microdnf \
255- ${ROOTFS_PATH:?}/usr/lib/rpm \
256- ${ROOTFS_PATH:?}/usr/lib/dnf \
257- ${ROOTFS_PATH:?}/usr/lib/yum* \
258- ${ROOTFS_PATH:?}/etc/dnf \
259- ${ROOTFS_PATH:?}/etc/yum*
215+ ${ROOTFS_PATH:?}/usr/lib*/python*/tkinter 2>/dev/null || true
260216
261217# ----------------------------------------------------------------------------
262- # Strip unneeded symbols from shared libraries and remove binutils
218+ # Strip unneeded symbols from shared libraries
263219# - This reduces the final image size and removes the build tool in one step
264220# ----------------------------------------------------------------------------
265221RUN find "${ROOTFS_PATH:?}/usr/lib64" -name '*.so*' -exec strip --strip-unneeded {} + 2>/dev/null || true \
0 commit comments