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

Commit dd0edc5

Browse files
authored
Use cargo-chef (#549)
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]>
1 parent 15edf5e commit dd0edc5

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

Dockerfile

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,27 @@
11
# build sqld
2-
FROM rust:slim-bullseye AS builder
2+
FROM rust:slim-bullseye AS chef
33
RUN apt update \
44
&& apt install -y libclang-dev clang \
55
build-essential tcl protobuf-compiler file \
66
libssl-dev pkg-config git\
7-
&& apt clean
7+
&& apt clean \
8+
&& cargo install cargo-chef
9+
# We need to install and set as default the toolchain specified in rust-toolchain.toml
10+
# Otherwise cargo-chef will build dependencies using wrong toolchain
11+
# This also prevents planner and builder steps from installing the toolchain over and over again
12+
COPY rust-toolchain.toml rust-toolchain.toml
13+
RUN cat rust-toolchain.toml | grep "channel" | awk '{print $3}' | sed 's/\"//g' > toolchain.txt \
14+
&& rustup update $(cat toolchain.txt) \
15+
&& rustup default $(cat toolchain.txt) \
16+
&& rm toolchain.txt rust-toolchain.toml
17+
18+
FROM chef AS planner
19+
COPY . .
20+
RUN cargo chef prepare --recipe-path recipe.json
21+
22+
FROM chef AS builder
23+
COPY --from=planner /recipe.json recipe.json
24+
RUN cargo chef cook --release --recipe-path recipe.json
825
COPY . .
926
RUN cargo build -p sqld --release
1027

0 commit comments

Comments
 (0)