use cargo-chef to cache build
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
a23a36fa5b
commit
4f26722592
35
Dockerfile
35
Dockerfile
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user