Skip to content

Commit 5a7e7b7

Browse files
KrishVora01claude
andcommitted
Migrate cp-kcat to UBI9 micro base image
Switch from 2-stage ubi9-minimal build to 3-stage build using ubi9-micro as the final base: - Stage 1: Build kcat from source on ubi9 (unchanged logic) - Stage 2: Install runtime deps (libcurl, cyrus-sasl, krb5, etc.) into /microdir using dnf --installroot - Stage 3: Copy runtime libs + kcat binary to ubi9-micro Key changes: - Base image: ubi9-minimal -> ubi9-micro (ultra-lightweight, no pkg mgr) - Package manager: microdnf -> dnf --installroot=/microdir - Runtime deps installed in isolated stage, only /usr/lib64 + /etc/pki copied - Remove shadow-utils from build deps; manually create appuser in /etc/passwd - Build arg: UBI_MINIMAL_VERSION -> UBI_MICRO_VERSION + UBI9_VERSION - Fix LABEL summary quoting (remove nested quotes) - Fix fabric8 plugin indentation in pom.xml Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 8f1938d commit 5a7e7b7

File tree

2 files changed

+55
-36
lines changed

2 files changed

+55
-36
lines changed

kcat/Dockerfile.ubi9

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,18 @@ ARG DOCKER_UPSTREAM_TAG=ubi9-latest
1818
ARG PROJECT_VERSION
1919
ARG ARTIFACT_ID
2020
ARG GIT_COMMIT
21-
ARG UBI_MINIMAL_VERSION="latest"
21+
ARG UBI9_VERSION
22+
ARG UBI_MICRO_VERSION
2223

23-
FROM registry.access.redhat.com/ubi9/ubi-minimal:${UBI_MINIMAL_VERSION}
24+
# Stage 1: Build kcat from source
25+
FROM registry.access.redhat.com/ubi9:${UBI9_VERSION} AS build
2426

2527
WORKDIR /build
2628

2729
ENV VERSION=1.7.0
28-
ENV BUILD_PACKAGES="which git make cmake gcc-c++ zlib-devel curl-devel openssl-devel cyrus-sasl-devel krb5-devel pkgconfig lz4-devel wget tar findutils shadow-utils"
29-
30-
USER root
30+
ENV BUILD_PACKAGES="which git make cmake gcc-c++ zlib-devel curl-devel openssl-devel cyrus-sasl-devel krb5-devel pkgconfig lz4-devel wget tar findutils"
3131

3232
RUN echo "Building kcat ....." \
33-
&& microdnf install -y dnf \
3433
&& dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
3534
&& dnf install -y $BUILD_PACKAGES \
3635
&& dnf clean all \
@@ -41,35 +40,53 @@ RUN echo "Building kcat ....." \
4140
&& make \
4241
&& ldd kcat
4342

