|
14 | 14 | # limitations under the License. |
15 | 15 |
|
16 | 16 |
|
17 | | -# Prep: |
| 17 | + |
| 18 | +# Multi-arch Bazel test image for Proxy-Wasm |
| 19 | +# |
| 20 | +# Preparation: |
18 | 21 | # docker run --rm --privileged tonistiigi/binfmt --install all |
19 | 22 | # 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-* |
21 | 24 | # |
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 . |
24 | 29 | # |
25 | | -# Push: |
| 30 | +# Push (optional): |
26 | 31 | # docker image tag $IMAGE ghcr.io/proxy-wasm/$IMAGE |
27 | 32 | # docker push ghcr.io/proxy-wasm/$IMAGE |
28 | 33 | # |
|
32 | 37 | # bazel test --verbose_failures --test_output=errors \ |
33 | 38 | # --define engine=null --config=clang --test_timeout=1800 \ |
34 | 39 | # -- //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. |
35 | 44 |
|
36 | | -# Update base image |
| 45 | +ARG BAZEL_VERSION=7.7.1 |
37 | 46 | 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"] |
42 | 47 |
|
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 | +" |
44 | 60 | 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 |
48 | 70 |
|
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\ |
62 | 79 | " |
63 | | -# Install all build dependencies (no PPA needed on Ubuntu 24.04) |
64 | 80 | 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/* |
77 | 83 |
|
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 |
85 | 86 |
|
86 | | -# Ensure a valid working directory after build |
| 87 | +# Set a valid working directory |
87 | 88 | WORKDIR /root |
0 commit comments