Skip to content

docker: Build with persistent cache#273

Open
Rongronggg9 wants to merge 3 commits into
sashiko-dev:mainfrom
Rongronggg9:docker-cache
Open

docker: Build with persistent cache#273
Rongronggg9 wants to merge 3 commits into
sashiko-dev:mainfrom
Rongronggg9:docker-cache

Conversation

@Rongronggg9

Copy link
Copy Markdown

Cache downloaded and generated files with RUN --mount=type=cache, so that later builds don't need to download and build everything from scratch.

Some Docker versions could run into bugs when a later stage accesses a cached directory from previous stages, so copy the binaries into a separate directory first. Doing so also allows Stage 2 to merge multiple COPY --from=builder steps into a single one.

This series also bumps rust image version to 1.90, otherwise it keeps downloading 1.90 according to rust-toolchain.toml.

Link: https://docs.docker.com/build/cache/optimize/#use-cache-mounts

Otherwise it keeps downloading 1.90 according to rust-toolchain.toml.

Fixes: 78f36a1 ("chore: bump rust version to 1.90.0")
Signed-off-by: Rong Zhang <i@rong.moe>
Cache downloaded and generated files with `RUN --mount=type=cache', so
that later builds don't need to download and build everything from
scratch.

Some Docker versions could run into bugs when a later stage accesses a
cached directory from previous stages, so copy the binaries into a
separate directory first. Doing so also allows Stage 2 to merge multiple
`COPY --from=builder' steps into a single one.

Link: https://docs.docker.com/build/cache/optimize/#use-cache-mounts
Signed-off-by: Rong Zhang <i@rong.moe>
Building Sashiko requires both clippy and rustfmt to be installed. They
were implicitly downloaded and installed during `cargo build', which is
not optimal as they couldn't be cached properly unless the
`--mount=type=cache' directories cover them as well.

However, covering them with `--mount=type=cache' is overkill. Simply
installing them first in a dedicated step allows the persistent cache to
cover them as well, so that the build step won't repeatedly download and
install them in each build attempt.

Signed-off-by: Rong Zhang <i@rong.moe>
@Rongronggg9

Copy link
Copy Markdown
Author

Added a new commit to cache the installations of clippy and rustfmt as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant