@@ -2,7 +2,7 @@ ARG RUST_VERSION=1
22ARG FEATURES
33ARG BUILD=false
44
5- FROM docker.io/rust:${RUST_VERSION}-slim-trixie
5+ FROM docker.io/rust:${RUST_VERSION}-slim-trixie AS base
66
77COPY scripts/environment/install-debian-build-deps.sh /
88RUN bash /install-debian-build-deps.sh
@@ -19,15 +19,19 @@ COPY rust-toolchain.toml .
1919RUN bash /prepare.sh --modules=cargo-nextest,cargo-llvm-cov
2020RUN bash /install-protoc.sh
2121
22+ FROM base AS build-false
23+
24+ FROM base AS build-true
2225COPY . .
2326ARG FEATURES
24- ARG BUILD
25-
2627RUN --mount=type=cache,target=/vector/target \
2728 --mount=type=cache,target=/usr/local/cargo/registry \
2829 --mount=type=cache,target=/usr/local/cargo/git \
29- if [ "$BUILD" = "true" ]; then \
30- /usr/bin/mold -run cargo build --tests --lib --bin vector \
31- --no-default-features --features $FEATURES && \
32- cp target/debug/vector /usr/bin/vector; \
33- fi
30+ /usr/bin/mold -run cargo build --tests --lib --bin vector \
31+ --no-default-features --features $FEATURES && \
32+ cp target/debug/vector /usr/bin/vector
33+
34+ # BuildKit conditional stage selection: selects build-false (lean, no source) or
35+ # build-true (full source + compiled binary) based on the BUILD arg.
36+ # https://www.docker.com/blog/advanced-dockerfiles-faster-builds-and-smaller-images-using-buildkit-and-multistage-builds/
37+ FROM build-${BUILD}
0 commit comments