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
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}