Image builds keep compiled crates between builds (#438)
The ipx Dockerfile built its dependencies in a layer of stub crates, which any change to Cargo.toml or Cargo.lock invalidated: all of them compiled again in release, 405 crates, 170 s at the builder's cap. The directory's had no such layer and compiled everything every time. Both now build with cargo's registry and target/ as BuildKit cache mounts. Measured on Tower: a Cargo.toml change rebuilds three crates in 52 s instead of 405 in 170 s. The peak is about the same, since the ipx crate itself is most of it; what goes is the minutes at the cap. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -6,18 +6,22 @@ RUN apt-get update && apt-get install -y --no-install-recommends build-essential
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /src
|
||||
# Every member of the workspace, since cargo reads them all to build one.
|
||||
# ponytail: no dependency layer, so each build compiles sea-orm again; add the stub trick from
|
||||
# the main Dockerfile if builds get slow enough to matter.
|
||||
COPY Cargo.toml Cargo.lock ./
|
||||
COPY crates ./crates
|
||||
# The logo and icon the public pages serve (#215), compiled into the binary.
|
||||
COPY web/logo.svg web/logo-dark.svg web/favicon.png ./web/
|
||||
RUN cargo build --release --locked -p ipx-directory
|
||||
# Compiled crates kept in the builder between builds, as in the main Dockerfile (#438). A target
|
||||
# of its own: built with ipx's, the two would rebuild shared crates for each other's features.
|
||||
RUN --mount=type=cache,id=ipx-cargo-registry,target=/usr/local/cargo/registry,sharing=locked \
|
||||
--mount=type=cache,id=ipx-directory-target,target=/src/target,sharing=locked \
|
||||
touch crates/directory/src/main.rs crates/directory/src/lib.rs crates/feed/src/lib.rs \
|
||||
&& cargo build --release --locked -p ipx-directory \
|
||||
&& cp target/release/ipx-directory /usr/local/bin/ipx-directory
|
||||
|
||||
FROM debian:trixie-slim
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
COPY --from=build /src/target/release/ipx-directory /usr/local/bin/ipx-directory
|
||||
COPY --from=build /usr/local/bin/ipx-directory /usr/local/bin/ipx-directory
|
||||
ENV DIRECTORY_CONFIG=/config/directory.toml
|
||||
# Unraid's nobody:users. It writes nothing to disk: the database is elsewhere.
|
||||
USER 99:100
|
||||
|
||||
Reference in New Issue
Block a user