use cargo-chef to cache build
continuous-integration/drone/push Build is passing Details

This commit is contained in:
Dmitry Belyaev 2023-08-18 11:51:49 +03:00
parent a23a36fa5b
commit 4f26722592
Signed by: b4tman
GPG Key ID: 41A00BF15EA7E5F3
1 changed files with 22 additions and 13 deletions

View File

@ -1,25 +1,34 @@
FROM rust:1-alpine as builder
FROM rust:1-alpine as chef
ENV CARGO_REGISTRIES_CRATES_IO_PROTOCOL sparse
RUN apk add --no-cache musl-dev
RUN apk add --no-cache musl-dev curl
# install cargo-binstall
RUN curl -L --proto '=https' --tlsv1.2 -sSf https://raw.githubusercontent.com/cargo-bins/cargo-binstall/main/install-from-binstall-release.sh -o install-from-binstall-release.sh
RUN sh install-from-binstall-release.sh
# install cargo-chef
RUN cargo binstall -y cargo-chef
WORKDIR /home/rust/src
COPY Cargo.toml /home/rust/src/
COPY Cargo.lock /home/rust/src/
RUN mkdir /home/rust/src/src && \
echo 'fn main() {}' > /home/rust/src/src/main.rs
FROM chef AS planner
RUN cargo fetch
COPY . .
RUN cargo chef prepare --recipe-path recipe.json
FROM chef as builder
COPY --from=planner /home/rust/src/recipe.json recipe.json
# build & cache deps
RUN cargo chef cook --release --recipe-path recipe.json
# build app with cached deps
COPY . .
RUN cargo build --release
RUN rm -f /home/rust/src/src/main.rs
COPY src /home/rust/src/src
RUN touch /home/rust/src/src/main.rs
RUN cargo build -v --release
FROM scratch
COPY static /static