44-
FROM registry.access.redhat.com/ubi9/ubi-minimal:${UBI_MINIMAL_VERSION}
43+
# Stage 2: Install runtime dependencies to /microdir
44+
FROM registry.access.redhat.com/ubi9:${UBI9_VERSION} AS runtime-deps
45+
46+
RUN mkdir -p /microdir \
47+
&& dnf install -y --installroot=/microdir --releasever=9 --setopt=install_weak_deps=False --nodocs \
48+
ca-certificates \
49+
libcurl-minimal \
50+
cyrus-sasl-lib \
51+
krb5-libs \
52+
openssl-libs \
53+
zlib \
54+
libxcrypt \
55+
libcom_err \
56+
keyutils-libs \
57+
libnghttp2 \
58+
&& dnf --installroot=/microdir clean all \
59+
&& rm -rf /microdir/var/cache/* /microdir/var/log/dnf* /microdir/var/log/yum.* \
60+
&& rm -rf /microdir/dev/* /microdir/proc/* /microdir/sys/*
61+
62+
# Stage 3: Final ultra-lightweight image using ubi9-micro
63+
FROM registry.access.redhat.com/ubi9-micro:${UBI_MICRO_VERSION}
4564

4665
LABEL maintainer="partner-support@confluent.io"
4766
LABEL vendor="Confluent"
4867
LABEL version=$GIT_COMMIT
4968
LABEL release=$PROJECT_VERSION
5069
LABEL name=$ARTIFACT_ID
51-
LABEL summary="kcat is a command line utility that you can use to test and debug Apache Kafka® deployments. You can use kcat to produce, consume, and list topic and partition information for Kafka. Described as netcat for Kafka, it is a swiss-army knife of tools for inspecting and creating data in Kafka."
70+
LABEL summary="kcat is a command line utility that you can use to test and debug Apache Kafka® deployments. You can use kcat to produce, consume, and list topic and partition information for Kafka. Described as netcat for Kafka, it is a swiss-army knife of tools for inspecting and creating data in Kafka."
5271
LABEL io.confluent.docker=true
5372
LABEL io.confluent.docker.git.id=$GIT_COMMIT
5473
ARG BUILD_NUMBER=-1
5574
LABEL io.confluent.docker.build.number=$BUILD_NUMBER
5675
LABEL io.confluent.docker.git.repo="confluentinc/kafkacat-images"
5776

58-
USER root
77+
# Copy runtime libraries from the deps stage
78+
COPY --from=runtime-deps /microdir/usr/lib64/ /usr/lib64/
79+
COPY --from=runtime-deps /microdir/etc/pki/ /etc/pki/
5980

60-
COPY --from=0 /build/kcat/kcat /usr/local/bin/
81+
# Copy kcat binary from the build stage
82+
COPY --from=build /build/kcat/kcat /usr/local/bin/
83+
RUN ln -s /usr/local/bin/kcat /usr/local/bin/kafkacat
6184

62-
RUN ln -s /usr/local/bin/kcat /usr/local/bin/kafkacat \
63-
&& echo "Installing runtime dependencies for SSL and SASL support ...." \
64-
&& microdnf install -y dnf \
65-
&& dnf install -y https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm \
66-
&& dnf install -y ca-certificates \
67-
&& echo "===> clean up ..." \
68-
&& dnf clean all \
69-
&& rm -rf /tmp/*
85+
# Create non-root user (ubi9-micro has no shadow-utils)
86+
RUN echo "appuser:x:1000:1000:appuser:/home/appuser:/sbin/nologin" >> /etc/passwd \
87+
&& echo "appuser:x:1000:" >> /etc/group
7088

71-
RUN useradd -ms /bin/bash appuser
72-
USER appuser
89+
USER 1000
7390

7491
RUN kcat -V
7592

kcat/pom.xml

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -42,27 +42,29 @@
4242
<artifactId>dockerfile-maven-plugin</artifactId>
4343
<configuration>
4444
<buildArgs>
45-
<UBI_MINIMAL_VERSION>${ubi9.minimal.image.version}</UBI_MINIMAL_VERSION>
45+
<UBI_MICRO_VERSION>${ubi9-micro.image.version}</UBI_MICRO_VERSION>
46+
<UBI9_VERSION>${ubi9.image.version}</UBI9_VERSION>
4647
</buildArgs>
4748
</configuration>
4849
</plugin>
4950

5051
<plugin>
51-
<groupId>io.fabric8</groupId>
52-
<artifactId>docker-maven-plugin</artifactId>
53-
<version>0.48.1</version>
54-
<configuration>
55-
<images>
56-
<image>
57-
<build>
58-
<args>
59-
<UBI_MINIMAL_VERSION>${ubi9.minimal.image.version}</UBI_MINIMAL_VERSION>
60-
</args>
61-
</build>
62-
</image>
63-
</images>
64-
</configuration>
65-
</plugin>
52+
<groupId>io.fabric8</groupId>
53+
<artifactId>docker-maven-plugin</artifactId>
54+
<version>0.48.1</version>
55+
<configuration>
56+
<images>
57+
<image>
58+
<build>
59+
<args>
60+
<UBI_MICRO_VERSION>${ubi9-micro.image.version}</UBI_MICRO_VERSION>
61+
<UBI9_VERSION>${ubi9.image.version}</UBI9_VERSION>
62+
</args>
63+
</build>
64+
</image>
65+
</images>
66+
</configuration>
67+
</plugin>
6668
</plugins>
6769
</build>
6870

0 commit comments

Comments
 (0)