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