Add BuildKit cache mounts, sccache, and full tooling suite

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
This commit is contained in:
2026-05-31 11:43:13 -04:00
parent e36a6888dd
commit 17141ceb5b
2 changed files with 35 additions and 6 deletions
+11 -3
View File
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
# Docker image for rust using the alpine template # Docker image for rust using the alpine template
ARG IMAGE_NAME="rust" ARG IMAGE_NAME="rust"
ARG PHP_SERVER="rust" ARG PHP_SERVER="rust"
@@ -99,7 +100,8 @@ RUN echo "Running pre-package commands"; \
$SHELL_OPTS; \ $SHELL_OPTS; \
echo "" 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; \ $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; \ if [ -n "${PACK_LIST}" ];then echo "Installing packages: $PACK_LIST";echo "${PACK_LIST}" >/root/docker/setup/packages.txt;pkmgr install ${PACK_LIST};fi; \
echo "" echo ""
@@ -154,7 +156,11 @@ RUN echo "Custom Applications"; \
$SHELL_OPTS; \ $SHELL_OPTS; \
echo "" 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; \ 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 "" echo ""
@@ -248,10 +254,12 @@ ENV WWW_ROOT_DIR="${WWW_ROOT_DIR}"
ENV RUSTUP_HOME="/usr/local/share/rustup" ENV RUSTUP_HOME="/usr/local/share/rustup"
ENV CARGO_HOME="/usr/local/share/cargo" ENV CARGO_HOME="/usr/local/share/cargo"
ENV RUSTUP_TOOLCHAIN="stable" ENV RUSTUP_TOOLCHAIN="stable"
ENV SCCACHE_DIR="/root/.cache/sccache"
ENV CARGO_INCREMENTAL="0"
COPY --from=build /. / 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} EXPOSE ${SERVICE_PORT} ${ENV_PORTS}
+24 -3
View File
@@ -32,7 +32,7 @@ exitCode=0
# Main script # Main script
# Install C/C++ toolchain and static-build dependencies needed by Rust -sys crates # 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 # Install cross-compile toolchains — failures are non-fatal on minimal mirrors
pkmgr install mingw-w64-gcc || true 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 # Add components not included in the default profile
rustup component add rust-src rust-analyzer llvm-tools-preview 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) # Cross-compile targets — Linux musl (fully static, no libc dependency)
rustup target add \ rustup target add \
@@ -181,7 +185,19 @@ cargo binstall -y \
cargo-bloat \ cargo-bloat \
cargo-asm \ cargo-asm \
mdbook \ 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 # Tools that occasionally lack musl prebuilts — fall back to source compilation
cargo binstall -y cargo-dist 2>/dev/null || cargo install cargo-dist 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 flip-link 2>/dev/null || cargo install flip-link
cargo binstall -y cargo-ndk 2>/dev/null || cargo install cargo-ndk 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 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) # cross (the cross-rs cross-compilation runner)
cargo binstall -y cross 2>/dev/null || cargo install cross 2>/dev/null || true 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 CARGO_HOME="${CARGO_HOME}"
export RUSTUP_TOOLCHAIN="stable" export RUSTUP_TOOLCHAIN="stable"
export PATH="${CARGO_HOME}/bin:\${PATH}" export PATH="${CARGO_HOME}/bin:\${PATH}"
export SCCACHE_DIR="\${SCCACHE_DIR:-/root/.cache/sccache}"
export CARGO_INCREMENTAL="\${CARGO_INCREMENTAL:-0}"
PROFILE PROFILE
# Work directories mounted or referenced in the README # 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 # Set the exit code