Skip to content

Commit 3a0504b

Browse files
committed
Add multi-arch Bazel Dockerfile and remove s390x-specific Dockerfile
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 78526e8 commit 3a0504b

File tree

1 file changed

+49
-48
lines changed

1 file changed

+49
-48
lines changed

bazel/external/Dockerfile.bazel

Lines changed: 49 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,20 @@
1414
# limitations under the License.
1515

1616

17-
# Prep:
17+
18+
# Multi-arch Bazel test image for Proxy-Wasm
19+
#
20+
# Preparation:
1821
# docker run --rm --privileged tonistiigi/binfmt --install all
1922
# docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
20-
# Need to see "F" flag: cat /proc/sys/fs/binfmt_misc/qemu-*
23+
# # Check for "F" flag: cat /proc/sys/fs/binfmt_misc/qemu-*
2124
#
22-
# Build:
23-
# docker buildx build --platform linux/s390x -t $IMAGE -f Dockerfile.bazel
25+
# Build (example for s390x, amd64, arm64):
26+
# docker buildx build --platform linux/s390x -t $IMAGE -f Dockerfile.bazel .
27+
# docker buildx build --platform linux/amd64 -t $IMAGE -f Dockerfile.bazel .
28+
# docker buildx build --platform linux/arm64 -t $IMAGE -f Dockerfile.bazel .
2429
#
25-
# Push:
30+
# Push (optional):
2631
# docker image tag $IMAGE ghcr.io/proxy-wasm/$IMAGE
2732
# docker push ghcr.io/proxy-wasm/$IMAGE
2833
#
@@ -32,56 +37,52 @@
3237
# bazel test --verbose_failures --test_output=errors \
3338
# --define engine=null --config=clang --test_timeout=1800 \
3439
# -- //test/...
40+
#
41+
# Notes:
42+
# - TARGETARCH and TARGETOS are set automatically by Docker buildx when using --platform.
43+
# - The first stage downloads the official Bazel binary for the target platform.
3544

36-
# Update base image
45+
ARG BAZEL_VERSION=7.7.1
3746
ARG UBUNTU_VERSION=24.04
38-
FROM ubuntu:${UBUNTU_VERSION} AS build
39-
40-
# Use bash for all RUN instructions
41-
SHELL ["/bin/bash", "-c"]
4247

43-
# Consolidated system update/upgrade and autoremove
48+
# Stage 1: build Bazel from release for the target platform
49+
FROM ubuntu:${UBUNTU_VERSION} AS bazel-builder
50+
WORKDIR /tmp
51+
ARG BAZEL_VERSION
52+
ARG TARGETARCH
53+
ARG TARGETOS
54+
ARG DEPS_BUILDER="\
55+
ca-certificates \
56+
curl \
57+
unzip \
58+
wget\
59+
"
4460
RUN apt-get update && \
45-
apt-get upgrade -y && \
46-
apt-get autoremove -y && \
47-
rm -rf /var/lib/apt/lists/*
61+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS_BUILDER openjdk-21-jdk build-essential python3 zip && \
62+
wget -O /tmp/bazel-dist.zip https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip && \
63+
mkdir -p /tmp/bazel-src && \
64+
unzip /tmp/bazel-dist.zip -d /tmp/bazel-src && \
65+
cd /tmp/bazel-src && \
66+
EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh && \
67+
cp /tmp/bazel-src/output/bazel /tmp/bazel && \
68+
chmod +x /tmp/bazel && \
69+
rm -rf /tmp/bazel-dist.zip /tmp/bazel-src
4870

49-
## All build dependencies for Bazel and ProxyWasm are listed in DEPS for clarity and maintainability.
50-
ARG DEPS="\
51-
build-essential \
52-
clang \
53-
curl \
54-
git \
55-
libssl-dev \
56-
libstdc++6 \
57-
libz-dev \
58-
openjdk-21-jdk \
59-
python3 \
60-
unzip \
61-
zip\
71+
# Stage 2: minimal runtime for executing tests
72+
FROM ubuntu:${UBUNTU_VERSION} AS test-runtime
73+
ARG DEPS_RUNTIME="\
74+
ca-certificates \
75+
openjdk-21-jre-headless \
76+
python3 \
77+
unzip \
78+
zip\
6279
"
63-
# Install all build dependencies (no PPA needed on Ubuntu 24.04)
6480
RUN apt-get update && \
65-
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS && \
66-
rm -rf /var/lib/apt/lists/*
67-
68-
# Set working directory for Bazel build
69-
WORKDIR /root/bazel
70-
71-
72-
# Download Bazel source and remove zip immediately after extraction
73-
ARG BAZEL_VERSION=7.7.1
74-
RUN curl -LO https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip && \
75-
unzip -q bazel-${BAZEL_VERSION}-dist.zip && \
76-
rm -f bazel-${BAZEL_VERSION}-dist.zip
81+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS_RUNTIME && \
82+
rm -rf /var/lib/apt/lists/*
7783

78-
## Build Bazel and copy the binary
79-
# NOTE: This step is flaky and may hang for multiarch/buildx.
80-
# If it takes more than 2 hours, restart the Docker build.
81-
ENV EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk"
82-
RUN ./compile.sh && \
83-
mv /output/bazel /usr/bin/bazel && \
84-
rm -rf /root/bazel
84+
# Copy Bazel binary from builder
85+
COPY --from=bazel-builder /tmp/bazel /usr/local/bin/bazel
8586

86-
# Ensure a valid working directory after build
87+
# Set a valid working directory
8788
WORKDIR /root

0 commit comments

Comments
 (0)