diff --git a/kafka/Dockerfile b/kafka/Dockerfile index 5d03888..837341b 100644 --- a/kafka/Dockerfile +++ b/kafka/Dockerfile @@ -1,13 +1,15 @@ FROM openjdk:11-jre-slim RUN apt update && \ - apt install -y wget + apt install -y wget curl jq -ARG KAFKA_VERSION=2.3.0 RUN mkdir /kafka WORKDIR /kafka -RUN wget http://miroir.univ-lorraine.fr/apache/kafka/$KAFKA_VERSION/kafka_2.11-$KAFKA_VERSION.tgz -RUN tar xzf kafka_2.11-$KAFKA_VERSION.tgz --strip-components=1 + +# download kafka +COPY download.sh /kafka +RUN /kafka/download.sh "/kafka/kafka.tgz" +RUN tar xzf /kafka/kafka.tgz --strip-components=1 VOLUME /tmp/kafka-logs diff --git a/kafka/download.sh b/kafka/download.sh new file mode 100755 index 0000000..999929e --- /dev/null +++ b/kafka/download.sh @@ -0,0 +1,19 @@ +#!/bin/sh -e +# download kafka, code from https://github.com/wurstmeister/kafka-docker/blob/master/download-kafka.sh + +KAFKA_VERSION=2.7.0 +SCALA_VERSION=2.12 + +FILENAME="kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz" + +url=$(curl --stderr /dev/null "https://www.apache.org/dyn/closer.cgi?path=/kafka/${KAFKA_VERSION}/${FILENAME}&as_json=1" | jq -r '"\(.preferred)\(.path_info)"') + +# Test to see if the suggested mirror has this version, currently pre 2.1.1 versions +# do not appear to be actively mirrored. This may also be useful if closer.cgi is down. +if [[ ! $(curl -s -f -I "${url}") ]]; then + echo "Mirror does not have desired version, downloading direct from Apache" + url="https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/${FILENAME}" +fi + +echo "Downloading Kafka from $url to $1" +wget "${url}" -O "$1"