Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,20 @@ 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
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 }}
Expand Down Expand Up @@ -151,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
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/zookeeper-images.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 10 additions & 4 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# syntax=docker/dockerfile:1
# check=skip=InvalidDefaultArgInFrom
#
# Copyright (c) 2018 Dell Inc., or its subsidiaries. All Rights Reserved.
Expand All @@ -9,22 +10,27 @@
# 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`.
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

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/
Expand All @@ -34,7 +40,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"
Expand Down
40 changes: 28 additions & 12 deletions docker/zookeeper-image/Dockerfile
Original file line number Diff line number Diff line change
@@ -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; \
Expand All @@ -8,37 +14,47 @@ 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}" ;; \
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; \
\
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"; \
Expand Down Expand Up @@ -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"
Expand Down
69 changes: 69 additions & 0 deletions docker/zookeeper-image/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Apache ZooKeeper base image

Build from the repository root:

```bash
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 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 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`).

For example, add these options to the build command:

```bash
--build-arg java_download_base_url=https://jdk.example.com/java \
--build-arg java_version=21 \
--build-arg java_download_version=21.0.13.1
```

This requests `/java/21/jdk-21.0.13.1_linux-<arch>_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.

## 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 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.
Direct Gradle builds, including `./gradlew build --no-daemon`, read the
default from the same base Dockerfile. An explicit `-PjavaVersion=<major>`
overrides that target when needed.
14 changes: 11 additions & 3 deletions docker/zu/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,17 @@ repositories {
mavenCentral()
}

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.VERSION_25
targetCompatibility = JavaVersion.VERSION_25
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
}

val zookeeperVersion = "3.9.7"
Expand All @@ -36,6 +44,6 @@ tasks.withType<ShadowJar>() {

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_25)
jvmTarget.set(JvmTarget.fromTarget(javaVersion.majorVersion))
}
}
94 changes: 94 additions & 0 deletions scripts/test_zookeeper_version.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import hashlib
import json
import os
from pathlib import Path
Expand All @@ -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",
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
)[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=major, 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",
major="21", version="21.0.13.1", api_key=key,
)
self.assertEqual(result.returncode, 0, result.stderr)
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:
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()
Expand Down
Loading
Loading