|
1 | 1 | # Update the rust version in-sync with the version in rust-toolchain.toml |
2 | | -FROM docker.io/rust:1.90.0-bookworm AS builder |
3 | 2 |
|
| 3 | +# Stage 0: Planner - Extract dependency metadata |
| 4 | +FROM docker.io/rust:1.90.0-slim-bookworm AS planner |
| 5 | +WORKDIR /app |
| 6 | +RUN cargo install cargo-chef --version 0.1.73 |
| 7 | +COPY . . |
| 8 | +RUN cargo chef prepare --recipe-path recipe.json |
| 9 | + |
| 10 | +# Stage 1: Cacher - Build dependencies only |
| 11 | +FROM docker.io/rust:1.90.0-slim-bookworm AS cacher |
| 12 | +WORKDIR /app |
4 | 13 | RUN apt-get update && apt-get install -y \ |
5 | | - protobuf-compiler fuse3 libfuse3-dev \ |
| 14 | + pkg-config=1.8.1-1 \ |
| 15 | + libssl-dev=3.0.17-1~deb12u3 \ |
| 16 | + protobuf-compiler=3.21.12-3 \ |
| 17 | + fuse3=3.14.0-4 \ |
| 18 | + libfuse3-dev=3.14.0-4 \ |
6 | 19 | && rm -rf /var/lib/apt/lists/* |
| 20 | +RUN cargo install cargo-chef --version 0.1.73 |
| 21 | +COPY --from=planner /app/recipe.json recipe.json |
| 22 | +# This layer is cached until Cargo.toml/Cargo.lock change |
| 23 | +RUN cargo chef cook --release --locked --features logrotate_fs --recipe-path recipe.json |
7 | 24 |
|
| 25 | +# Stage 2: Builder - Build source code |
| 26 | +FROM docker.io/rust:1.90.0-slim-bookworm AS builder |
8 | 27 | WORKDIR /app |
9 | | -COPY . /app |
| 28 | +RUN apt-get update && apt-get install -y \ |
| 29 | + pkg-config=1.8.1-1 \ |
| 30 | + libssl-dev=3.0.17-1~deb12u3 \ |
| 31 | + protobuf-compiler=3.21.12-3 \ |
| 32 | + fuse3=3.14.0-4 \ |
| 33 | + libfuse3-dev=3.14.0-4 \ |
| 34 | + && rm -rf /var/lib/apt/lists/* |
| 35 | +# Copy cached dependencies |
| 36 | +COPY --from=cacher /app/target target |
| 37 | +COPY --from=cacher /usr/local/cargo /usr/local/cargo |
| 38 | +# Copy source code (frequently changes) |
| 39 | +COPY . . |
| 40 | +# Build binary - reuses cached dependencies |
10 | 41 | RUN cargo build --release --locked --bin lading --features logrotate_fs |
11 | 42 |
|
| 43 | +# Stage 3: Runtime |
12 | 44 | FROM docker.io/debian:bookworm-20241202-slim |
13 | | -RUN apt-get update && apt-get install -y libfuse3-dev=3.14.0-4 fuse3=3.14.0-4 && rm -rf /var/lib/apt/lists/* |
| 45 | +RUN apt-get update && apt-get install -y \ |
| 46 | + libfuse3-dev=3.14.0-4 \ |
| 47 | + fuse3=3.14.0-4 \ |
| 48 | + && rm -rf /var/lib/apt/lists/* |
14 | 49 | COPY --from=builder /app/target/release/lading /usr/bin/lading |
15 | 50 |
|
16 | | -# smoke test |
| 51 | +# Smoke test |
17 | 52 | RUN ["/usr/bin/lading", "--help"] |
18 | 53 | ENTRYPOINT ["/usr/bin/lading"] |
0 commit comments