diff --git a/Makefile b/Makefile index c83172c3b0f..42e947511a7 100644 --- a/Makefile +++ b/Makefile @@ -63,7 +63,7 @@ PROTOS = $(shell git ls-files *.proto | grep -v vendor) MSP_SAMPLECONFIG = $(shell git ls-files msp/sampleconfig/*.pem) GENESIS_SAMPLECONFIG = $(shell git ls-files common/configtx/test/*.template) PROJECT_FILES = $(shell git ls-files) -IMAGES = peer orderer ccenv javaenv testenv runtime +IMAGES = peer orderer ccenv javaenv testenv runtime zookeeper pkgmap.peer := $(PKGNAME)/peer pkgmap.orderer := $(PKGNAME)/orderer @@ -191,6 +191,7 @@ build/image/orderer/payload: build/docker/bin/orderer \ orderer/orderer.yaml build/image/testenv/payload: build/gotools.tar.bz2 build/image/runtime/payload: build/docker/busybox +build/image/zookeeper/payload: images/zookeeper/docker-entrypoint.sh build/image/%/payload: mkdir -p $@ diff --git a/bddtests/environments/kafka/docker-compose.yml b/bddtests/environments/kafka/docker-compose.yml index a67e83e038e..0e4135d5f96 100644 --- a/bddtests/environments/kafka/docker-compose.yml +++ b/bddtests/environments/kafka/docker-compose.yml @@ -1,8 +1,7 @@ version: '2' services: zookeeper: - # Offical Apache ZooKeeper image. See https://hub.docker.com/_/zookeeper/ - image: zookeeper:3.4.9 + image: hyperledger/fabric-zookeeper kafka: build: . diff --git a/bddtests/environments/orderer-1-kafka-1/docker-compose.yml b/bddtests/environments/orderer-1-kafka-1/docker-compose.yml index ead814fab64..de9c35253fc 100644 --- a/bddtests/environments/orderer-1-kafka-1/docker-compose.yml +++ b/bddtests/environments/orderer-1-kafka-1/docker-compose.yml @@ -1,8 +1,7 @@ version: '2' services: zookeeper: - # Offical Apache ZooKeeper image. See https://hub.docker.com/_/zookeeper/ - image: zookeeper:3.4.9 + image: hyperledger/fabric-zookeeper orderer0: image: hyperledger/fabric-orderer diff --git a/bddtests/environments/orderer-1-kafka-3/docker-compose.yml b/bddtests/environments/orderer-1-kafka-3/docker-compose.yml index 97c5585fd4e..b6bacf9dc2d 100644 --- a/bddtests/environments/orderer-1-kafka-3/docker-compose.yml +++ b/bddtests/environments/orderer-1-kafka-3/docker-compose.yml @@ -1,8 +1,7 @@ version: '2' services: zookeeper: - # Offical Apache ZooKeeper image. See https://hub.docker.com/_/zookeeper/ - image: zookeeper:3.4.9 + image: hyperledger/fabric-zookeeper orderer0: image: hyperledger/fabric-orderer diff --git a/bddtests/environments/orderer-n-kafka-n/docker-compose.yml b/bddtests/environments/orderer-n-kafka-n/docker-compose.yml index 8171b851268..4bfd74b2a67 100644 --- a/bddtests/environments/orderer-n-kafka-n/docker-compose.yml +++ b/bddtests/environments/orderer-n-kafka-n/docker-compose.yml @@ -1,8 +1,7 @@ version: '2' services: zookeeper: - # Offical Apache ZooKeeper image. See https://hub.docker.com/_/zookeeper/ - image: zookeeper:3.4.9 + image: hyperledger/fabric-zookeeper orderer: build: ./orderer diff --git a/images/zookeeper/Dockerfile.in b/images/zookeeper/Dockerfile.in new file mode 100755 index 00000000000..81c7c4ca8f2 --- /dev/null +++ b/images/zookeeper/Dockerfile.in @@ -0,0 +1,47 @@ +FROM hyperledger/fabric-baseimage:_BASE_TAG_ +# Based on https://github.com/31z4/zookeeper-docker/blob/master/3.4.9/Dockerfile + +# Install su-exec +RUN set -x \ + && git clone https://github.com/ncopa/su-exec /tmp/su-exec/ \ + && cd /tmp/su-exec \ + && make all \ + && cp su-exec /usr/bin/ + +ENV ZOO_USER=zookeeper \ + ZOO_CONF_DIR=/conf \ + ZOO_DATA_DIR=/data \ + ZOO_DATA_LOG_DIR=/datalog \ + ZOO_PORT=2181 \ + ZOO_TICK_TIME=2000 \ + ZOO_INIT_LIMIT=5 \ + ZOO_SYNC_LIMIT=2 + +# Add a user and make dirs +RUN set -x \ + && useradd "$ZOO_USER" \ + && mkdir -p "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR" \ + && chown "$ZOO_USER:$ZOO_USER" "$ZOO_DATA_LOG_DIR" "$ZOO_DATA_DIR" "$ZOO_CONF_DIR" + +ARG GPG_KEY=C823E3E5B12AF29C67F81976F5CECB3CB5E9BD2D +ARG DISTRO_NAME=zookeeper-3.4.9 + +# Download Apache Zookeeper, verify its PGP signature, untar and clean up +RUN set -x \ + && cd / \ + && wget -q "http://www.apache.org/dist/zookeeper/$DISTRO_NAME/$DISTRO_NAME.tar.gz" \ + && tar -xzf "$DISTRO_NAME.tar.gz" \ + && mv "$DISTRO_NAME/conf/"* "$ZOO_CONF_DIR" \ + && rm -r "$DISTRO_NAME.tar.gz" + +WORKDIR $DISTRO_NAME +VOLUME ["$ZOO_DATA_DIR", "$ZOO_DATA_LOG_DIR"] + +EXPOSE $ZOO_PORT 2888 3888 + +ENV PATH=$PATH:/$DISTRO_NAME/bin \ + ZOOCFGDIR=$ZOO_CONF_DIR + +COPY payload/docker-entrypoint.sh / +ENTRYPOINT ["/docker-entrypoint.sh"] +CMD ["zkServer.sh", "start-foreground"] diff --git a/images/zookeeper/docker-entrypoint.sh b/images/zookeeper/docker-entrypoint.sh new file mode 100755 index 00000000000..c053a4a05d1 --- /dev/null +++ b/images/zookeeper/docker-entrypoint.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +set -e + +# Allow the container to be started with `--user` +if [ "$1" = 'zkServer.sh' -a "$(id -u)" = '0' ]; then + chown -R "$ZOO_USER" "$ZOO_DATA_DIR" "$ZOO_DATA_LOG_DIR" + exec su-exec "$ZOO_USER" "$0" "$@" +fi + +# Generate the config only if it doesn't exist +if [ ! -f "$ZOO_CONF_DIR/zoo.cfg" ]; then + CONFIG="$ZOO_CONF_DIR/zoo.cfg" + + echo "clientPort=$ZOO_PORT" >> "$CONFIG" + echo "dataDir=$ZOO_DATA_DIR" >> "$CONFIG" + echo "dataLogDir=$ZOO_DATA_LOG_DIR" >> "$CONFIG" + + echo "tickTime=$ZOO_TICK_TIME" >> "$CONFIG" + echo "initLimit=$ZOO_INIT_LIMIT" >> "$CONFIG" + echo "syncLimit=$ZOO_SYNC_LIMIT" >> "$CONFIG" + + for server in $ZOO_SERVERS; do + echo "$server" >> "$CONFIG" + done +fi + +# Write myid only if it doesn't exist +if [ ! -f "$ZOO_DATA_DIR/myid" ]; then + echo "${ZOO_MY_ID:-1}" > "$ZOO_DATA_DIR/myid" +fi + +exec "$@"