#
# Copyright (c) 2019, 2020 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.
# 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 openjdk:8-jre-alpine

ENV VERSION=2.5.0

RUN apk add --no-cache bash curl 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 \
&& tar -xzf kafka.tar.gz -C /opt && rm kafka.tar.gz \
&& mv /opt/kafka* /opt/kafka

WORKDIR /opt/kafka

COPY start_kafka.sh start_kafka.sh
COPY init_topics.sh init_topics.sh

RUN chmod a+x ./*.sh

# Expose Zookeeper and Kafka ports
EXPOSE 2181 9092

CMD bash start_kafka.sh
