Skip to content

Commit

Permalink
Add Zookeeper multi-arch support
Browse files Browse the repository at this point in the history
  • Loading branch information
mandrean committed Feb 18, 2022
1 parent 97957bd commit 49d77c8
Show file tree
Hide file tree
Showing 6 changed files with 183 additions and 28 deletions.
66 changes: 66 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
sudo: required

language: java

services:
- docker

# This version will be also tagged as 'latest'
env:
global:
- LATEST="3.7.0"

matrix:
include:
- jdk: openjdk11
env: ZOOKEEPER_VERSION=3.7.0 JAVA_VERSION=11-jre-slim

# Upgrade Docker Engine so we can use buildx
before_install:
- curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
- sudo add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable"
- sudo apt-get update
- sudo apt-get -y -o Dpkg::Options::="--force-confnew" install docker-ce

install:
- docker --version
- docker buildx version
- docker-compose --version
- echo "ZOOKEEPER VERSION $ZOOKEEPER_VERSION"
- echo "JAVA VERSION $JAVA_VERSION"
- echo "LATEST VERSION $LATEST"
- if [ -z ${DOCKER_PASSWORD+x} ]; then echo "Using unauthenticated pulls on PR"; else echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin; fi
- export CURRENT=${ZOOKEEPER_VERSION}

# Prepare the environment for multi-arch builds
- docker run --rm --privileged multiarch/qemu-user-static --reset -p yes
- docker buildx create --use

# Build all of the platforms and cache the result
- bash docker_buildx

# Using the multi-arch build cache
- bash docker_buildx --load

