Skip to content

Commit 86cf3bb

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 f22ff3a commit 86cf3bb

File tree

1 file changed

+19
-6
lines changed

1 file changed

+19
-6
lines changed

Dockerfile

+19-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,26 @@
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+
67
COPY Cargo.toml .
78
COPY Cargo.lock .
89
COPY src /app/src
9-
RUN cargo build --target ${RUST_TARGET} --release --bin openapi-codegen
10+
11+
RUN cargo chef prepare --recipe-path recipe.json
12+
13+
FROM chef AS openapi-codegen-builder
14+
15+
COPY --from=planner /app/recipe.json recipe.json
16+
17+
RUN cargo chef cook --release --recipe-path recipe.json
18+
19+
COPY Cargo.toml .
20+
COPY Cargo.lock .
21+
COPY src /app/src
22+
23+
RUN cargo build --release --bin openapi-codegen
1024

1125
# build rubyfmt
1226
FROM docker.io/rust:1.85 AS rubyfmt-builder
@@ -49,7 +63,6 @@ RUN rm -rf /usr/local/go/*.md && \
4963

5064
# main image
5165
FROM alpine:3.21
52-
ARG RUST_TARGET="x86_64-unknown-linux-musl"
5366
ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/go/bin:/root/.cargo/bin"
5467
RUN apk add --no-cache openjdk17-jre-headless curl gcompat libgcc ruff libstdc++
5568

@@ -115,4 +128,4 @@ RUN apk add --no-cache binutils && \
115128
apk del binutils
116129

117130
# openapi-codegen
118-
COPY --from=openapi-codegen-builder /app/target/${RUST_TARGET}/release/openapi-codegen /usr/bin/
131+
COPY --from=openapi-codegen-builder /app/target/release/openapi-codegen /usr/bin/

0 commit comments

Comments
 (0)