Speed up image builds with Docker cache mounts

This commit is contained in:
Zanie 2024-01-18 20:20:56 -06:00
parent 3a1cd44fc6
commit c6ec7be27b
1 changed files with 11 additions and 2 deletions

View File

@ -34,8 +34,17 @@ RUN rustup target add $(cat rust_target.txt)
COPY crates crates COPY crates crates
COPY ./Cargo.toml Cargo.toml COPY ./Cargo.toml Cargo.toml
COPY ./Cargo.lock Cargo.lock COPY ./Cargo.lock Cargo.lock
RUN cargo zigbuild --bin puffin --target $(cat rust_target.txt) --release
RUN cp target/$(cat rust_target.txt)/release/puffin /puffin # Build with mounted cache
RUN --mount=type=cache,target=./target \
--mount=type=cache,target=/usr/local/cargo/git \
--mount=type=cache,target=/usr/local/cargo/registry \
cargo zigbuild --bin puffin --target $(cat rust_target.txt) --release
# Copy binary into normal layer
RUN --mount=type=cache,target=./target \
cp ./target/$(cat rust_target.txt)/release/puffin /puffin
# TODO(konsti): Optimize binary size, with a version that also works when cross compiling # TODO(konsti): Optimize binary size, with a version that also works when cross compiling
# RUN strip --strip-all /puffin # RUN strip --strip-all /puffin