script:
# Shellcheck main source files
- shellcheck -s bash start-zk.sh
- cd test
# Shellcheck the tests
- shellcheck -x -e SC1090 -s bash *.sh **/*.sh
- ./verifyImageLabels.sh # Verify docker image's label
# Add more tests in the future

# This will deploy from master. Might want to have a single release branch for a little more control
deploy:
- provider: script
script: bash docker_push latest
on:
repo: wurstmeister/zookeeper-docker
branch: master
condition: $CURRENT = $LATEST
- provider: script
script: bash docker_push "${ZOOKEEPER_VERSION}"
on:
repo: wurstmeister/zookeeper-docker
# branch: release
75 changes: 48 additions & 27 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
FROM wurstmeister/base

MAINTAINER Wurstmeister

ENV ZOOKEEPER_VERSION 3.4.13

#Download Zookeeper
RUN wget -q http://mirror.vorboss.net/apache/zookeeper/zookeeper-${ZOOKEEPER_VERSION}/zookeeper-${ZOOKEEPER_VERSION}.tar.gz && \
wget -q https://www.apache.org/dist/zookeeper/KEYS && \
wget -q https://www.apache.org/dist/zookeeper/zookeeper-${ZOOKEEPER_VERSION}/zookeeper-${ZOOKEEPER_VERSION}.tar.gz.asc && \
wget -q https://www.apache.org/dist/zookeeper/zookeeper-${ZOOKEEPER_VERSION}/zookeeper-${ZOOKEEPER_VERSION}.tar.gz.md5

#Verify download
RUN md5sum -c zookeeper-${ZOOKEEPER_VERSION}.tar.gz.md5 && \
gpg --import KEYS && \
gpg --verify zookeeper-${ZOOKEEPER_VERSION}.tar.gz.asc

#Install
RUN tar -xzf zookeeper-${ZOOKEEPER_VERSION}.tar.gz -C /opt

#Configure
RUN mv /opt/zookeeper-${ZOOKEEPER_VERSION}/conf/zoo_sample.cfg /opt/zookeeper-${ZOOKEEPER_VERSION}/conf/zoo.cfg

ENV JAVA_HOME /usr/lib/jvm/java-7-openjdk-amd64
ENV ZK_HOME /opt/zookeeper-${ZOOKEEPER_VERSION}
ARG java_version=11-jre-slim

FROM openjdk:${java_version}

ARG zookeeper_version=3.7.0
ARG vcs_ref=unspecified
ARG build_date=unspecified

LABEL org.label-schema.name="zookeeper" \
org.label-schema.description="Apache Zookeeper" \
org.label-schema.build-date="${build_date}" \
org.label-schema.vcs-url="https://github.com/wurstmeister/zookeeper-docker" \
org.label-schema.vcs-ref="${vcs_ref}" \
org.label-schema.version="${java_version}_${zookeeper_version}}" \
org.label-schema.schema-version="1.0" \
maintainer="wurstmeister"

ENV ZOOKEEPER_VERSION=$zookeeper_version

# Install deps
RUN apt-get update && apt-get install -y \
wget \
gnupg \
ssh \
&& mkdir -p /run/sshd \
&& rm -rf /var/lib/apt/lists/*

# Download Zookeeper
RUN wget -q https://mirror.vorboss.net/apache/zookeeper/zookeeper-${ZOOKEEPER_VERSION}/apache-zookeeper-${ZOOKEEPER_VERSION}-bin.tar.gz && \
wget -q https://www.apache.org/dist/zookeeper/KEYS && \
wget -q https://downloads.apache.org/zookeeper/zookeeper-${ZOOKEEPER_VERSION}/apache-zookeeper-${ZOOKEEPER_VERSION}-bin.tar.gz.asc && \
wget -q https://downloads.apache.org/zookeeper/zookeeper-${ZOOKEEPER_VERSION}/apache-zookeeper-${ZOOKEEPER_VERSION}-bin.tar.gz.sha512

# Verify download
RUN sha512sum -c apache-zookeeper-${ZOOKEEPER_VERSION}-bin.tar.gz.sha512 && \
gpg --import KEYS && \
gpg --verify apache-zookeeper-${ZOOKEEPER_VERSION}-bin.tar.gz.asc

# Install
RUN tar -xzf apache-zookeeper-${ZOOKEEPER_VERSION}-bin.tar.gz -C /opt && \
mv /opt/apache-zookeeper-${ZOOKEEPER_VERSION}-bin /opt/zookeeper

# Configure
RUN mv /opt/zookeeper/conf/zoo_sample.cfg /opt/zookeeper/conf/zoo.cfg

ENV ZK_HOME /opt/zookeeper
RUN sed -i "s|/tmp/zookeeper|$ZK_HOME/data|g" $ZK_HOME/conf/zoo.cfg; mkdir $ZK_HOME/data

ADD start-zk.sh /usr/bin/start-zk.sh
EXPOSE 2181 2888 3888

WORKDIR /opt/zookeeper-${ZOOKEEPER_VERSION}
VOLUME ["/opt/zookeeper-${ZOOKEEPER_VERSION}/conf", "/opt/zookeeper-${ZOOKEEPER_VERSION}/data"]
WORKDIR /opt/zookeeper
VOLUME ["/opt/zookeeper/conf", "/opt/zookeeper/data"]

CMD /usr/sbin/sshd && bash /usr/bin/start-zk.sh
32 changes: 32 additions & 0 deletions docker_buildx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#!/bin/bash -e

# Build for amd64 and arm64
PLATFORMS="linux/amd64,linux/arm64"

EXTRA_BUILDX_ARGS=$@
CACHE_LOCATION="/tmp/docker-cache"

if [[ "${EXTRA_BUILDX_ARGS}" == *"--load"* ]]; then
# We have to load the image for the current architecture only in order to run tests, so let's
# pull FROM the multi-arch build that happened previously
PLATFORMS="linux/${TRAVIS_CPU_ARCH}"
CACHE="--cache-from=type=local,src=${CACHE_LOCATION}"
elif [[ "${EXTRA_BUILDX_ARGS}" == *"--push"* ]]; then
# Push ALL architectures FROM the multi-arch build cache that happened previously
CACHE="--cache-from=type=local,src=${CACHE_LOCATION}"
else
# This is the multi-arch build that we should cache and use later
CACHE="--cache-to=type=local,dest=${CACHE_LOCATION}"
fi

docker buildx build \
$CACHE \
--platform "${PLATFORMS}" \
--progress=plain \
--build-arg zookeeper_version=$ZOOKEEPER_VERSION \
--build-arg java_version=$JAVA_VERSION \
--build-arg vcs_ref=$TRAVIS_COMMIT \
--build-arg build_date=$(date -u +"%Y-%m-%dT%H:%M:%SZ") \
-t wurstmeister/zookeeper \
$EXTRA_BUILDX_ARGS \
.
15 changes: 15 additions & 0 deletions docker_push
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
!/bin/bash -e

BASE_IMAGE="wurstmeister/zookeeper"
IMAGE_VERSION="$1"

if [ -z "$IMAGE_VERSION" ]; then
echo "No IMAGE_VERSION var specified"
exit 1
fi

echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
TARGET="$BASE_IMAGE:$IMAGE_VERSION"
bash docker_buildx \
-t "$TARGET" \
--push
2 changes: 1 addition & 1 deletion start-zk.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
sed -i -r 's|#(log4j.appender.ROLLINGFILE.MaxBackupIndex.*)|\1|g' $ZK_HOME/conf/log4j.properties
sed -i -r 's|#autopurge|autopurge|g' $ZK_HOME/conf/zoo.cfg

/opt/zookeeper-3.4.13/bin/zkServer.sh start-foreground
/opt/zookeeper/bin/zkServer.sh start-foreground
21 changes: 21 additions & 0 deletions test/verifyImageLabels.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

#!/bin/bash -e

VCS_REF=$(docker inspect -f '{{ index .Config.Labels "org.label-schema.vcs-ref"}}' wurstmeister/zookeeper)
echo "VCS_REF=$VCS_REF"
if [ -z "$VCS_REF" ] || [ "$VCS_REF" = "unspecified" ]; then
echo "org.label-schema.vcs-ref is empty or unspecified"
exit 1
fi
if ! git cat-file -e "$VCS_REF^{commit}"; then
echo "$VCS_REF Not a valid git commit"
exit 1
fi

BUILD_DATE=$(docker inspect -f '{{ index .Config.Labels "org.label-schema.build-date"}}' wurstmeister/zookeeper)
echo "BUILD_DATE=$BUILD_DATE"
if ! date -d "$BUILD_DATE"; then
echo "$BUILD_DATE Not a valid date"
exit 1
fi
exit 0

0 comments on commit 49d77c8

Please sign in to comment.