Skip to content

Commit e03222a

Browse files
committed
feat(docker): adopt cargo-chef
1 parent 8f2b017 commit e03222a

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

Dockerfile

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,24 @@
1-
FROM --platform=amd64 rust:1.72-alpine as builder
2-
WORKDIR /build
1+
FROM --platform=amd64 rust:1.72-alpine as common-build
32

4-
# RUN apt-get update && apt-get install -y build-essential musl-dev musl-tools gcc-x86-64-linux-gnu && apt-get clean && rm -rf /var/lib/apt/lists/*
53
RUN apk update && apk upgrade && apk add --no-cache musl-dev
64
RUN rustup target add x86_64-unknown-linux-musl
5+
RUN cargo install cargo-chef --locked
76

8-
ENV CARGO_BUILD_RUSTFLAGS="-C target-feature=+crt-static"
7+
WORKDIR /build
8+
9+
FROM common-build AS planner
910

10-
COPY Cargo.toml Cargo.lock ./
11-
RUN mkdir -p src && touch src/main.rs
12-
RUN cargo fetch --target x86_64-unknown-linux-musl --locked
11+
COPY . ./
12+
RUN cargo chef prepare --recipe-path recipe.json
13+
14+
FROM common-build AS builder
15+
16+
COPY --from=planner /build/recipe.json recipe.json
17+
RUN cargo chef cook --release --target x86_64-unknown-linux-musl --recipe-path recipe.json
1318

1419
COPY . ./
15-
RUN cargo build --target x86_64-unknown-linux-musl --release --locked
20+
ENV CARGO_BUILD_RUSTFLAGS="-C target-feature=+crt-static"
21+
RUN cargo build --release --locked --target x86_64-unknown-linux-musl --bin valfisk
1622

1723
FROM gcr.io/distroless/static:latest
1824
COPY --from=builder /build/target/x86_64-unknown-linux-musl/release/valfisk /valfisk

0 commit comments

Comments
 (0)