1+ # Copied from https://github.com/kubernetes-sigs/blixt/blob
2+
3+
4+ FROM rust:1.79-slim-bookworm as builder
5+
6+ ARG TARGETARCH
7+ ARG LLVM_VERSION=19
8+
9+ RUN apt-get update
10+ RUN apt-get install --yes \
11+ build-essential \
12+ protobuf-compiler \
13+ pkg-config \
14+ musl-tools \
15+ clang \
16+ wget
17+
18+ RUN apt install --yes lsb-release software-properties-common gnupg
19+ RUN wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh
20+ RUN chmod +x /tmp/llvm.sh
21+ RUN /bin/sh -c "/tmp/llvm.sh ${LLVM_VERSION} all"
22+
23+ RUN rustup default stable
24+ RUN rustup install nightly
25+ RUN rustup component add rust-src --toolchain nightly
26+ RUN --mount=type=cache,target=/root/.cargo/registry \
27+ cargo install bpf-linker
28+
29+ WORKDIR /workspace
30+ # Docker uses the amd64/arm64 convention while Rust uses the x86_64/aarch64 convention.
31+ # Since Dockerfile doesn't support conditional variables (sigh), write the arch in Rust's
32+ # convention to a file for later usage.
33+ RUN if [ "$TARGETARCH" = "amd64" ]; \
34+ then echo "x86_64" >> arch; \
35+ else echo "aarch64" >> arch; \
36+ fi
37+ RUN rustup target add $(eval cat arch)-unknown-linux-musl
38+
39+ COPY dataplane dataplane
40+ COPY tools/udp-test-server tools/udp-test-server
41+ COPY xtask xtask
42+ COPY Cargo.toml Cargo.toml
43+ COPY Cargo.lock Cargo.lock
44+ COPY .cargo .cargo
45+
46+ # We need to tell bpf-linker where it can find LLVM's shared library file.
47+ # Ref: https://github.com/aya-rs/rustc-llvm-proxy/blob/cbcb3c6/src/lib.rs#L48
48+ ENV LD_LIBRARY_PATH="/usr/lib/llvm-$LLVM_VERSION/lib"
49+ ENV CC_aarch64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/clang"
50+ ENV AR_aarch64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/llvm-ar"
51+ ENV CC_x86_64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/clang"
52+ ENV AR_x86_64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/llvm-ar"
53+ ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"
54+
55+ RUN --mount=type=cache,target=/workspace/target/ \
56+ --mount=type=cache,target=/root/.cargo/registry \
57+ cargo xtask build-ebpf --release
58+ RUN --mount=type=cache,target=/workspace/target/ \
59+ --mount=type=cache,target=/root/.cargo/registry \
60+ RUSTFLAGS=-Ctarget-feature=+crt-static cargo build \
61+ --workspace \
62+ --exclude ebpf \
63+ --release \
64+ --target=$(eval cat arch)-unknown-linux-musl
65+ RUN --mount=type=cache,target=/workspace/target/ \
66+ cp /workspace/target/$(eval cat arch)-unknown-linux-musl/release/loader /workspace/dataplane-release
67+
68+ FROM alpine
69+
70+ LABEL org.opencontainers.image.source=https://github.com/kubernetes-sigs/blixt
71+ LABEL org.opencontainers.image.licenses=GPL-2.0-only,BSD-2-Clause
72+
73+ WORKDIR /opt/blixt/
74+
75+ COPY --from=builder /workspace/dataplane-release /opt/blixt/dataplane
76+
77+ COPY dataplane/LICENSE.GPL-2.0 /opt/blixt/LICENSE.GPL-2.0
78+ COPY dataplane/LICENSE.BSD-2-Clause /opt/blixt/LICENSE.BSD-2-Clause
79+
80+ ENTRYPOINT ["/opt/blixt/dataplane" ]
0 commit comments