Skip to content

Commit f9dca65

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

File tree

1 file changed

+34
-44
lines changed

1 file changed

+34
-44
lines changed

bazel/external/Dockerfile.bazel

Lines changed: 34 additions & 44 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,45 @@
3333
# --define engine=null --config=clang --test_timeout=1800 \
3434
# -- //test/...
3535

36-
# Update base image
36+
ARG BAZEL_VERSION=7.7.1
3737
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"]
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+
ca-certificates \
45+
curl \
46+
unzip \
47+
wget\
48+
"
4449
RUN apt-get update && \
45-
apt-get upgrade -y && \
46-
apt-get autoremove -y && \
47-
rm -rf /var/lib/apt/lists/*
50+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS_BUILDER openjdk-21-jdk build-essential python3 zip && \
51+
wget -O /tmp/bazel-dist.zip https://github.com/bazelbuild/bazel/releases/download/${BAZEL_VERSION}/bazel-${BAZEL_VERSION}-dist.zip && \
52+
mkdir -p /tmp/bazel-src && \
53+
unzip /tmp/bazel-dist.zip -d /tmp/bazel-src && \
54+
cd /tmp/bazel-src && \
55+
EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk" bash ./compile.sh && \
56+
cp /tmp/bazel-src/output/bazel /tmp/bazel && \
57+
chmod +x /tmp/bazel && \
58+
rm -rf /tmp/bazel-dist.zip /tmp/bazel-src
4859

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\
60+
# Stage 2: minimal runtime for executing tests
61+
FROM ubuntu:${UBUNTU_VERSION} AS test-runtime
62+
ARG DEPS_RUNTIME="\
63+
ca-certificates \
64+
openjdk-21-jre-headless \
65+
python3 \
66+
unzip \
67+
zip\
6268
"
63-
# Install all build dependencies (no PPA needed on Ubuntu 24.04)
6469
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
70+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS_RUNTIME && \
71+
rm -rf /var/lib/apt/lists/*
7772

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
73+
# Copy Bazel binary from builder
74+
COPY --from=bazel-builder /tmp/bazel /usr/bin/bazel
8575

86-
# Ensure a valid working directory after build
76+
# Set a valid working directory
8777
WORKDIR /root

0 commit comments

Comments
 (0)