33#########################
44ARG BASE_IMAGE
55
6+ ARG PKG_CACHE="on"
7+
68######################################################
79# mongocli-builder (build stage only, not published) #
810######################################################
@@ -34,6 +36,7 @@ ARG TRUSTYAI_SOURCE_CODE=jupyter/trustyai/ubi9-python-3.12
3436COPY ${TRUSTYAI_SOURCE_CODE}/pylock.toml .
3537COPY ${TRUSTYAI_SOURCE_CODE}/devel_env_setup.sh .
3638
39+ ARG PKG_CACHE
3740RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=notebooks-dnf \
3841 --mount=type=cache,target=/root/.cache/uv /bin/bash <<'EOF'
3942set -Eeuxo pipefail
@@ -52,6 +55,8 @@ source ./devel_env_setup.sh
5255# we often don't know the correct hashes and `--require-hashes` would therefore fail on non amd64, where building is common.
5356# RHAIENG-2111: building pandas requires cython from PyPI
5457UV_LINK_MODE=copy uv pip install --strict --no-deps --refresh --no-config --no-progress --verify-hashes --compile-bytecode --index-strategy=unsafe-best-match --extra-index-url https://pypi.org/simple --requirements=./pylock.toml
58+
59+ if [ "${PKG_CACHE}" == "off" ]; then dnf clean all; fi
5560EOF
5661
5762####################
8085# Problem: The operation would result in removing the following protected packages: systemd
8186# (try to add '--allowerasing' to command line to replace conflicting packages or '--skip-broken' to skip uninstallable packages)
8287# Solution: --best --skip-broken does not work either, so use --nobest
88+ ARG PKG_CACHE
8389RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=notebooks-dnf /bin/bash <<'EOF'
8490set -Eeuxo pipefail
85- dnf -y upgrade --refresh --nobest --skip-broken --nodocs --noplugins --setopt=install_weak_deps=0 --setopt=keepcache=1
91+ dnf -y upgrade --refresh --nobest --skip-broken --nodocs --noplugins --setopt=install_weak_deps=0 --setopt=keepcache=$DNF_KEEPCACHE
92+
93+ if [ "${PKG_CACHE}" == "off" ]; then dnf clean all; fi
8694EOF
8795
8896### END upgrade first to avoid fixable vulnerabilities
8997
9098# Install useful OS packages
99+ ARG PKG_CACHE
91100RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=notebooks-dnf /bin/bash <<'EOF'
92101set -Eeuxo pipefail
93102dnf install -y --setopt=keepcache=1 perl mesa-libGL skopeo
103+
104+ if [ "${PKG_CACHE}" == "off" ]; then dnf clean all; fi
94105EOF
95106
96107# Other apps and tools installed as default user
@@ -152,9 +163,12 @@ WORKDIR /opt/app-root/bin
152163USER root
153164
154165# Install useful OS packages
166+ ARG PKG_CACHE
155167RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=notebooks-dnf /bin/bash <<'EOF'
156168set -Eeuxo pipefail
157169dnf install -y --setopt=keepcache=1 jq unixODBC unixODBC-devel postgresql git-lfs libsndfile libxcrypt-compat
170+
171+ if [ "${PKG_CACHE}" == "off" ]; then dnf clean all; fi
158172EOF
159173
160174# Copy dynamically-linked mongocli built in earlier build stage
@@ -192,6 +206,7 @@ USER 0
192206
193207# Install jre that is needed to run the trustyai library
194208# Also install runtime libraries for s390x/ppc64le
209+ ARG PKG_CACHE
195210RUN --mount=type=cache,target=/var/cache/dnf,sharing=locked,id=notebooks-dnf /bin/bash <<'EOF'
196211set -Eeuxo pipefail
197212INSTALL_PKGS="java-17-openjdk"
@@ -206,6 +221,8 @@ if [ "$ARCH" = "s390x" ] || [ "$ARCH" = "ppc64le" ]; then
206221 ln -sf /usr/lib64/libopenblasp.so.0 /usr/lib64/libopenblas.so.0
207222 ldconfig
208223fi
224+
225+ if [ "${PKG_CACHE}" == "off" ]; then dnf clean all; fi
209226EOF
210227
211228# Install Python packages and Jupyterlab extensions from requirements.txt
0 commit comments