From 9d3330b1f153965a800a11150b62db21b177eeae Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Wed, 18 Nov 2026 12:22:56 +0100 Subject: [PATCH 1/4] feat(docker): support alternate authenticated JDK downloads Port alternate Java download sources and optional BuildKit-secret authentication from adobe/koperator#403. Upgrade the ZooKeeper base image to Debian Trixie while retaining Oracle and Java 25 defaults. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/release.yml | 7 +++ docker/zookeeper-image/Dockerfile | 40 +++++++++---- docker/zookeeper-image/README.md | 48 ++++++++++++++++ scripts/test_zookeeper_version.py | 94 +++++++++++++++++++++++++++++++ 4 files changed, 177 insertions(+), 12 deletions(-) create mode 100644 docker/zookeeper-image/README.md diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e191b813..324dcbb3 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -123,6 +123,13 @@ jobs: uses: docker/build-push-action@v7 with: context: docker/zookeeper-image + # Enable these together when selecting an alternate JDK release: + # secrets: | + # JAVA_DOWNLOAD_APIKEY=${{ secrets.JAVA_DOWNLOAD_APIKEY }} + # Add these overrides under build-args: + # java_version=25 + # java_download_base_url=${{ secrets.JAVA_DOWNLOAD_BASE_URL }} + # java_download_version=25.0.1.1 platforms: linux/amd64,linux/arm64 build-args: | ZK_VERSION=${{ needs.prepare.outputs.zk_version }} diff --git a/docker/zookeeper-image/Dockerfile b/docker/zookeeper-image/Dockerfile index eddefd9c..5c544ade 100644 --- a/docker/zookeeper-image/Dockerfile +++ b/docker/zookeeper-image/Dockerfile @@ -1,5 +1,11 @@ +# syntax=docker/dockerfile:1 + # backported from https://github.com/docker-library/openjdk/blob/4c2b1a57869e24c5fcfbea6a17e558c710d4f6bd/21/jdk/slim-bullseye/Dockerfile -FROM debian:bookworm-slim +FROM debian:trixie-slim + +ARG java_version=25 +ARG java_download_version=${java_version} +ARG java_download_base_url=https://download.oracle.com/java RUN set -eux; \ apt-get update; \ @@ -8,24 +14,30 @@ RUN set -eux; \ ; \ rm -rf /var/lib/apt/lists/* -ENV JAVA_HOME=/usr/local/openjdk-25 +ENV JAVA_HOME=/usr/local/openjdk-${java_version} ENV PATH=$JAVA_HOME/bin:$PATH # Default to UTF-8 file.encoding ENV LANG=C.UTF-8 -ENV JAVA_VERSION=25 +ENV JAVA_VERSION=${java_version} -RUN set -eux; \ +RUN --mount=type=secret,id=JAVA_DOWNLOAD_APIKEY,env=JAVA_DOWNLOAD_APIKEY \ + set -eux; \ + \ + case "$java_download_base_url" in \ + https://download.oracle.com/*) java_download_base_url="${java_download_base_url}/${java_version}/latest" ;; \ + *) java_download_base_url="${java_download_base_url}/${java_version}/${java_download_version}" ;; \ + esac; \ \ arch="$(dpkg --print-architecture)"; \ case "$arch" in \ 'amd64') \ - downloadUrl='https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.tar.gz'; \ - downloadSha256='https://download.oracle.com/java/25/latest/jdk-25_linux-x64_bin.tar.gz.sha256'; \ + downloadUrl="${java_download_base_url}/jdk-${java_download_version}_linux-x64_bin.tar.gz"; \ + downloadSha256="${downloadUrl}.sha256"; \ ;; \ 'arm64') \ - downloadUrl='https://download.oracle.com/java/25/latest/jdk-25_linux-aarch64_bin.tar.gz'; \ - downloadSha256='https://download.oracle.com/java/25/latest/jdk-25_linux-aarch64_bin.tar.gz.sha256'; \ + downloadUrl="${java_download_base_url}/jdk-${java_download_version}_linux-aarch64_bin.tar.gz"; \ + downloadSha256="${downloadUrl}.sha256"; \ ;; \ *) echo >&2 "error: unsupported architecture: '$arch'"; exit 1 ;; \ esac; \ @@ -33,12 +45,16 @@ RUN set -eux; \ savedAptMark="$(apt-mark showmanual)"; \ apt-get update; \ apt-get install -y --no-install-recommends \ - wget \ + curl \ ; \ rm -rf /var/lib/apt/lists/*; \ \ - wget --progress=dot:giga -O openjdk.tgz "$downloadUrl"; \ - SHA256=$(wget -qO- $downloadSha256) ; \ + set --; \ + if [ -n "${JAVA_DOWNLOAD_APIKEY:+set}" ]; then \ + set -- --variable '%JAVA_DOWNLOAD_APIKEY' --expand-header 'Authorization: Bearer {{JAVA_DOWNLOAD_APIKEY}}'; \ + fi; \ + curl --fail --location "$@" --output openjdk.tgz "$downloadUrl"; \ + SHA256="$(curl --fail --silent --show-error --location "$@" "$downloadSha256")"; \ echo "$SHA256 *openjdk.tgz" | sha256sum --strict --check -; \ \ mkdir -p "$JAVA_HOME"; \ @@ -162,7 +178,7 @@ ENV PATH=$PATH:/$DISTRO_NAME/bin \ # OCI standard labels LABEL org.opencontainers.image.title="Apache Zookeeper" -LABEL org.opencontainers.image.description="Apache Zookeeper ${ZK_VERSION} with OpenJDK 25" +LABEL org.opencontainers.image.description="Apache Zookeeper ${ZK_VERSION} with OpenJDK ${java_version}" LABEL org.opencontainers.image.source="https://github.com/adobe/zookeeper-operator" LABEL org.opencontainers.image.url="https://github.com/adobe/zookeeper-operator" LABEL org.opencontainers.image.documentation="https://github.com/adobe/zookeeper-operator" diff --git a/docker/zookeeper-image/README.md b/docker/zookeeper-image/README.md new file mode 100644 index 00000000..b0b8b88e --- /dev/null +++ b/docker/zookeeper-image/README.md @@ -0,0 +1,48 @@ +# Apache ZooKeeper base image + +Build from the repository root: + +```bash +docker buildx build \ + --build-arg ZK_VERSION="$(./scripts/zookeeper-version.sh)" \ + -t zookeeper-apache:local docker/zookeeper-image +``` + +The image uses Debian Trixie and Java 25. Oracle's public JDK download URL is +the default, without authentication. + +## Alternate JDK downloads + +Override `java_download_base_url` and `java_download_version` to use another +source. The Dockerfile appends `java_version` (default: `25`) and `latest` +for Oracle, or `java_version` and `java_download_version` for alternate +sources. Neither version belongs in the base URL. Alternate sources must +provide Oracle-style archive filenames and matching `.sha256` files for +each architecture (`x64` and `aarch64`). + +For example, add these options to the build command: + +```bash +--build-arg java_download_base_url=https://jdk.example.com/java \ +--build-arg java_download_version=25.0.1.1 +``` + +This requests `/java/25/25.0.1.1/jdk-25.0.1.1_linux-_bin.tar.gz` +and its `.sha256` file. Both downloads must succeed and the checksum must match. + +For authenticated downloads, pass an optional API key as a BuildKit secret: + +```bash +--secret id=JAVA_DOWNLOAD_APIKEY,env=JAVA_DOWNLOAD_APIKEY +``` + +The key is sent as an `Authorization: Bearer` header, is not stored in the +image, and is not forwarded to a different host on redirects. + +Release builds also default to Oracle. To use an alternate source, add the +commented overrides in `.github/workflows/release.yml` to the Apache ZooKeeper +build step's `build-args`, configure the GitHub Actions secret +`JAVA_DOWNLOAD_BASE_URL`, and select a matching `java_download_version`. +For authenticated downloads, also enable the commented `secrets` input and +configure `JAVA_DOWNLOAD_APIKEY`. PR image builds continue to use Oracle +without secrets. diff --git a/scripts/test_zookeeper_version.py b/scripts/test_zookeeper_version.py index fce0e6d4..c79a59d9 100644 --- a/scripts/test_zookeeper_version.py +++ b/scripts/test_zookeeper_version.py @@ -1,3 +1,4 @@ +import hashlib import json import os from pathlib import Path @@ -10,6 +11,99 @@ ROOT = Path(__file__).resolve().parents[1] +class JavaDownloadTest(unittest.TestCase): + def run_download(self, arch="amd64", base="https://download.oracle.com/java", + version="25", api_key=None, corrupt=False): + dockerfile = (ROOT / "docker/zookeeper-image/Dockerfile").read_text() + download = dockerfile.split("ENV JAVA_VERSION=", 1)[1].split( + "RUN ", 1 + )[1].split('mkdir -p "$JAVA_HOME"', 1)[0] + if download.startswith("--mount="): + download = download.split("\\\n", 1)[1] + download = download.replace("\\\n", "").rstrip() + "\n" + variables = {key: value for key, value in os.environ.items() + if key != "JAVA_DOWNLOAD_APIKEY"} + variables.update( + ARCH=arch, java_version="25", java_download_version=version, + java_download_base_url=base, + DOWNLOAD_SHA=hashlib.sha256( + b"wrong" if corrupt else b"artifact" + ).hexdigest(), + ) + if api_key is not None: + variables["JAVA_DOWNLOAD_APIKEY"] = api_key + with tempfile.TemporaryDirectory() as directory: + result = subprocess.run( + ["bash", "-ec", + 'dpkg() { printf "%s\\n" "$ARCH"; }\n' + 'apt-mark() { :; }\n' + 'apt-get() { :; }\n' + 'rm() { :; }\n' + 'wget() { return 99; }\n' + 'curl() {\n' + ' python3 -c \'import json, sys; ' + 'open("downloads.jsonl", "a").write(' + 'json.dumps(sys.argv[1:]) + "\\n")\' "$@"\n' + ' for url; do :; done\n' + ' case "$url" in\n' + ' *.sha256) printf "%s\\n" "$DOWNLOAD_SHA" ;;\n' + ' *) printf artifact > openjdk.tgz ;;\n' + ' esac\n' + '}\n' + download], + cwd=directory, env=variables, text=True, capture_output=True, + ) + log = Path(directory) / "downloads.jsonl" + calls = [json.loads(line) for line in log.read_text().splitlines() + ] if log.exists() else [] + return result, calls + + def test_oracle_defaults_preserve_both_architecture_urls(self): + for arch, name in (("amd64", "x64"), ("arm64", "aarch64")): + with self.subTest(arch=arch): + result, calls = self.run_download(arch=arch) + self.assertEqual(result.returncode, 0, result.stderr) + url = ("https://download.oracle.com/java/25/latest/" + f"jdk-25_linux-{name}_bin.tar.gz") + self.assertEqual([call[-1] for call in calls], + [url, url + ".sha256"]) + self.assertNotIn("--expand-header", calls[0]) + + def test_alternate_source_uses_patch_version_and_optional_authentication(self): + for arch, name in (("amd64", "x64"), ("arm64", "aarch64")): + for key in (None, "synthetic-download-key"): + with self.subTest(arch=arch, authenticated=key is not None): + result, calls = self.run_download( + arch=arch, base="https://jdk.example.test/java", + version="25.0.1.1", api_key=key, + ) + self.assertEqual(result.returncode, 0, result.stderr) + url = ("https://jdk.example.test/java/25/25.0.1.1/" + f"jdk-25.0.1.1_linux-{name}_bin.tar.gz") + self.assertEqual([call[-1] for call in calls], + [url, url + ".sha256"]) + for call in calls: + self.assertIn("--fail", call) + self.assertIn("--location", call) + self.assertEqual("--expand-header" in call, key is not None) + if key is not None: + self.assertIn("%JAVA_DOWNLOAD_APIKEY", call) + self.assertIn("Authorization: Bearer {{JAVA_DOWNLOAD_APIKEY}}", + call) + self.assertNotIn(key, " ".join(call)) + self.assertNotIn(key, result.stderr) + + def test_checksum_mismatch_stops_the_build(self): + result, _ = self.run_download(corrupt=True) + self.assertNotEqual(result.returncode, 0) + self.assertIn("FAILED", result.stdout) + + def test_unsupported_architecture_stops_before_downloading(self): + result, calls = self.run_download(arch="s390x") + self.assertNotEqual(result.returncode, 0) + self.assertIn("unsupported architecture", result.stderr) + self.assertEqual(calls, []) + + class ZookeeperDownloadTest(unittest.TestCase): def run_download(self, available_url, empty=False): dockerfile = (ROOT / "docker/zookeeper-image/Dockerfile").read_text() From 90bafb9f1490ab1283829e73fbf4b9e57d59313b Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Wed, 18 Nov 2026 12:55:59 +0100 Subject: [PATCH 2/4] fix(docker): support major-only JDK mirrors and Java 21 runtime Use the documented major-only layout for alternate JDK mirrors. Compile the zu helper to Java 21 bytecode while retaining JDK 25 as the builder and default runtime, and keep image descriptions accurate for alternate runtimes. Validated the complete amd64 image with authenticated Oracle JDK 21.0.13.1+4 downloads, ZooKeeper startup and live zu client access. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/release.yml | 7 +++---- docker/Dockerfile | 4 ++-- docker/zookeeper-image/Dockerfile | 2 +- docker/zookeeper-image/README.md | 29 ++++++++++++++++++++++------- docker/zu/build.gradle.kts | 6 +++--- scripts/test_zookeeper_version.py | 10 +++++----- 6 files changed, 36 insertions(+), 22 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 324dcbb3..740c9e13 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -115,9 +115,8 @@ jobs: type=raw,value=${{ needs.prepare.outputs.zk_version }}-apache-${{ needs.prepare.outputs.tag }} type=raw,value=${{ needs.prepare.outputs.zk_version }}-apache labels: | - org.opencontainers.image.description=Apache Zookeeper ${{ needs.prepare.outputs.zk_version }} with OpenJDK 25 - # Rebuilt on every release, so it also picks up the latest JDK 25 patch - # release and Debian security updates. + org.opencontainers.image.description=Apache Zookeeper ${{ needs.prepare.outputs.zk_version }} + # Rebuilt on every release with Debian security updates and the selected JDK. - name: Build and push zookeeper Apache image id: build-zk-apache uses: docker/build-push-action@v7 @@ -158,7 +157,7 @@ jobs: tags: | type=raw,value=${{ needs.prepare.outputs.zk_version }}-${{ needs.prepare.outputs.tag }} labels: | - org.opencontainers.image.description=Apache Zookeeper image build with java-25 + org.opencontainers.image.description=Apache Zookeeper image - name: Build and push zookeeper image id: build-zk uses: docker/build-push-action@v7 diff --git a/docker/Dockerfile b/docker/Dockerfile index 4f9f1c09..c67cd7bd 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -9,7 +9,7 @@ # http://www.apache.org/licenses/LICENSE-2.0 # -# Base Apache ZooKeeper + OpenJDK 25 image built from docker/zookeeper-image. +# Base Apache ZooKeeper + OpenJDK image built from docker/zookeeper-image. # It is not pinned here: the build-zookeeper release job builds that image # first and passes its digest in, so both always come from the same commit # and shared zookeeperVersion. For local builds use `make build-zk-image`. @@ -34,7 +34,7 @@ RUN apt-get -q update && \ # OCI standard labels LABEL org.opencontainers.image.title="Apache Zookeeper" -LABEL org.opencontainers.image.description="Apache Zookeeper image build with java-25" +LABEL org.opencontainers.image.description="Apache Zookeeper image build with java-${JAVA_VERSION}" LABEL org.opencontainers.image.source="https://github.com/adobe/zookeeper-operator" LABEL org.opencontainers.image.url="https://github.com/adobe/zookeeper-operator" LABEL org.opencontainers.image.documentation="https://github.com/adobe/zookeeper-operator" diff --git a/docker/zookeeper-image/Dockerfile b/docker/zookeeper-image/Dockerfile index 5c544ade..0465ae4c 100644 --- a/docker/zookeeper-image/Dockerfile +++ b/docker/zookeeper-image/Dockerfile @@ -26,7 +26,7 @@ RUN --mount=type=secret,id=JAVA_DOWNLOAD_APIKEY,env=JAVA_DOWNLOAD_APIKEY \ \ case "$java_download_base_url" in \ https://download.oracle.com/*) java_download_base_url="${java_download_base_url}/${java_version}/latest" ;; \ - *) java_download_base_url="${java_download_base_url}/${java_version}/${java_download_version}" ;; \ + *) java_download_base_url="${java_download_base_url}/${java_version}" ;; \ esac; \ \ arch="$(dpkg --print-architecture)"; \ diff --git a/docker/zookeeper-image/README.md b/docker/zookeeper-image/README.md index b0b8b88e..dd8a4d5e 100644 --- a/docker/zookeeper-image/README.md +++ b/docker/zookeeper-image/README.md @@ -3,20 +3,20 @@ Build from the repository root: ```bash -docker buildx build \ +docker buildx build --load \ --build-arg ZK_VERSION="$(./scripts/zookeeper-version.sh)" \ -t zookeeper-apache:local docker/zookeeper-image ``` -The image uses Debian Trixie and Java 25. Oracle's public JDK download URL is -the default, without authentication. +The image uses Debian Trixie and defaults to Java 25. Oracle's public JDK +download URL is the default, without authentication. ## Alternate JDK downloads Override `java_download_base_url` and `java_download_version` to use another source. The Dockerfile appends `java_version` (default: `25`) and `latest` -for Oracle, or `java_version` and `java_download_version` for alternate -sources. Neither version belongs in the base URL. Alternate sources must +for Oracle, or only `java_version` for alternate sources. Do not include +the Java-major directory in the base URL. Alternate sources must provide Oracle-style archive filenames and matching `.sha256` files for each architecture (`x64` and `aarch64`). @@ -24,10 +24,11 @@ For example, add these options to the build command: ```bash --build-arg java_download_base_url=https://jdk.example.com/java \ ---build-arg java_download_version=25.0.1.1 +--build-arg java_version=21 \ +--build-arg java_download_version=21.0.13.1 ``` -This requests `/java/25/25.0.1.1/jdk-25.0.1.1_linux-_bin.tar.gz` +This requests `/java/21/jdk-21.0.13.1_linux-_bin.tar.gz` and its `.sha256` file. Both downloads must succeed and the checksum must match. For authenticated downloads, pass an optional API key as a BuildKit secret: @@ -46,3 +47,17 @@ build step's `build-args`, configure the GitHub Actions secret For authenticated downloads, also enable the commented `secrets` input and configure `JAVA_DOWNLOAD_APIKEY`. PR image builds continue to use Oracle without secrets. + +## Full ZooKeeper image + +After building the base image above, build the operator-flavoured image: + +```bash +docker buildx build --load \ + --build-arg BASE_IMAGE=zookeeper-apache:local \ + -t zookeeper:local docker +``` + +The `zu` helper targets Java 21 bytecode, so the full image supports both +Java 21 and the default Java 25 runtime. The helper is built with JDK 25 +regardless of the runtime selected for the base image. diff --git a/docker/zu/build.gradle.kts b/docker/zu/build.gradle.kts index 9b2896b0..8f0c303f 100644 --- a/docker/zu/build.gradle.kts +++ b/docker/zu/build.gradle.kts @@ -12,8 +12,8 @@ repositories { } java { - sourceCompatibility = JavaVersion.VERSION_25 - targetCompatibility = JavaVersion.VERSION_25 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 } val zookeeperVersion = "3.9.7" @@ -36,6 +36,6 @@ tasks.withType() { tasks.withType { compilerOptions { - jvmTarget.set(JvmTarget.JVM_25) + jvmTarget.set(JvmTarget.JVM_21) } } diff --git a/scripts/test_zookeeper_version.py b/scripts/test_zookeeper_version.py index c79a59d9..dc483ae7 100644 --- a/scripts/test_zookeeper_version.py +++ b/scripts/test_zookeeper_version.py @@ -13,7 +13,7 @@ class JavaDownloadTest(unittest.TestCase): def run_download(self, arch="amd64", base="https://download.oracle.com/java", - version="25", api_key=None, corrupt=False): + major="25", version="25", api_key=None, corrupt=False): dockerfile = (ROOT / "docker/zookeeper-image/Dockerfile").read_text() download = dockerfile.split("ENV JAVA_VERSION=", 1)[1].split( "RUN ", 1 @@ -24,7 +24,7 @@ def run_download(self, arch="amd64", base="https://download.oracle.com/java", variables = {key: value for key, value in os.environ.items() if key != "JAVA_DOWNLOAD_APIKEY"} variables.update( - ARCH=arch, java_version="25", java_download_version=version, + ARCH=arch, java_version=major, java_download_version=version, java_download_base_url=base, DOWNLOAD_SHA=hashlib.sha256( b"wrong" if corrupt else b"artifact" @@ -74,11 +74,11 @@ def test_alternate_source_uses_patch_version_and_optional_authentication(self): with self.subTest(arch=arch, authenticated=key is not None): result, calls = self.run_download( arch=arch, base="https://jdk.example.test/java", - version="25.0.1.1", api_key=key, + major="21", version="21.0.13.1", api_key=key, ) self.assertEqual(result.returncode, 0, result.stderr) - url = ("https://jdk.example.test/java/25/25.0.1.1/" - f"jdk-25.0.1.1_linux-{name}_bin.tar.gz") + url = ("https://jdk.example.test/java/21/" + f"jdk-21.0.13.1_linux-{name}_bin.tar.gz") self.assertEqual([call[-1] for call in calls], [url, url + ".sha256"]) for call in calls: From 9a20f307bcdda5ad1d792856cb041a7e25aa99af Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Wed, 18 Nov 2026 13:30:23 +0100 Subject: [PATCH 3/4] refactor(docker): derive helper Java targets from the base image Keep java_version in the base Dockerfile as the single runtime setting. Read the selected base JDK release metadata in the native helper builder and use one Gradle property for Java source/target compatibility and the Kotlin JVM target. Verified full Java 21 and Java 25 image builds, matching helper bytecode versions, ZooKeeper startup and live helper operations; all 35 build-script tests pass. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- docker/Dockerfile | 10 ++++++-- docker/zookeeper-image/README.md | 11 ++++++--- docker/zu/build.gradle.kts | 8 ++++--- scripts/test_zu_runtime.py | 40 ++++++++++++++++++++++++++++++++ 4 files changed, 61 insertions(+), 8 deletions(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index c67cd7bd..4bdd8a04 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,3 +1,4 @@ +# syntax=docker/dockerfile:1 # check=skip=InvalidDefaultArgInFrom # # Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved. @@ -15,6 +16,8 @@ # and shared zookeeperVersion. For local builds use `make build-zk-image`. ARG BASE_IMAGE +FROM ${BASE_IMAGE} AS runtime + # zu.jar is architecture-independent bytecode, so build it once on the native # build platform instead of re-running Gradle under emulation for every target. FROM --platform=$BUILDPLATFORM gradle:jdk25 AS zu-builder @@ -22,9 +25,12 @@ FROM --platform=$BUILDPLATFORM gradle:jdk25 AS zu-builder RUN mkdir /zu COPY zu /zu WORKDIR /zu -RUN ./gradlew shadowJar --no-daemon +RUN --mount=type=bind,from=runtime,source=/usr/local,target=/runtime-java \ + java_version="$(sed -n 's/^JAVA_VERSION="\([0-9][0-9]*\).*/\1/p' /runtime-java/openjdk-*/release)" && \ + test -n "$java_version" && \ + ./gradlew -PjavaVersion="$java_version" shadowJar --no-daemon -FROM ${BASE_IMAGE} +FROM runtime COPY bin /usr/local/bin RUN chmod +x /usr/local/bin/* COPY --from=zu-builder /zu/build/libs/zu.jar /opt/libs/ diff --git a/docker/zookeeper-image/README.md b/docker/zookeeper-image/README.md index dd8a4d5e..ea970475 100644 --- a/docker/zookeeper-image/README.md +++ b/docker/zookeeper-image/README.md @@ -58,6 +58,11 @@ docker buildx build --load \ -t zookeeper:local docker ``` -The `zu` helper targets Java 21 bytecode, so the full image supports both -Java 21 and the default Java 25 runtime. The helper is built with JDK 25 -regardless of the runtime selected for the base image. +The full image reads the base image's JDK release metadata and uses its +Java major version for both Java and Kotlin compilation targets in `zu`. +Set `java_version` only when building the base image; no second version +argument is needed for the full image. + +The native Gradle builder uses JDK 25 independently of the selected runtime. +For direct Gradle builds, supply the target explicitly with +`./gradlew -PjavaVersion=21 shadowJar --no-daemon`. diff --git a/docker/zu/build.gradle.kts b/docker/zu/build.gradle.kts index 8f0c303f..df28a8af 100644 --- a/docker/zu/build.gradle.kts +++ b/docker/zu/build.gradle.kts @@ -11,9 +11,11 @@ repositories { mavenCentral() } +val javaVersion = JavaVersion.toVersion(providers.gradleProperty("javaVersion").get()) + java { - sourceCompatibility = JavaVersion.VERSION_21 - targetCompatibility = JavaVersion.VERSION_21 + sourceCompatibility = javaVersion + targetCompatibility = javaVersion } val zookeeperVersion = "3.9.7" @@ -36,6 +38,6 @@ tasks.withType() { tasks.withType { compilerOptions { - jvmTarget.set(JvmTarget.JVM_21) + jvmTarget.set(JvmTarget.fromTarget(javaVersion.majorVersion)) } } diff --git a/scripts/test_zu_runtime.py b/scripts/test_zu_runtime.py index 30b0f5df..3c481c6c 100644 --- a/scripts/test_zu_runtime.py +++ b/scripts/test_zu_runtime.py @@ -2,12 +2,52 @@ import os from pathlib import Path import subprocess +import tempfile import unittest ROOT = Path(__file__).resolve().parents[1] +class ZuJavaVersionTest(unittest.TestCase): + def run_build(self, release): + dockerfile = (ROOT / "docker/Dockerfile").read_text() + build = dockerfile.split("WORKDIR /zu\n", 1)[1].split( + "\nFROM ", 1 + )[0].strip().removeprefix("RUN ") + if build.startswith("--mount="): + build = build.split("\\\n", 1)[1] + with tempfile.TemporaryDirectory() as directory: + root = Path(directory) + jdk = root / "runtime-java/openjdk-selected" + jdk.mkdir(parents=True) + (jdk / "release").write_text(release) + gradle = root / "gradlew" + gradle.write_text('#!/bin/sh\nprintf "%s\\n" "$@"\n') + gradle.chmod(0o700) + return subprocess.run( + ["sh", "-ec", build.replace("\\\n", "").replace( + "/runtime-java", str(root / "runtime-java") + )], + cwd=root, text=True, capture_output=True, + ) + + def test_compilation_target_follows_base_image_jdk(self): + for release, major in (('JAVA_VERSION="21.0.13.1"\n', "21"), + ('JAVA_VERSION="25.0.5.1"\n', "25")): + with self.subTest(major=major): + result = self.run_build(release) + self.assertEqual(result.returncode, 0, result.stderr) + self.assertEqual(result.stdout.splitlines(), [ + f"-PjavaVersion={major}", "shadowJar", "--no-daemon", + ]) + + def test_missing_java_version_stops_before_gradle(self): + result = self.run_build('IMPLEMENTOR="Oracle Corporation"\n') + self.assertNotEqual(result.returncode, 0) + self.assertEqual(result.stdout, "") + + class ZuRuntimeTest(unittest.TestCase): def run_zu(self, env=None, java_body=None): variables = { From b56b2771c1424981e8c22cf4764d9790a751cfa3 Mon Sep 17 00:00:00 2001 From: Adi Muraru Date: Wed, 18 Nov 2026 13:45:34 +0100 Subject: [PATCH 4/4] fix(zu): restore bare Gradle builds using the central Java default Default javaVersion lazily from the base Dockerfile when no explicit Gradle property is supplied. This restores the CodeQL ./gradlew build command while retaining Java 25 as the shared runtime and compilation default. Docker builds continue to derive targets from the selected base image. Verified bare Gradle build, explicit Java 21 override, full Java 25 image/runtime smoke tests and 35 script regression tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .github/workflows/zookeeper-images.yaml | 2 +- docker/zookeeper-image/README.md | 5 +++-- docker/zu/build.gradle.kts | 8 +++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/.github/workflows/zookeeper-images.yaml b/.github/workflows/zookeeper-images.yaml index df3b8e1e..07b19e7c 100644 --- a/.github/workflows/zookeeper-images.yaml +++ b/.github/workflows/zookeeper-images.yaml @@ -87,7 +87,7 @@ jobs: run: | docker run --rm --entrypoint bash -e ZK_VERSION zookeeper:ci -ec ' java -version - java -XshowSettings:properties -version 2>&1 | grep -Eq "^[[:space:]]*java.specification.version = 25$" + java -XshowSettings:properties -version 2>&1 | grep -Eq "^[[:space:]]*java.specification.version = ${JAVA_VERSION}$" zkServer.sh version 2>/dev/null | tee /dev/stderr | grep -q "${ZK_VERSION}" test -s /opt/libs/zu.jar set +e diff --git a/docker/zookeeper-image/README.md b/docker/zookeeper-image/README.md index ea970475..0e440757 100644 --- a/docker/zookeeper-image/README.md +++ b/docker/zookeeper-image/README.md @@ -64,5 +64,6 @@ Set `java_version` only when building the base image; no second version argument is needed for the full image. The native Gradle builder uses JDK 25 independently of the selected runtime. -For direct Gradle builds, supply the target explicitly with -`./gradlew -PjavaVersion=21 shadowJar --no-daemon`. +Direct Gradle builds, including `./gradlew build --no-daemon`, read the +default from the same base Dockerfile. An explicit `-PjavaVersion=` +overrides that target when needed. diff --git a/docker/zu/build.gradle.kts b/docker/zu/build.gradle.kts index df28a8af..497fdafd 100644 --- a/docker/zu/build.gradle.kts +++ b/docker/zu/build.gradle.kts @@ -11,7 +11,13 @@ repositories { mavenCentral() } -val javaVersion = JavaVersion.toVersion(providers.gradleProperty("javaVersion").get()) +val javaVersion = JavaVersion.toVersion( + providers.gradleProperty("javaVersion").orElse(providers.provider { + file("../zookeeper-image/Dockerfile").readLines() + .single { it.startsWith("ARG java_version=") } + .substringAfter("=") + }).get() +) java { sourceCompatibility = javaVersion