kafka/docker/native/Dockerfile

80 lines
3.0 KiB
Docker
Raw Normal View History

# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
FROM ghcr.io/graalvm/graalvm-community:21 AS build-native-image
ARG kafka_url
WORKDIR /app
ENV KAFKA_URL=$kafka_url
ENV NATIVE_IMAGE_PATH="native-image"
ENV KAFKA_DIR="/app/kafka"
ENV NATIVE_CONFIGS_DIR="/app/native-image-configs"
ENV KAFKA_LIBS_DIR="$KAFKA_DIR/libs"
ENV TARGET_PATH="$KAFKA_DIR/kafka.Kafka"
COPY native-image-configs $NATIVE_CONFIGS_DIR
COPY native_command.sh native_command.sh
KAFKA-18841: Enable to test docker image locally (#19028) ### Case 1: no --kafka-url and --kafka-archive Should fail. One of argument (--kafka-url/--kafka-archive) is required. ``` > python docker_build_test.py apache/kafka --image-tag KAFKA-18841 --image-type jvm --build usage: docker_build_test.py [-h] [--image-tag TAG] [--image-type {jvm,native}] [--build] [--test] (--kafka-url KAFKA_URL | --kafka-archive KAFKA_ARCHIVE) image docker_build_test.py: error: one of the arguments --kafka-url/-u --kafka-archive/-a is required ``` ### Case 2: --kafka-url with native ``` > python docker_build_test.py apache/kafka --image-tag KAFKA-18841 --image-type native --kafka-url https://dist.apache.org/repos/dist/dev/kafka/4.0.0-rc0/kafka_2.13-4.0.0.tgz --build ``` ### Case 3: --karka-url with jvm ``` > python docker_build_test.py apache/kafka --image-tag KAFKA-18841 --image-type jvm --kafka-url https://dist.apache.org/repos/dist/dev/kafka/4.0.0-rc0/kafka_2.13-4.0.0.tgz --build ``` ### Case 4: --kafka-archive with native ``` > ./gradlew clean releaseTarGz > cd docker > python docker_build_test.py apache/kafka --image-tag KAFKA-18841 --image-type native --kafka-archive </absolute/path/to/core/build/distributions/kafka_2.13-4.1.0-SNAPSHOT.tgz> --build ``` ### Case 5: --kafka-archive with jvm ``` > ./gradlew clean releaseTarGz > cd docker > python docker_build_test.py apache/kafka --image-tag KAFKA-18841 --image-type jvm --kafka-archive </absolute/path/to/core/build/distributions/kafka_2.13-4.1.0-SNAPSHOT.tgz> --build ``` Reviewers: Vedarth Sharma <vesharma@confluent.io>, Chia-Ping Tsai <chia7712@gmail.com>, TengYao Chi <frankvicky@apache.org> --------- Signed-off-by: PoAn Yang <payang@apache.org>
2025-08-26 10:30:14 +08:00
COPY *kafka.tgz /app
RUN if [ -n "$KAFKA_URL" ]; then \
microdnf install wget; \
wget -nv -O kafka.tgz "$KAFKA_URL"; \
wget -nv -O kafka.tgz.asc "$KAFKA_URL.asc"; \
wget -nv -O KEYS https://downloads.apache.org/kafka/KEYS; \
gpg --import KEYS; \
gpg --batch --verify kafka.tgz.asc kafka.tgz; \
fi; \
mkdir $KAFKA_DIR; \
tar xfz kafka.tgz -C $KAFKA_DIR --strip-components 1; \
# Build the native-binary of the apache kafka using graalVM native-image.
/app/native_command.sh $NATIVE_IMAGE_PATH $NATIVE_CONFIGS_DIR $KAFKA_LIBS_DIR $TARGET_PATH
FROM alpine:latest
EXPOSE 9092
ARG build_date
LABEL org.label-schema.name="kafka" \
org.label-schema.description="Apache Kafka" \
org.label-schema.build-date="${build_date}" \
org.label-schema.vcs-url="https://github.com/apache/kafka" \
org.opencontainers.image.authors="Apache Kafka"
RUN apk update ; \
apk add --no-cache gcompat ; \
apk add --no-cache bash ; \
mkdir -p /etc/kafka/docker /mnt/shared/config /opt/kafka/config /etc/kafka/secrets ; \
adduser -h /home/appuser -D --shell /bin/bash appuser ; \
chown appuser:root -R /etc/kafka /opt/kafka /mnt/shared/config ; \
chmod -R ug+w /etc/kafka /opt/kafka /mnt/shared/config ;
COPY server.properties /etc/kafka/docker/server.properties
COPY --chown=appuser:root --from=build-native-image /app/kafka/kafka.Kafka /opt/kafka/
COPY --chown=appuser:root --from=build-native-image /app/kafka/config/log4j2.yaml /etc/kafka/docker/
COPY --chown=appuser:root --from=build-native-image /app/kafka/config/tools-log4j2.yaml /etc/kafka/docker/
COPY --chown=appuser:root resources/common-scripts /etc/kafka/docker/
COPY --chown=appuser:root launch /etc/kafka/docker/
USER appuser
VOLUME ["/etc/kafka/secrets", "/mnt/shared/config"]
CMD ["/etc/kafka/docker/run"]