Skip to content

Commit 5035133

Browse files
committed
Enable docker layer caching with cargo chef
We don't need to target musl, `gcompat` allows us to use glibc programs on alpine
1 parent 09781fc commit 5035133

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

Dockerfile

+20-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
11
# build openapi-codegen
2-
FROM rust:1.85 AS openapi-codegen-builder
3-
ARG RUST_TARGET="x86_64-unknown-linux-musl"
2+
FROM docker.io/lukemathwalker/cargo-chef:latest-rust-1.85 AS chef
43
WORKDIR /app
5-
RUN rustup target add ${RUST_TARGET}
4+
5+
FROM chef AS planner
6+
7+
COPY Cargo.toml .
8+
COPY Cargo.lock .
9+
COPY build.rs .
10+
COPY src /app/src
11+
12+
RUN cargo chef prepare --recipe-path recipe.json
13+
14+
FROM chef AS openapi-codegen-builder
15+
16+
COPY --from=planner /app/recipe.json recipe.json
17+
18+
RUN cargo chef cook --release --recipe-path recipe.json
19+
620
COPY Cargo.toml .
721
COPY Cargo.lock .
822
COPY build.rs .
923
COPY src /app/src
10-
RUN cargo build --target ${RUST_TARGET} --release --bin openapi-codegen
24+
25+
RUN cargo build --release --bin openapi-codegen
1126

1227
# build rubyfmt
1328
FROM docker.io/rust:1.85 AS rubyfmt-builder
@@ -50,7 +65,6 @@ RUN rm -rf /usr/local/go/*.md && \
5065

5166
# main image
5267
FROM alpine:3.21
53-
ARG RUST_TARGET="x86_64-unknown-linux-musl"
5468
ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/root/.cargo/bin"
5569
RUN apk add --no-cache openjdk17-jre-headless curl gcompat libgcc ruff libstdc++
5670

@@ -116,4 +130,4 @@ RUN apk add --no-cache binutils && \
116130
apk del binutils
117131

118132
# openapi-codegen
119-
COPY --from=openapi-codegen-builder /app/target/${RUST_TARGET}/release/openapi-codegen /usr/bin/
133+
COPY --from=openapi-codegen-builder /app/target/release/openapi-codegen /usr/bin/

0 commit comments

Comments
 (0)