Skip to content

Commit d299452

Browse files
committed
Use cargo chef to optimize Docker build
1 parent fc55ec2 commit d299452

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Dockerfile

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
FROM node:18 as frontend
22

3-
COPY ./site ./site
3+
COPY ./site/frontend ./site/frontend
44
RUN cd site/frontend && npm ci
55
RUN cd site/frontend && npm run check
66
RUN cd site/frontend && npm run build
77

8-
FROM ubuntu:20.04 as build
8+
FROM ubuntu:20.04 as base
9+
10+
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse
911

1012
RUN apt-get update -y && \
1113
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
@@ -23,6 +25,17 @@ RUN apt-get update -y && \
2325
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- \
2426
--default-toolchain stable --profile minimal -y
2527

28+
RUN bash -c 'source $HOME/.cargo/env && cargo install cargo-chef'
29+
30+
FROM base AS planner
31+
COPY . .
32+
RUN bash -c 'source $HOME/.cargo/env && cargo chef prepare --recipe-path recipe.json'
33+
34+
FROM base as build
35+
COPY --from=planner recipe.json recipe.json
36+
37+
RUN bash -c 'source $HOME/.cargo/env && cargo chef cook --release --recipe-path recipe.json'
38+
2639
COPY ./Cargo.lock ./Cargo.lock
2740
COPY ./Cargo.toml ./Cargo.toml
2841
COPY ./collector ./collector

0 commit comments

Comments
 (0)