diff --git a/Dockerfile b/Dockerfile index b0a549d..8c43f3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,32 @@ -#FROM ubuntu:trusty -#FROM ubuntu:16.04 -#FROM java:8 -FROM openjdk:8-alpine +FROM java:8 MAINTAINER Juergen Jakobitsch -#RUN apt-get update && apt-get install -y vim +# Install utilities +RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y netcat -RUN apk add --update bash && rm -rf /var/cache/apk/* +# Zookeeper version to be used +ENV ZK_VERSION zookeeper-3.4.11 -ADD zookeeper-3.5.2-alpha.tar.gz /usr/local/apache-zookeeper/ +# Download distribution +RUN wget -q http://ftp.halifax.rwth-aachen.de/apache/zookeeper/"$ZK_VERSION"/"$ZK_VERSION".tar.gz -O /tmp/"$ZK_VERSION".tar.gz \ + && tar xfz /tmp/"$ZK_VERSION".tar.gz -C /opt \ + && rm /tmp/"$ZK_VERSION".tar.gz -RUN ln -s /usr/local/apache-zookeeper/zookeeper-3.5.2-alpha /usr/local/apache-zookeeper/current +# The common installation dirname to use zookeeper +RUN ln -s /opt/"$ZK_VERSION" /opt/zookeeper -RUN rm -f /tmp/zookeeper-3.5.2-alpha.tar.gz +# Define the run configuration +RUN cd /opt/zookeeper/conf \ + && cp -p zoo_sample.cfg zoo.cfg -RUN ln -s /usr/local/apache-zookeeper/zookeeper-3.5.2-alpha /app -RUN ln -s /usr/local/apache-zookeeper/zookeeper-3.5.2-alpha/conf /config +EXPOSE 2181 -COPY zk-config /app/bin -COPY startup / -#COPY wait-for-step.sh / -#COPY execute-step.sh / -#COPY finish-step.sh / +COPY wait-for-step.sh / +COPY execute-step.sh / +COPY finish-step.sh / + +COPY healthcheck / +COPY zookeeper-startup.sh / + +CMD [ "./zookeeper-startup.sh" ] diff --git a/README.md b/README.md index 067cac4..4fdaf0b 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # Zookeeper Docker Versions used in this docker image: -* Zookeeper Version: 3.5.2-alpha -* Java 1.8.0_72 +* Zookeeper Version: 3.4.11 +* Java 1.8.x Image details: * Installation directory: /app (i.e: /usr/local/apache-zookeeper/current) diff --git a/execute-step.sh b/execute-step.sh new file mode 100755 index 0000000..adccfb0 --- /dev/null +++ b/execute-step.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [[ $ENABLE_INIT_DAEMON = "true" ]] + then + echo "Execute step ${INIT_DAEMON_STEP} in pipeline" + while true; do + sleep 5 + echo -n '.' + string=$(curl -w "%{http_code}" -X PUT $INIT_DAEMON_BASE_URI/execute?step=$INIT_DAEMON_STEP -d "") + [ "$string" = "204" ] && break + done + echo "Notified execution of step ${INIT_DAEMON_STEP}" +fi diff --git a/finish-step.sh b/finish-step.sh new file mode 100755 index 0000000..587eab9 --- /dev/null +++ b/finish-step.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [[ $ENABLE_INIT_DAEMON = "true" ]] + then + echo "Finish step ${INIT_DAEMON_STEP} in pipeline" + while true; do + sleep 5 + echo -n '.' + string=$(curl -w "%{http_code}" -X PUT $INIT_DAEMON_BASE_URI/finish?step=$INIT_DAEMON_STEP -d "") + [ "$string" = "204" ] && break + done + echo "Notified finish of step ${INIT_DAEMON_STEP}" +fi diff --git a/healthcheck b/healthcheck new file mode 100755 index 0000000..fe64cab --- /dev/null +++ b/healthcheck @@ -0,0 +1,10 @@ +#!/bin/bash + +set -e + +export IMOK=$(echo ruok | nc localhost 2181) +if [[ "$IMOK" == "imok" ]]; then + exit 0 +else + exit 1 +fi diff --git a/startup b/startup deleted file mode 100755 index a501949..0000000 --- a/startup +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/bash - -cd /app/bin && ./zk-config && ./zkServer.sh start-foreground - diff --git a/wait-for-step.sh b/wait-for-step.sh new file mode 100755 index 0000000..c501c61 --- /dev/null +++ b/wait-for-step.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +if [[ $ENABLE_INIT_DAEMON = "true" ]] + then + echo "Validating if step ${INIT_DAEMON_STEP} can start in pipeline" + while true; do + sleep 5 + echo -n '.' + string=$(curl -s $INIT_DAEMON_BASE_URI/canStart?step=$INIT_DAEMON_STEP) + [ "$string" = "true" ] && break + done + echo "Can start step ${INIT_DAEMON_STEP}" +fi diff --git a/zk-config b/zk-config deleted file mode 100755 index f2e43ba..0000000 --- a/zk-config +++ /dev/null @@ -1,68 +0,0 @@ -#!/bin/bash - -HOSTNAME=`hostname` -IFS=" " -IPS=`hostname -i` -echo "HOSTNAME==>$HOSTNAME"; -echo "IPS==>$IPS"; -read -r -a IP_ADDRESSES <<< "$IPS" - -ZK_CONF_DIR="/config" -ZK_CONF_FILE="zoo.cfg" -MYID_REGEX="\\.([0-9]{1,3})=" - -function extractMyId { - if [[ $1 =~ $MYID_REGEX ]] - then - echo "${BASH_REMATCH[1]}" - else - echo "NaN" - fi -} - -while read line -do - if [[ $line = dataDir=* ]]; - then - IFS="=" - read -r key ZK_DATADIR <<< "$line" - [[ -d "$ZK_DATADIR" ]] || mkdir -p "$ZK_DATADIR" - fi - if [[ $line = dynamicConfigFile=* ]]; - then - IFS="=" - read -r key ZK_DYNAMIC_CONFIG_FILE <<< "$line" - fi -done < "$ZK_CONF_DIR/$ZK_CONF_FILE" - -#echo "ZK_DATADIR:$ZK_DATADIR"; -#echo "ZK_DYNAMIC_CONFIG_FILE:$ZK_DYNAMIC_CONFIG_FILE"; -#echo "HOSTNAME:$HOSTNAME" -#echo "IPS:$IPS" - -if [ ! -f "$ZK_DATADIR/myid" ]; then - while read line - do - echo "READING CONFIGLINE: $line" - if [[ $line == *"$HOSTNAME"* ]]; - then - MYID=`extractMyId "$line"`; - echo $MYID >> "$ZK_DATADIR/myid" - echo "Writing myid $MYID to $ZK_DATADIR/myid" - break; - else - #for ip in `ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'` - for ip in ${IP_ADDRESSES[@]} - do - if [[ $line == *"$ip"* ]]; - then - MYID=`extractMyId "$line"`; - echo $MYID >> "$ZK_DATADIR/myid" - echo "Writing myid $MYID to $ZK_DATADIR/myid" - break; - fi - done - fi - done < "$ZK_DYNAMIC_CONFIG_FILE" -fi -exit 0 diff --git a/zookeeper-3.5.2-alpha.tar.gz b/zookeeper-3.5.2-alpha.tar.gz deleted file mode 100644 index 49e18a7..0000000 Binary files a/zookeeper-3.5.2-alpha.tar.gz and /dev/null differ diff --git a/zookeeper-startup.sh b/zookeeper-startup.sh new file mode 100755 index 0000000..f5d2fe9 --- /dev/null +++ b/zookeeper-startup.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +set -e + +echo `date` $0 + +/wait-for-step.sh +/execute-step.sh + +if [[ $ENABLE_INIT_DAEMON = "true" ]] ;then + ( + while ! ( /healthcheck ) ;do echo expect to become healthy; sleep 1; done + echo XXX $0 initialisation finished, service is healthy + /finish-step.sh + ) & +fi + +echo `date` $0 : zkServer.sh start-foreground +exec /opt/zookeeper/bin/zkServer.sh start-foreground