|
20 | 20 | # Need to see "F" flag: cat /proc/sys/fs/binfmt_misc/qemu-* |
21 | 21 | # |
22 | 22 | # 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 . |
24 | 24 | # |
25 | 25 | # Push: |
26 | 26 | # docker image tag $IMAGE ghcr.io/proxy-wasm/$IMAGE |
|
33 | 33 | # --define engine=null --config=clang --test_timeout=1800 \ |
34 | 34 | # -- //test/... |
35 | 35 |
|
36 | | -# Update base image |
| 36 | +ARG BAZEL_VERSION=7.7.1 |
37 | 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"] |
42 | 38 |
|
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 | +" |
44 | 54 | 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 | +RUN EXTRA_BAZEL_ARGS="--tool_java_runtime_version=local_jdk --experimental_enable_bzlmod_starlark_macro" bash ./compile.sh && \ |
| 62 | + cp /tmp/src/bazel/output/bazel /tmp/bazel && \ |
| 63 | + chmod +x /tmp/bazel && \ |
| 64 | + rm -rf /tmp/src/bazel |
48 | 65 |
|
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\ |
| 66 | +# Stage 2: minimal runtime for executing tests |
| 67 | +FROM ubuntu:${UBUNTU_VERSION} AS test-runtime |
| 68 | +ARG DEPS_RUNTIME="\ |
| 69 | + ca-certificates \ |
| 70 | + openjdk-21-jre-headless \ |
| 71 | + python3 \ |
| 72 | + unzip \ |
| 73 | + zip\ |
62 | 74 | " |
63 | | -# Install all build dependencies (no PPA needed on Ubuntu 24.04) |
64 | 75 | 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 |
| 76 | + DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends $DEPS_RUNTIME && \ |
| 77 | + rm -rf /var/lib/apt/lists/* |
77 | 78 |
|
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 |
| 79 | +# Copy Bazel binary from builder |
| 80 | +COPY --from=bazel-builder /tmp/bazel /usr/bin/bazel |
85 | 81 |
|
86 | | -# Ensure a valid working directory after build |
| 82 | +# Set a valid working directory |
87 | 83 | WORKDIR /root |
0 commit comments