perf(Dockerfile): improve Docker cache mounts usage (#4507)

As described in
https://hackmd.io/jgkoQ24YRW6i0xWd73S64A#Using-Docker-cache-mounts,
cache mounts need to be used with a fairly specific syntax for caching
of previously build Rust artifacts to be as effective as it can be.
This commit is contained in:
Alejandro González
2025-10-08 18:03:15 +02:00
committed by GitHub
parent 6919c8dea9
commit 15a7815ec3
2 changed files with 14 additions and 16 deletions

View File

@@ -5,8 +5,7 @@ FROM rust:1.89.0 AS build
WORKDIR /usr/src/daedalus WORKDIR /usr/src/daedalus
COPY . . COPY . .
RUN --mount=type=cache,target=/usr/src/daedalus/target \ RUN --mount=type=cache,target=/usr/src/daedalus/target \
--mount=type=cache,target=/usr/local/cargo/git/db \ --mount=type=cache,target=/usr/local/cargo,from=rust:1.89.0,source=/usr/local/cargo \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo build --release --package daedalus_client cargo build --release --package daedalus_client
FROM build AS artifacts FROM build AS artifacts

View File

@@ -6,8 +6,7 @@ WORKDIR /usr/src/labrinth
COPY . . COPY . .
ARG GIT_HASH ARG GIT_HASH
RUN --mount=type=cache,target=/usr/src/labrinth/target \ RUN --mount=type=cache,target=/usr/src/labrinth/target \
--mount=type=cache,target=/usr/local/cargo/git/db \ --mount=type=cache,target=/usr/local/cargo,from=rust:1.89.0,source=/usr/local/cargo \
--mount=type=cache,target=/usr/local/cargo/registry \
SQLX_OFFLINE=true cargo build --profile release-labrinth --package labrinth SQLX_OFFLINE=true cargo build --profile release-labrinth --package labrinth
FROM build AS artifacts FROM build AS artifacts