Skip to content
This repository has been archived by the owner on Oct 18, 2023. It is now read-only.

Commit

Permalink
Use cargo-chef (#549)
Browse files Browse the repository at this point in the history
cargo-chef allows to split downloading and building dependencies
from building the actual project. This allows docker to cache a layer
that downloads and builds dependencies and rebuild only the project
instead.

This change reduced the incremental build for me by over 60% from 327s to 130s.

Signed-off-by: Piotr Jastrzebski <[email protected]>
  • Loading branch information
haaawk authored Jul 26, 2023
1 parent 15edf5e commit dd0edc5
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,27 @@
# build sqld
FROM rust:slim-bullseye AS builder
FROM rust:slim-bullseye AS chef
RUN apt update \
&& apt install -y libclang-dev clang \
build-essential tcl protobuf-compiler file \
libssl-dev pkg-config git\
&& apt clean
&& apt clean \
&& cargo install cargo-chef
# We need to install and set as default the toolchain specified in rust-toolchain.toml
# Otherwise cargo-chef will build dependencies using wrong toolchain
# This also prevents planner and builder steps from installing the toolchain over and over again
COPY rust-toolchain.toml rust-toolchain.toml
RUN cat rust-toolchain.toml | grep "channel" | awk '{print $3}' | sed 's/\"//g' > toolchain.txt \
&& rustup update $(cat toolchain.txt) \
&& rustup default $(cat toolchain.txt) \
&& rm toolchain.txt rust-toolchain.toml

FROM chef AS planner
COPY . .
RUN cargo chef prepare --recipe-path recipe.json

FROM chef AS builder
COPY --from=planner /recipe.json recipe.json
RUN cargo chef cook --release --recipe-path recipe.json
COPY . .
RUN cargo build -p sqld --release

Expand Down

0 comments on commit dd0edc5

Please sign in to comment.