From 17141ceb5bd35f592ee83acf6868768894a62599 Mon Sep 17 00:00:00 2001 From: casjay Date: Sun, 31 May 2026 11:43:13 -0400 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20BuildKit=20cache=20mounts,=20?= =?UTF-8?q?sccache,=20and=20full=20tooling=20suite=20=E2=9C=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cache strategy: BuildKit --mount=type=cache on apk and cargo/rustup/sccache directories so docker build never re-downloads packages between runs. sccache is available as a compilation cache; mount /root/.cache/sccache at runtime to persist compiled artifacts across container invocations. Added gdb, a nightly toolchain (miri + rust-src), and a broad set of linting, formatting, debugging, fuzzing, and analysis tools. - Dockerfile: add # syntax=docker/dockerfile:1 pragma; add BuildKit cache mount for /var/cache/apk on the packages RUN step; add cache mounts for cargo/registry (shared), cargo/git, rustup/downloads, and sccache on the custom commands RUN step; add SCCACHE_DIR and CARGO_INCREMENTAL ENV vars; extend VOLUME to include /root/.cache/sccache - rootfs/root/docker/setup/05-custom.sh: add gdb to system packages; install nightly toolchain (minimal profile) with miri + rust-src; extend binstall block with sccache, typos, taplo-cli, cargo-sort, cargo-hack, cargo-criterion, dprint, cargo-careful, cargo-public-api, cargo-spellcheck, cargo-geiger, grcov; add fallback cargo installs for cargo-udeps, cargo-fuzz, cargo-minimal-versions; export SCCACHE_DIR and CARGO_INCREMENTAL in /etc/profile.d/rust.sh; create /root/.cache/sccache Dockerfile rootfs/root/docker/setup/05-custom.sh --- Dockerfile | 14 +++++++++++--- rootfs/root/docker/setup/05-custom.sh | 27 ++++++++++++++++++++++++--- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Dockerfile b/Dockerfile index 1cae772..f807f1e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 # Docker image for rust using the alpine template ARG IMAGE_NAME="rust" ARG PHP_SERVER="rust" @@ -99,7 +100,8 @@ RUN echo "Running pre-package commands"; \ $SHELL_OPTS; \ echo "" -RUN echo "Setting up and installing packages"; \ +RUN --mount=type=cache,id=apk-cache,sharing=locked,target=/var/cache/apk \ + echo "Setting up and installing packages"; \ $SHELL_OPTS; \ if [ -n "${PACK_LIST}" ];then echo "Installing packages: $PACK_LIST";echo "${PACK_LIST}" >/root/docker/setup/packages.txt;pkmgr install ${PACK_LIST};fi; \ echo "" @@ -154,7 +156,11 @@ RUN echo "Custom Applications"; \ $SHELL_OPTS; \ echo "" -RUN echo "Running custom commands"; \ +RUN --mount=type=cache,id=cargo-registry,sharing=shared,target=/usr/local/share/cargo/registry \ + --mount=type=cache,id=cargo-git,sharing=locked,target=/usr/local/share/cargo/git \ + --mount=type=cache,id=rustup-downloads,sharing=locked,target=/usr/local/share/rustup/downloads \ + --mount=type=cache,id=sccache-build,sharing=locked,target=/root/.cache/sccache \ + echo "Running custom commands"; \ if [ -f "/root/docker/setup/05-custom.sh" ];then echo "Running the custom script";/root/docker/setup/05-custom.sh||{ echo "Failed to execute /root/docker/setup/05-custom.sh" && exit 10; };echo "Done running the custom script";fi; \ echo "" @@ -248,10 +254,12 @@ ENV WWW_ROOT_DIR="${WWW_ROOT_DIR}" ENV RUSTUP_HOME="/usr/local/share/rustup" ENV CARGO_HOME="/usr/local/share/cargo" ENV RUSTUP_TOOLCHAIN="stable" +ENV SCCACHE_DIR="/root/.cache/sccache" +ENV CARGO_INCREMENTAL="0" COPY --from=build /. / -VOLUME [ "/config","/data","/usr/local/share/cargo","/usr/local/share/rustup" ] +VOLUME [ "/config","/data","/usr/local/share/cargo","/usr/local/share/rustup","/root/.cache/sccache" ] EXPOSE ${SERVICE_PORT} ${ENV_PORTS} diff --git a/rootfs/root/docker/setup/05-custom.sh b/rootfs/root/docker/setup/05-custom.sh index df8ba7e..9220e28 100755 --- a/rootfs/root/docker/setup/05-custom.sh +++ b/rootfs/root/docker/setup/05-custom.sh @@ -32,7 +32,7 @@ exitCode=0 # Main script # Install C/C++ toolchain and static-build dependencies needed by Rust -sys crates -pkmgr install build-base musl-dev clang lld cmake make perl openssl-dev pkgconf +pkmgr install build-base musl-dev clang lld cmake make perl openssl-dev pkgconf gdb # Install cross-compile toolchains — failures are non-fatal on minimal mirrors pkmgr install mingw-w64-gcc || true @@ -80,6 +80,10 @@ rm -f /tmp/rustup-init /tmp/rustup-init.sha256 # Add components not included in the default profile rustup component add rust-src rust-analyzer llvm-tools-preview +# Nightly toolchain for miri and other unstable tooling; minimal profile +# keeps the download small — only the compiler and std/src are pulled in +rustup toolchain install nightly --profile minimal --component miri rust-src + # - - - - - - - - - - - - - - - - - - - - - - - - - # Cross-compile targets — Linux musl (fully static, no libc dependency) rustup target add \ @@ -181,7 +185,19 @@ cargo binstall -y \ cargo-bloat \ cargo-asm \ mdbook \ - mdbook-toc + mdbook-toc \ + sccache \ + typos \ + taplo-cli \ + cargo-sort \ + cargo-hack \ + cargo-criterion \ + dprint \ + cargo-careful \ + cargo-public-api \ + cargo-spellcheck \ + cargo-geiger \ + grcov # Tools that occasionally lack musl prebuilts — fall back to source compilation cargo binstall -y cargo-dist 2>/dev/null || cargo install cargo-dist @@ -190,6 +206,9 @@ cargo binstall -y cargo-mutants 2>/dev/null || cargo install cargo-mutants cargo binstall -y flip-link 2>/dev/null || cargo install flip-link cargo binstall -y cargo-ndk 2>/dev/null || cargo install cargo-ndk cargo binstall -y trunk 2>/dev/null || cargo install trunk 2>/dev/null || true +cargo binstall -y cargo-udeps 2>/dev/null || cargo install cargo-udeps || true +cargo binstall -y cargo-fuzz 2>/dev/null || cargo install cargo-fuzz || true +cargo binstall -y cargo-minimal-versions 2>/dev/null || cargo install cargo-minimal-versions || true # cross (the cross-rs cross-compilation runner) cargo binstall -y cross 2>/dev/null || cargo install cross 2>/dev/null || true @@ -265,10 +284,12 @@ export RUSTUP_HOME="${RUSTUP_HOME}" export CARGO_HOME="${CARGO_HOME}" export RUSTUP_TOOLCHAIN="stable" export PATH="${CARGO_HOME}/bin:\${PATH}" +export SCCACHE_DIR="\${SCCACHE_DIR:-/root/.cache/sccache}" +export CARGO_INCREMENTAL="\${CARGO_INCREMENTAL:-0}" PROFILE # Work directories mounted or referenced in the README -mkdir -p /app /work /root/app /root/project /data/build +mkdir -p /app /work /root/app /root/project /data/build /root/.cache/sccache # - - - - - - - - - - - - - - - - - - - - - - - - - # Set the exit code