Skip to content

Commit

Permalink
fix dataplane and udp server builds on arm64 (#261)
Browse files Browse the repository at this point in the history
  • Loading branch information
k8s-ci-robot authored Dec 2, 2024
2 parents 6f902e5 + 73032fe commit 427839a
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 9 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,36 @@ jobs:
- name: Run Tests
run: |
make test
docker-build:
name: docker-build
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- uses: dorny/paths-filter@v3
id: filter
with:
filters: |
dataplane:
- 'dataplane/**'
containerfile:
- 'build/Containerfile.dataplane'
- name: Setup QEMU
if: steps.filter.outputs.dataplane || steps.filter.outputs.containerfile
uses: docker/setup-qemu-action@49b3bc8e6bdd4a60e6116a5414239cba5943d3cf # v3.2.0
- name: Setup Docker Buildx
if: steps.filter.outputs.dataplane || steps.filter.outputs.containerfile
id: buildx
uses: docker/setup-buildx-action@988b5a0280414f521da01fcc63a27aeeb4b104db # v3.6.1
with:
buildkitd-flags: "--debug"
- name: Build multi-arch container image
if: steps.filter.outputs.dataplane || steps.filter.outputs.containerfile
uses: docker/build-push-action@5cd11c3a4ced054e52742c5fd54dca954e0edd85 # v6.7.0
with:
push: false
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/amd64,linux/arm64
file: build/Containerfile.dataplane
tags: kong/blixt-dataplane:${{ github.head_ref }}-${{ github.sha }}
20 changes: 16 additions & 4 deletions build/Containerfile.dataplane
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
FROM rust:1.75-slim-bookworm AS builder
FROM rust:1.79-slim-bookworm as builder

ARG TARGETARCH
ARG LLVM_VERSION=19

RUN apt-get update
RUN apt-get install --yes \
build-essential \
protobuf-compiler \
pkg-config \
llvm-16 \
musl-tools
musl-tools \
clang \
wget

RUN apt install --yes lsb-release software-properties-common gnupg
RUN wget -O /tmp/llvm.sh https://apt.llvm.org/llvm.sh
RUN chmod +x /tmp/llvm.sh
RUN /bin/sh -c "/tmp/llvm.sh ${LLVM_VERSION} all"

RUN rustup default stable
RUN rustup install nightly
Expand All @@ -35,7 +42,12 @@ COPY .cargo .cargo

# We need to tell bpf-linker where it can find LLVM's shared library file.
# Ref: https://github.com/aya-rs/rustc-llvm-proxy/blob/cbcb3c6/src/lib.rs#L48
ENV LD_LIBRARY_PATH="/usr/lib/llvm-16/lib"
ENV LD_LIBRARY_PATH="/usr/lib/llvm-$LLVM_VERSION/lib"
ENV CC_aarch64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/clang"
ENV AR_aarch64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/llvm-ar"
ENV CC_x86_64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/clang"
ENV AR_x86_64_unknown_linux_musl="/usr/lib/llvm-$LLVM_VERSION/bin/llvm-ar"
ENV CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="-Clink-self-contained=yes -Clinker=rust-lld"

RUN --mount=type=cache,target=/workspace/target/ \
--mount=type=cache,target=/root/.cargo/registry \
Expand Down
18 changes: 14 additions & 4 deletions build/Containerfile.udp_server
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
FROM rust AS builder

ARG TARGETARCH

RUN apt-get update && \
apt-get install musl-tools -yq && \
rustup target add x86_64-unknown-linux-musl
apt-get install musl-tools -yq

WORKDIR /workspace

Expand All @@ -13,15 +14,24 @@ COPY tools/udp-test-server/Cargo.lock tools/udp-test-server/Cargo.lock
COPY tools/udp-test-server/src/main.rs tools/udp-test-server/src/main.rs
COPY xtask xtask

# Docker uses the amd64/arm64 convention while Rust uses the x86_64/aarch64 convention.
# Since Dockerfile doesn't support conditional variables (sigh), write the arch in Rust's
# convention to a file for later usage.
RUN if [ "$TARGETARCH" = "amd64" ]; \
then echo "x86_64" >> arch; \
else echo "aarch64" >> arch; \
fi
RUN rustup target add $(eval cat arch)-unknown-linux-musl

RUN --mount=type=cache,target=/workspace/target/ \
--mount=type=cache,target=/usr/local/cargo/registry/ \
RUSTFLAGS=-Ctarget-feature=+crt-static cargo build \
--package=udp-test-server \
--release \
--target=x86_64-unknown-linux-musl
--target=$(eval cat arch)-unknown-linux-musl

RUN --mount=type=cache,target=/workspace/target/ \
cp /workspace/target/x86_64-unknown-linux-musl/release/udp-test-server /workspace/udp-test-server
cp /workspace/target/$(eval cat arch)-unknown-linux-musl/release/udp-test-server /workspace/udp-test-server

FROM alpine

Expand Down
2 changes: 1 addition & 1 deletion dataplane/loader/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ async fn main() -> Result<(), anyhow::Error> {
"../../target/bpfel-unknown-none/debug/loader"
))?;
#[cfg(not(debug_assertions))]
let mut bpf = Ebpf::load(include_bytes_aligned!(
let mut bpf_program = Ebpf::load(include_bytes_aligned!(
"../../target/bpfel-unknown-none/release/loader"
))?;
if let Err(e) = EbpfLogger::init(&mut bpf_program) {
Expand Down

0 comments on commit 427839a

Please sign in to comment.