Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Download Kafka binaries from archive if not present on mirror #2768

Merged
merged 4 commits into from
Mar 12, 2021
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
21 changes: 14 additions & 7 deletions examples/messaging/docker/kafka/Dockerfile.kafka
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 2019, 2020 Oracle and/or its affiliates.
# Copyright (c) 2019, 2021 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,15 +14,22 @@
# limitations under the License.
#

FROM openjdk:8-jre-alpine
FROM openjdk:11-jre-slim-buster

ENV VERSION=2.5.0
ENV VERSION=2.7.0
ENV SCALA_VERSION=2.13

RUN apk add --no-cache bash curl jq gcompat
RUN apt-get -qq update && apt-get -qq -y install bash curl wget netcat jq

# Find closest mirror, download and extract Kafka
RUN MIRROR=$(curl -s 'https://www.apache.org/dyn/closer.cgi?as_json=1' | jq -r '.http[0]') \
&& wget -q -O kafka.tar.gz ${MIRROR}kafka/${VERSION}/kafka_2.12-${VERSION}.tgz \
RUN REL_PATH=kafka/${VERSION}/kafka_${SCALA_VERSION}-${VERSION}.tgz \
&& BACKUP_ARCHIVE=https://archive.apache.org/dist/ \
&& echo "Looking for closest mirror ..." \
&& MIRROR=$(curl -s 'https://www.apache.org/dyn/closer.cgi?as_json=1' | jq -r '.http[0]') \
&& echo "Checking if version ${VERSION} is available on the mirror: ${MIRROR} ..." \
&& MIRROR_RESPONSE=$(curl -L --write-out '%{http_code}' --silent --output /dev/null ${MIRROR}kafka/${VERSION}) \
&& if [ $MIRROR_RESPONSE -eq 200 ]; then BIN_URL=${MIRROR}${REL_PATH}; else BIN_URL=${BACKUP_ARCHIVE}${REL_PATH}; fi \
&& if [ $MIRROR_RESPONSE -ne 200 ]; then echo "Version ${VERSION} not found on the mirror ${MIRROR}, defaulting to archive ${BACKUP_ARCHIVE}."; fi \
&& wget -q -O kafka.tar.gz ${BIN_URL} \
&& tar -xzf kafka.tar.gz -C /opt && rm kafka.tar.gz \
&& mv /opt/kafka* /opt/kafka

Expand Down
10 changes: 7 additions & 3 deletions examples/messaging/docker/kafka/init_topics.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2020 Oracle and/or its affiliates.
# Copyright (c) 2020, 2021 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -24,9 +24,9 @@ ZOOKEEPER_URL=localhost:2181
KAFKA_TOPICS="/opt/kafka/bin/kafka-topics.sh --if-not-exists --zookeeper $ZOOKEEPER_URL"

while sleep 2; do
brokers=$(echo dump | nc localhost 2181 | grep brokers)
brokers=$(echo dump | nc localhost 2181 | grep brokers | wc -l)
echo "Checking if Kafka is up: ${brokers}"
if [[ -z $brokers ]]; then
if [[ "$brokers" -gt "0" ]]; then
echo "KAFKA IS UP !!!"

echo "Creating test topics"
Expand All @@ -41,6 +41,10 @@ while sleep 2; do
--partitions 10 \
--topic messaging-test-topic-2

echo
echo "Example topics messaging-test-topic-1 and messaging-test-topic-2 created"
echo
echo "================== Kafka is ready, stop it with Ctrl+C =================="
exit 0
fi
done
5 changes: 4 additions & 1 deletion examples/messaging/docker/kafka/start_kafka.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
#
# Copyright (c) 2020 Oracle and/or its affiliates.
# Copyright (c) 2020, 2021 Oracle and/or its affiliates.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -44,3 +44,6 @@ if [ $state -ne 0 ]; then
echo "Kafka stopped."
exit $state
fi

# Keep Kafka up till Ctrl+C
read ;