From 5d42c4dd83fcbd4d3eb95046f184fd2cd07291d8 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Tue, 24 Nov 2026 17:03:53 +0100 Subject: [PATCH 1/3] spike: hummingbird based operator image --- Makefile | 3 + hummingbird-spike/Dockerfile | 226 +++++++++++++++++++++++++++++++++++ tests/test-definition.yaml | 6 +- 3 files changed, 232 insertions(+), 3 deletions(-) create mode 100644 hummingbird-spike/Dockerfile diff --git a/Makefile b/Makefile index 08214405..e5ebf5f2 100644 --- a/Makefile +++ b/Makefile @@ -27,6 +27,9 @@ render-docs: docker-build: docker build --force-rm --build-arg VERSION=${VERSION} -t "${OCI_REGISTRY_HOSTNAME}/${OCI_REGISTRY_PROJECT_IMAGES}/${OPERATOR_NAME}:${VERSION}-${ARCH}" -f docker/Dockerfile . +docker-build-humm: + docker build --force-rm --build-arg VERSION=${VERSION} -t "${OCI_REGISTRY_HOSTNAME}/${OCI_REGISTRY_PROJECT_IMAGES}/${OPERATOR_NAME}:${VERSION}-${ARCH}-humm" -f hummingbird-spike/Dockerfile . + ## Chart related targets compile-chart: version crds crd-annotation diff --git a/hummingbird-spike/Dockerfile b/hummingbird-spike/Dockerfile new file mode 100644 index 00000000..10f9f0e6 --- /dev/null +++ b/hummingbird-spike/Dockerfile @@ -0,0 +1,226 @@ +# syntax=docker/dockerfile:1.16.0@sha256:e2dd261f92e4b763d789984f6eab84be66ab4f5f08052316d8eb8f173593acf7 +# NOTE: The syntax directive needs to be the first line in a Dockerfile + +# SPIKE: Stackable Operator for Apache ZooKeeper on Red Hat Hummingbird, without any UBI stage. +# +# +# Differences to docker/Dockerfile: +# - The `ubi10-rust-builder` and `ubi10-minimal` stages are replaced by a Hummingbird builder and by a +# root filesystem that is assembled with `dnf --installroot` from the Hummingbird RPM repo. +# - The final image is `FROM scratch`, the distroless Hummingbird runtime has no shell to run these steps in. +# - `nano` and `iputils` are left out, they are not in the Hummingbird repo (same as in the ZooKeeper spike). +# - `libkadm5` is left out, the operator only needs the Kerberos client libraries (`krb5-libs`). +# TODO: check that nothing needs it (the UBI image installs it). +# - The builder is `hi/rust:latest-builder`, which ships the Rust toolchain and dnf. Nothing here installs or pins Rust, so the +# image's Rust version must match rust-toolchain.toml (the build prints both, see the `builder` stage). +# +# Build from the repository root (the build context must be the repo root and contain `.git`, +# the `built` crate reads the commit hash from it): +# +# docker build -f hummingbird-spike/Dockerfile --build-arg VERSION=0.0.0-dev -t zookeeper-operator-hum:spike . +# +# Useful intermediate targets: builder, rootfs +# +# docker build -f hummingbird-spike/Dockerfile --target rootfs -t zk-op-hum-rootfs . + +# https://docs.docker.com/build/checks/#fail-build-on-check-violations +# check=error=true + +# TODO: pin both bases by digest, like the other Dockerfiles in this repo do +# The `-builder` variant of hi/rust. The plain `hi/rust:latest` has no dnf. The builder variants add +# bash, dnf5 and shadow-utils (default_rpm_packages.builder in the Hummingbird containers repo, +# images/variables.yml), on top of cargo, rust, git-core, make, glibc-devel and openssl-devel (images/rust/properties.yml). +ARG BUILDER_BASE=registry.access.redhat.com/hi/rust:latest-builder +# Used for the runtime root filesystem only, it only needs dnf and shadow-utils. The Rust toolchain in it is not used. +ARG ROOTFS_BASE=${BUILDER_BASE} + +# ============================================================================== +# builder: Hummingbird Rust image, builds the operator binary + +# We want to automatically use the latest. +# hadolint ignore=DL3007 +FROM ${BUILDER_BASE} AS builder + +ARG CARGO_AUDITABLE_CRATE_VERSION=0.7.7 + +# Build stage only, nothing from it is shipped as is. The final image is FROM scratch and +# runs as an unprivileged user. Root is needed for dnf and to create /src and /app. hi/rust already +# runs as root (`user: root` in its properties.yml), this makes it explicit. +# hadolint ignore=DL3002 +USER 0 +SHELL ["/bin/bash", "-euo", "pipefail", "-c"] + +# What the build needs on top of the image's cargo, rust, git-core, make and glibc-devel: +# - a C compiler: build scripts of `ring` and the vendored libgit2 (via `git2` in the `built` crate). +# hi/rust does not list gcc, so make sure it is there (a no-op if it already is). +# hadolint ignore=DL3041 +RUN dnf install --assumeyes gcc && dnf clean all + +WORKDIR /src +COPY . /src + +# The image's Rust must match what the repo pins, nothing else enforces that here +RUN <> /rootfs/stackable/.bashrc +printf 'if [ -f ~/.bashrc ]; then\n\tsource ~/.bashrc\nfi\n' >> /rootfs/stackable/.profile +EOF + +COPY < /rootfs/stackable/package_manifest.txt +chown -R ${STACKABLE_USER_UID}:0 /rootfs/stackable /rootfs/usr/local/bin +chmod -R g=u /rootfs/stackable +EOF + +# ============================================================================== +# FINAL OPERATOR IMAGE + +FROM scratch AS operator + +ARG VERSION +ARG RELEASE="1" +ARG TARGETARCH +ARG STACKABLE_USER_UID="782252253" + +COPY --from=rootfs /rootfs / + +# These labels have mostly been superseded by the OpenContainer spec annotations below but it doesn't hurt to include them +# http://label-schema.org/rc1/ +LABEL name="Stackable Operator for Apache ZooKeeper" +LABEL maintainer="info@stackable.tech" +LABEL vendor="Stackable GmbH" +LABEL version="${VERSION}" +# NOTE (@Techassi): This is required for OpenShift/Red Hat certification +# Keeping this as "1" seems to be fine since a couple of years /shrug +LABEL release="${RELEASE}" +LABEL summary="Deploy and manage Apache ZooKeeper clusters." +LABEL description="Deploy and manage Apache ZooKeeper clusters." +LABEL distribution-scope="public" +LABEL url="https://stackable.tech" +LABEL architecture="${TARGETARCH}" + +# https://github.com/opencontainers/image-spec/blob/64294bd7a2bf2537e1a6a34d687caae70300b0c4/annotations.md#annotations +LABEL org.opencontainers.image.authors="info@stackable.tech" +LABEL org.opencontainers.image.url="https://stackable.tech" +LABEL org.opencontainers.image.vendor="Stackable GmbH" +LABEL org.opencontainers.image.licenses="OSL-3.0" +LABEL org.opencontainers.image.documentation="https://docs.stackable.tech/home/stable/zookeeper/" +LABEL org.opencontainers.image.version="${VERSION}" +LABEL org.opencontainers.image.revision="${RELEASE}" +LABEL org.opencontainers.image.title="Stackable Operator for Apache ZooKeeper" +LABEL org.opencontainers.image.description="Deploy and manage Apache ZooKeeper clusters." + +# https://docs.openshift.com/container-platform/4.16/openshift_images/create-images.html#defining-image-metadata +LABEL io.openshift.tags="hummingbird,stackable,sdp,zookeeper" +LABEL io.k8s.description="Deploy and manage Apache ZooKeeper clusters." +LABEL io.k8s.display-name="Stackable Operator for Apache ZooKeeper" + +# C.UTF-8 is built into glibc >= 2.35, so no langpack is needed (the Hummingbird images +# set LANG=en_US.UTF-8 but do not ship that locale) +ENV LANG=C.UTF-8 +ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +ENV HOME=/stackable + +USER ${STACKABLE_USER_UID} + +ENTRYPOINT ["stackable-zookeeper-operator"] +CMD ["run"] diff --git a/tests/test-definition.yaml b/tests/test-definition.yaml index bcd5a455..5487b7b8 100644 --- a/tests/test-definition.yaml +++ b/tests/test-definition.yaml @@ -2,13 +2,13 @@ dimensions: - name: zookeeper values: - - 3.9.5 - - 3.9.6 + # - 3.9.5 + - 3.9.6,localhost/zookeeper-hum:spike # To use a custom image, add a comma and the full name after the product version # - x.x.x,oci.stackable.tech/sdp/zookeeper:x.x.x-stackable0.0.0-dev - name: zookeeper-latest values: - - 3.9.6 + - 3.9.6,localhost/zookeeper-hum:spike # To use a custom image, add a comma and the full name after the product version # - x.x.x,oci.stackable.tech/sdp/zookeeper:x.x.x-stackable0.0.0-dev - name: use-server-tls From 9b58589d37386769a2b37ae84ed0d70f5e2903cc Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Thu, 26 Nov 2026 16:00:15 +0100 Subject: [PATCH 2/3] Replace "scratch" with "hi/core-runtime" to pass OpenShift preflight checks --- hummingbird-spike/Dockerfile | 138 +++++++++++++---------------------- 1 file changed, 50 insertions(+), 88 deletions(-) diff --git a/hummingbird-spike/Dockerfile b/hummingbird-spike/Dockerfile index 10f9f0e6..58125b08 100644 --- a/hummingbird-spike/Dockerfile +++ b/hummingbird-spike/Dockerfile @@ -5,12 +5,19 @@ # # # Differences to docker/Dockerfile: -# - The `ubi10-rust-builder` and `ubi10-minimal` stages are replaced by a Hummingbird builder and by a -# root filesystem that is assembled with `dnf --installroot` from the Hummingbird RPM repo. -# - The final image is `FROM scratch`, the distroless Hummingbird runtime has no shell to run these steps in. -# - `nano` and `iputils` are left out, they are not in the Hummingbird repo (same as in the ZooKeeper spike). -# - `libkadm5` is left out, the operator only needs the Kerberos client libraries (`krb5-libs`). -# TODO: check that nothing needs it (the UBI image installs it). +# - The `ubi10-rust-builder` and `ubi10-minimal` stages are replaced by a Hummingbird builder and by +# a Hummingbird runtime image (`RUNTIME_BASE`, default `hi/core-runtime`). +# - The final image is built FROM the Hummingbird runtime image and only adds files on top of it. +# It is not `FROM scratch` and nothing is installed into it with dnf. Reason: the Red Hat certification check +# `BasedOnUbi` asks Red Hat Pyxis whether a certified image contains the layers of the image under test. A +# `FROM scratch` image with a single new layer is never found, even if its contents are the same RPMs. +# Installing RPMs on top of the base could also overwrite files the base layers own (check `HasModifiedFiles`). +# - No user is created. The image runs as a numeric UID without a passwd entry (works in Kubernetes and OpenShift), +# which avoids editing /etc/passwd and /etc/group, files that belong to RPMs of the base image. +# - Not part of the image (they were in the UBI image and in the previous `FROM scratch` version of this spike): +# bash profile and aliases, `nano`, `iputils`, `libkadm5`, `krb5-libs` and the other tools from `ubi10-minimal`. +# TODO: check that nothing needs them. The build prints the shared libraries the binary needs (see `additions`), +# compare them with what the runtime image provides. # - The builder is `hi/rust:latest-builder`, which ships the Rust toolchain and dnf. Nothing here installs or pins Rust, so the # image's Rust version must match rust-toolchain.toml (the build prints both, see the `builder` stage). # @@ -19,20 +26,30 @@ # # docker build -f hummingbird-spike/Dockerfile --build-arg VERSION=0.0.0-dev -t zookeeper-operator-hum:spike . # -# Useful intermediate targets: builder, rootfs +# To try another runtime base (it must be a glibc based, certified Hummingbird image): # -# docker build -f hummingbird-spike/Dockerfile --target rootfs -t zk-op-hum-rootfs . +# docker build -f hummingbird-spike/Dockerfile --build-arg VERSION=0.0.0-dev \ +# --build-arg RUNTIME_BASE=registry.access.redhat.com/hi/core-runtime: -t zookeeper-operator-hum:spike . +# +# Useful intermediate targets: builder, additions +# +# docker build -f hummingbird-spike/Dockerfile --target additions -t zk-op-hum-additions . # https://docs.docker.com/build/checks/#fail-build-on-check-violations # check=error=true -# TODO: pin both bases by digest, like the other Dockerfiles in this repo do +# TODO: pin the bases by digest, like the other Dockerfiles in this repo do # The `-builder` variant of hi/rust. The plain `hi/rust:latest` has no dnf. The builder variants add # bash, dnf5 and shadow-utils (default_rpm_packages.builder in the Hummingbird containers repo, # images/variables.yml), on top of cargo, rust, git-core, make, glibc-devel and openssl-devel (images/rust/properties.yml). ARG BUILDER_BASE=registry.access.redhat.com/hi/rust:latest-builder -# Used for the runtime root filesystem only, it only needs dnf and shadow-utils. The Rust toolchain in it is not used. +# Used for the `additions` stage only, it needs a shell, chown and ldd. The Rust toolchain in it is not used. ARG ROOTFS_BASE=${BUILDER_BASE} +# The base of the final image. The final image must share its layers, so this has to be an image that +# Red Hat certified (see the BasedOnUbi check of the preflight tool). It must be glibc based, the operator is +# dynamically linked. `hi/static` has no glibc. +# The binary is built against the glibc of BUILDER_BASE. Keep both bases on the same Hummingbird release. +ARG RUNTIME_BASE=registry.access.redhat.com/hi/core-runtime:latest # ============================================================================== # builder: Hummingbird Rust image, builds the operator binary @@ -43,8 +60,8 @@ FROM ${BUILDER_BASE} AS builder ARG CARGO_AUDITABLE_CRATE_VERSION=0.7.7 -# Build stage only, nothing from it is shipped as is. The final image is FROM scratch and -# runs as an unprivileged user. Root is needed for dnf and to create /src and /app. hi/rust already +# Build stage only, nothing from it is shipped as is. The final image runs as an unprivileged user. +# Root is needed for dnf and to create /src and /app. hi/rust already # runs as root (`user: root` in its properties.yml), this makes it explicit. # hadolint ignore=DL3002 USER 0 @@ -74,85 +91,25 @@ cp target/release/stackable-zookeeper-operator /app/ EOF # ============================================================================== -# rootfs: assembles the runtime filesystem from the Hummingbird RPM repo into /rootfs +# additions: collects the files that are added on top of the runtime base image into /additions # hadolint ignore=DL3006,DL3007 -FROM ${ROOTFS_BASE} AS rootfs +FROM ${ROOTFS_BASE} AS additions ARG VERSION -ARG RELEASE="1" -# These are chosen at random and are this high on purpose to have very little chance to clash with an existing user or group on the host system +# This is chosen at random and is this high on purpose to have very little chance to clash with an existing user on the host system # NOTE: Please also update default.nix accordingly! -ARG STACKABLE_USER_GID="574654813" +# There is no passwd entry for it in the image, the UID only has to be numeric and non-zero. ARG STACKABLE_USER_UID="782252253" -ARG STACKABLE_USER_NAME="stackable" # hadolint ignore=DL3002 USER 0 SHELL ["/bin/bash", "-euo", "pipefail", "-c"] -ENV HOME=/root -COPY <> /rootfs/stackable/.bashrc -printf 'if [ -f ~/.bashrc ]; then\n\tsource ~/.bashrc\nfi\n' >> /rootfs/stackable/.profile -EOF - -COPY < /rootfs/stackable/package_manifest.txt -chown -R ${STACKABLE_USER_UID}:0 /rootfs/stackable /rootfs/usr/local/bin -chmod -R g=u /rootfs/stackable +chown -R ${STACKABLE_USER_UID}:0 /additions/stackable /additions/usr/local/bin +chmod -R g=u /additions/stackable + +# The runtime base has to provide these. Compare them with the output of `ldd` in the runtime image +# (the shell-less runtime image cannot run it), a missing library shows up as a start failure of the operator. +echo "Shared libraries needed by the operator binary:" +ldd /additions/usr/local/bin/stackable-zookeeper-operator || true EOF # ============================================================================== # FINAL OPERATOR IMAGE -FROM scratch AS operator +# hadolint ignore=DL3006,DL3007 +FROM ${RUNTIME_BASE} AS operator ARG VERSION ARG RELEASE="1" ARG TARGETARCH ARG STACKABLE_USER_UID="782252253" -COPY --from=rootfs /rootfs / +COPY --from=additions /additions / # These labels have mostly been superseded by the OpenContainer spec annotations below but it doesn't hurt to include them # http://label-schema.org/rc1/ @@ -217,10 +179,10 @@ LABEL io.k8s.display-name="Stackable Operator for Apache ZooKeeper" # C.UTF-8 is built into glibc >= 2.35, so no langpack is needed (the Hummingbird images # set LANG=en_US.UTF-8 but do not ship that locale) ENV LANG=C.UTF-8 -ENV PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" +# PATH is left to the base image, the entrypoint below uses an absolute path. ENV HOME=/stackable USER ${STACKABLE_USER_UID} -ENTRYPOINT ["stackable-zookeeper-operator"] +ENTRYPOINT ["/usr/local/bin/stackable-zookeeper-operator"] CMD ["run"] From be4dee96d3546cfbf766ce1c692fdd7d713cefc0 Mon Sep 17 00:00:00 2001 From: Razvan-Daniel Mihai <84674+razvan@users.noreply.github.com> Date: Fri, 27 Nov 2026 10:25:24 +0100 Subject: [PATCH 3/3] refactor: drop the "additions" stage --- hummingbird-spike/Dockerfile | 90 ++++++++++++++---------------------- 1 file changed, 34 insertions(+), 56 deletions(-) diff --git a/hummingbird-spike/Dockerfile b/hummingbird-spike/Dockerfile index 58125b08..eaf156fe 100644 --- a/hummingbird-spike/Dockerfile +++ b/hummingbird-spike/Dockerfile @@ -8,16 +8,11 @@ # - The `ubi10-rust-builder` and `ubi10-minimal` stages are replaced by a Hummingbird builder and by # a Hummingbird runtime image (`RUNTIME_BASE`, default `hi/core-runtime`). # - The final image is built FROM the Hummingbird runtime image and only adds files on top of it. -# It is not `FROM scratch` and nothing is installed into it with dnf. Reason: the Red Hat certification check -# `BasedOnUbi` asks Red Hat Pyxis whether a certified image contains the layers of the image under test. A -# `FROM scratch` image with a single new layer is never found, even if its contents are the same RPMs. -# Installing RPMs on top of the base could also overwrite files the base layers own (check `HasModifiedFiles`). +# The runtime image has bash and coreutils but no package manager, so nothing is installed in it. # - No user is created. The image runs as a numeric UID without a passwd entry (works in Kubernetes and OpenShift), # which avoids editing /etc/passwd and /etc/group, files that belong to RPMs of the base image. # - Not part of the image (they were in the UBI image and in the previous `FROM scratch` version of this spike): # bash profile and aliases, `nano`, `iputils`, `libkadm5`, `krb5-libs` and the other tools from `ubi10-minimal`. -# TODO: check that nothing needs them. The build prints the shared libraries the binary needs (see `additions`), -# compare them with what the runtime image provides. # - The builder is `hi/rust:latest-builder`, which ships the Rust toolchain and dnf. Nothing here installs or pins Rust, so the # image's Rust version must match rust-toolchain.toml (the build prints both, see the `builder` stage). # @@ -31,9 +26,9 @@ # docker build -f hummingbird-spike/Dockerfile --build-arg VERSION=0.0.0-dev \ # --build-arg RUNTIME_BASE=registry.access.redhat.com/hi/core-runtime: -t zookeeper-operator-hum:spike . # -# Useful intermediate targets: builder, additions +# Useful intermediate target: builder # -# docker build -f hummingbird-spike/Dockerfile --target additions -t zk-op-hum-additions . +# docker build -f hummingbird-spike/Dockerfile --target builder -t zk-op-hum-builder . # https://docs.docker.com/build/checks/#fail-build-on-check-violations # check=error=true @@ -42,12 +37,11 @@ # The `-builder` variant of hi/rust. The plain `hi/rust:latest` has no dnf. The builder variants add # bash, dnf5 and shadow-utils (default_rpm_packages.builder in the Hummingbird containers repo, # images/variables.yml), on top of cargo, rust, git-core, make, glibc-devel and openssl-devel (images/rust/properties.yml). +# The image also has gcc (gcc-16.2.1 when checked), which rustc needs as linker and the build scripts of +# `ring` and the vendored libgit2 (via `git2` in the `built` crate) need as C compiler. ARG BUILDER_BASE=registry.access.redhat.com/hi/rust:latest-builder -# Used for the `additions` stage only, it needs a shell, chown and ldd. The Rust toolchain in it is not used. -ARG ROOTFS_BASE=${BUILDER_BASE} # The base of the final image. The final image must share its layers, so this has to be an image that -# Red Hat certified (see the BasedOnUbi check of the preflight tool). It must be glibc based, the operator is -# dynamically linked. `hi/static` has no glibc. +# Red Hat certified. It must be glibc based, the operator is dynamically linked. `hi/static` has no glibc. # The binary is built against the glibc of BUILDER_BASE. Keep both bases on the same Hummingbird release. ARG RUNTIME_BASE=registry.access.redhat.com/hi/core-runtime:latest @@ -67,12 +61,6 @@ ARG CARGO_AUDITABLE_CRATE_VERSION=0.7.7 USER 0 SHELL ["/bin/bash", "-euo", "pipefail", "-c"] -# What the build needs on top of the image's cargo, rust, git-core, make and glibc-devel: -# - a C compiler: build scripts of `ring` and the vendored libgit2 (via `git2` in the `built` crate). -# hi/rust does not list gcc, so make sure it is there (a no-op if it already is). -# hadolint ignore=DL3041 -RUN dnf install --assumeyes gcc && dnf clean all - WORKDIR /src COPY . /src @@ -91,60 +79,50 @@ cp target/release/stackable-zookeeper-operator /app/ EOF # ============================================================================== -# additions: collects the files that are added on top of the runtime base image into /additions +# FINAL OPERATOR IMAGE # hadolint ignore=DL3006,DL3007 -FROM ${ROOTFS_BASE} AS additions +FROM ${RUNTIME_BASE} AS operator ARG VERSION - -# This is chosen at random and is this high on purpose to have very little chance to clash with an existing user on the host system -# NOTE: Please also update default.nix accordingly! -# There is no passwd entry for it in the image, the UID only has to be numeric and non-zero. +ARG RELEASE="1" +ARG TARGETARCH ARG STACKABLE_USER_UID="782252253" -# hadolint ignore=DL3002 +# All files are owned by the user and the root group (g=u) to support running as arbitrary users. +# This is best practice as all container users will belong to the root group (0). +COPY --chown=${STACKABLE_USER_UID}:0 --chmod=0664 LICENSE /licenses/LICENSE +COPY --from=builder --chown=${STACKABLE_USER_UID}:0 --chmod=0775 /app/stackable-zookeeper-operator /usr/local/bin/stackable-zookeeper-operator + +# The home directory and the README. The runtime image has bash and coreutils, so no extra stage is needed. +# Runs as root only for this step, the USER instruction below sets the unprivileged user. +# The check runs `ldd` in the runtime image: it fails the build if the base lacks a shared library of the binary. USER 0 SHELL ["/bin/bash", "-euo", "pipefail", "-c"] +RUN < /README.md <