Skip to content

Commit b7e74ed

Browse files
committed
Make Bazel Dockerfile multi‑arch; compile Bazel from source (Ubuntu 24.04, JDK 21)
Signed-off-by: Matthieu MOREL <[email protected]>
1 parent 78526e8 commit b7e74ed

File tree

2 files changed

+68
-45
lines changed

2 files changed

+68
-45
lines changed

bazel/external/Dockerfile.bazel

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
# Need to see "F" flag: cat /proc/sys/fs/binfmt_misc/qemu-*
2121
#
2222
# Build:
23-
# docker buildx build --platform linux/s390x -t $IMAGE -f Dockerfile.bazel
23+
# docker buildx build --platform linux/s390x -t $IMAGE -f Dockerfile.bazel .
2424
#
2525
# Push:
2626
# docker image tag $IMAGE ghcr.io/proxy-wasm/$IMAGE
@@ -33,55 +33,54 @@
3333
# --define engine=null --config=clang --test_timeout=1800 \
3434
# -- //test/...
3535

36-
# Update base image
37-
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"]
36+
ARG BAZEL_VERSION=7.7.1
37+
ARG UBUNTU_VERSION=22.04
4238

43-
# Consolidated system update/upgrade and autoremove
39+
# Stage 1: build Bazel from release for the target platform
40+
FROM ubuntu:${UBUNTU_VERSION} AS bazel-builder
41+
WORKDIR /tmp
42+
ARG BAZEL_VERSION
43+
ARG DEPS_BUILDER="\
44+
build-essential \
45+
ca-certificates \
46+
curl \
47+
git \
48+
openjdk-21-jdk \
49+
python3 \
50+
unzip \
51+
wget \
52+
zip\
53+
"
4454
RUN apt-get update && \
45-
apt-get upgrade -y && \
46-
apt-get autoremove -y && \
47-
rm -rf /var/lib/apt/lists/*
55+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS_BUILDER && \
56+
mkdir -p /tmp/src/bazel && \
57+
wget --progress=dot:giga -O /tmp/bazel-dist.zip https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip && \
58+
unzip /tmp/bazel-dist.zip -d /tmp/src/bazel && \
59+
rm /tmp/bazel-dist.zip
60+
WORKDIR /tmp/src/bazel
61+
# Patch MODULE.bazel to force bazel_features v1.26.0 (avoids bzlmod macro requirement during bootstrap)
62+
COPY bazel/external/bazel-v7.7.1.patch /tmp/bazel-v7.7.1.patch
63+
RUN git apply /tmp/bazel-v7.7.1.patch
64+
RUN EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh && \
65+
cp /tmp/src/bazel/output/bazel /tmp/bazel && \
66+
chmod +x /tmp/bazel && \
67+
rm -rf /tmp/src/bazel /tmp/bazel-v7.7.1.patch
4868

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\
69+
# Stage 2: minimal runtime for executing tests
70+
FROM ubuntu:${UBUNTU_VERSION} AS test-runtime
71+
ARG DEPS_RUNTIME="\
72+
ca-certificates \
73+
openjdk-21-jre-headless \
74+
python3 \
75+
unzip \
76+
zip\
6277
"
63-
# Install all build dependencies (no PPA needed on Ubuntu 24.04)
6478
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
79+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS_RUNTIME && \
80+
rm -rf /var/lib/apt/lists/*
7781

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
82+
# Copy Bazel binary from builder
83+
COPY --from=bazel-builder /tmp/bazel /usr/bin/bazel
8584

86-
# Ensure a valid working directory after build
85+
# Set a valid working directory
8786
WORKDIR /root

bazel/external/bazel-v7.7.1.patch

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2+
From: Bazel Build <[email protected]>
3+
Date: Sat, 28 Dec 2025 00:00:00 +0000
4+
Subject: [PATCH] Force bazel_features to v1.26.0 to avoid bzlmod macro
5+
requirement during bootstrap
6+
7+
---
8+
MODULE.bazel | 1 +
9+
1 file changed, 1 insertion(+)
10+
11+
diff --git a/MODULE.bazel b/MODULE.bazel
12+
index 1234567890ab..fedcba098765 100644
13+
--- a/MODULE.bazel
14+
+++ b/MODULE.bazel
15+
@@ -5,6 +5,7 @@ module(
16+
)
17+
18+
bazel_dep(name = "bazel_skylib", version = "1.7.1")
19+
+bazel_dep(name = "bazel_features", version = "1.26.0")
20+
bazel_dep(name = "platforms", version = "0.0.10")
21+
bazel_dep(name = "rules_license", version = "0.0.8")
22+
bazel_dep(name = "rules_pkg", version = "0.10.1")
23+
--
24+
2.47.1

0 commit comments

Comments
 (0)