#
# Copyright Kroxylicious Authors.
#
# Licensed under the Apache Software License version 2.0, available at http://www.apache.org/licenses/LICENSE-2.0
#

# Multi-stage build for OpenMessaging Benchmark (OMB).
# The published openmessaging/openmessaging-benchmark:latest image ships
# Kafka client 1.0.0 on Java 8.  This Containerfile builds from the
# current upstream source (Kafka 3.6.1, JDK 21).

# Upstream OMB has no tags or releases — pin to a known-good commit on master.
ARG OMB_COMMIT=85599891321cafa2fb7065a63f009b4bb5374288

# ---------- Stage 1: build ----------
FROM registry.access.redhat.com/ubi9/openjdk-21:1.24-2.1774011803@sha256:15c5052ae2d9f48b8876c895200e0468c3b1cc40b9727fdd41bd1d5a6152d891 AS builder
USER root

ARG OMB_COMMIT
RUN microdnf --setopt=install_weak_deps=0 --setopt=tsflags=nodocs install -y git && \
    microdnf clean all

RUN git clone https://github.com/openmessaging/benchmark.git /build && \
    cd /build && git checkout ${OMB_COMMIT}

WORKDIR /build
RUN mvn clean package -DskipTests && \
    mkdir -p /opt/benchmark && \
    tar -xzf /build/package/target/openmessaging-benchmark-*-bin.tar.gz --strip-components=1 -C /opt/benchmark

# ---------- Stage 2: runtime ----------
FROM registry.access.redhat.com/ubi9/openjdk-21-runtime:1.24-2.1774011801@sha256:622ba9ba5339b3af9bd4fd4bb9aad4d199ff3e2d0d1e50500d113aac38a801bf
USER root

COPY --from=builder --chown=185:0 /opt/benchmark /opt/benchmark

USER 185
WORKDIR /opt/benchmark
