Skip to content

Commit 0efae8f

Browse files
sscalingwurstmeister
authored andcommitted
Build docker images from travis-ci (wurstmeister#335)
* Fix up downloading binaries < 0.11 * Update kafkacat tests to account for older broker versions Fixes wurstmeister#163 Fixes wurstmeister#324 Fixes wurstmeister#210 Fixes wurstmeister#231 Fixes wurstmeister#210
1 parent 8582140 commit 0efae8f

14 files changed

+176
-47
lines changed

.travis.yml

+57-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,52 @@
11
sudo: required
22

3-
language: java
3+
language: scala
44

55
services:
66
- docker
77

8+
# An alternative approach is to build a full matrix.
9+
#scala:
10+
# - "2.10"
11+
# - 2.11
12+
#
13+
#env:
14+
# - KAFKA_VERSION=0.8.2.2
15+
# - KAFKA_VERSION=0.9.0.1
16+
# - KAFKA_VERSION=0.10.2.1
17+
# - KAFKA_VERSION=0.11.0.2
18+
# - KAFKA_VERSION=1.0.1
19+
# - KAFKA_VERSION=1.1.0
20+
21+
# This version will be also tagged as 'latest'
22+
env:
23+
global:
24+
- LATEST="2.11-1.1.0"
25+
26+
# Build recommended versions based on: http://kafka.apache.org/downloads
27+
matrix:
28+
include:
29+
- scala: "2.10"
30+
env: KAFKA_VERSION=0.8.2.2
31+
- scala: 2.11
32+
env: KAFKA_VERSION=0.9.0.1
33+
- scala: 2.11
34+
env: KAFKA_VERSION=0.10.2.1
35+
- scala: 2.11
36+
env: KAFKA_VERSION=0.11.0.2
37+
- scala: 2.11
38+
env: KAFKA_VERSION=1.0.1
39+
- scala: 2.11
40+
env: KAFKA_VERSION=1.1.0
41+
842
install:
943
- docker --version
1044
- docker-compose --version
11-
- docker build -t wurstmeister/kafka .
45+
- echo "KAFKA VERSION $KAFKA_VERSION"
46+
- echo "SCALA VERSION $TRAVIS_SCALA_VERSION"
47+
- echo "LATEST VERSION $LATEST"
48+
- export CURRENT=${TRAVIS_SCALA_VERSION}-${KAFKA_VERSION}
49+
- docker build --build-arg kafka_version=$KAFKA_VERSION --build-arg scala_version=$TRAVIS_SCALA_VERSION -t wurstmeister/kafka .
1250
- docker pull confluentinc/cp-kafkacat
1351

1452
before_script:
@@ -17,15 +55,30 @@ before_script:
1755

1856
script:
1957
# Shellcheck main source files
20-
- shellcheck -s bash broker-list.sh create-topics.sh start-kafka.sh download-kafka.sh
58+
- shellcheck -s bash broker-list.sh create-topics.sh start-kafka.sh download-kafka.sh versions.sh
2159
- cd test
2260
# Shellcheck the tests
23-
- shellcheck -x -e SC1090 -s bash *sh
61+
- shellcheck -x -e SC1090 -s bash *.sh **/*.sh
2462
- sleep 5 # Wait for containers to start
63+
- docker ps -a
2564
- ./runAllTests.sh
2665
# End-to-End scenario tests
2766
- cd scenarios
2867
- ./runJmxScenario.sh
2968

3069
after_script:
3170
- docker-compose stop
71+
72+
# This will deploy from master. Might want to have a single release branch for a little more control
73+
deploy:
74+
- provider: script
75+
script: bash docker_push latest
76+
on:
77+
repo: wurstmeister/kafka-docker
78+
branch: master
79+
condition: $CURRENT = $LATEST
80+
- provider: script
81+
script: bash docker_push "${TRAVIS_SCALA_VERSION}-${KAFKA_VERSION}"
82+
on:
83+
repo: wurstmeister/kafka-docker
84+
# branch: release

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ ENV KAFKA_VERSION=$kafka_version \
1313

1414
ENV PATH=${PATH}:${KAFKA_HOME}/bin
1515

16-
COPY download-kafka.sh start-kafka.sh broker-list.sh create-topics.sh /tmp/
16+
COPY download-kafka.sh start-kafka.sh broker-list.sh create-topics.sh versions.sh /tmp/
1717

1818
RUN apk add --no-cache bash curl jq docker \
1919
&& mkdir /opt \
2020
&& chmod a+x /tmp/*.sh \
21-
&& mv /tmp/start-kafka.sh /tmp/broker-list.sh /tmp/create-topics.sh /usr/bin \
21+
&& mv /tmp/start-kafka.sh /tmp/broker-list.sh /tmp/create-topics.sh /tmp/versions.sh /usr/bin \
2222
&& sync && /tmp/download-kafka.sh \
2323
&& tar xfz /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt \
2424
&& rm /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz \

README.md

+15
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,25 @@ Dockerfile for [Apache Kafka](http://kafka.apache.org/)
1111

1212
The image is available directly from [Docker Hub](https://hub.docker.com/r/wurstmeister/kafka/)
1313

14+
Tags and releases
15+
-----------------
16+
17+
All versions of the image are built from the same set of scripts with only minor variations (i.e. certain features are not supported on older versions). The version format mirrors the Kafka format, `<scala version>-<kafka version>`. Initially, all images are built with the recommended version of scala documented on [http://kafka.apache.org/downloads](http://kafka.apache.org/downloads). Available tags are:
18+
19+
- `2.11-1.1.0`
20+
- `2.11-1.0.1`
21+
- `2.11-0.11.0.2`
22+
- `2.11-0.10.2.1`
23+
- `2.11-0.9.0.1`
24+
- `2.10-0.8.2.2`
25+
26+
Everytime the image is updated, all tags will be pushed with the latest updates. This should allow for greater consistency across tags, as well as any security updates that have been made to the base image.
27+
1428
---
1529

1630
## Announcements
1731

32+
* **28-May-2018** - New docker image tag format - see Readme.
1833
* **03-Apr-2018** - *BREAKING* - `KAFKA_ADVERTISED_PROTOCOL_NAME` and `KAFKA_PROTOCOL_NAME` removed. Please update to canonical kafka settings.
1934
* **03-Apr-2018** - *BREAKING* - `KAFKA_ZOOKEEPER_CONNECT` is now a mandatory environment var.
2035

create-topics.sh

+9-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ if $start_timeout_exceeded; then
2626
exit 1
2727
fi
2828

29+
# introduced in 0.10. In earlier versions, this will fail because the topic already exists.
30+
# shellcheck disable=SC1091
31+
source "/usr/bin/versions.sh"
32+
if [[ "$MAJOR_VERSION" == "0" && "$MINOR_VERSION" -gt "9" ]] || [[ "$MAJOR_VERSION" -gt "0" ]]; then
33+
KAFKA_0_10_OPTS="--if-not-exists"
34+
fi
35+
2936
# Expected format:
3037
# name:partitions:replicas:cleanup.policy
3138
IFS="${KAFKA_CREATE_TOPICS_SEPARATOR-,}"; for topicToCreate in $KAFKA_CREATE_TOPICS; do
@@ -35,14 +42,15 @@ IFS="${KAFKA_CREATE_TOPICS_SEPARATOR-,}"; for topicToCreate in $KAFKA_CREATE_TOP
3542
if [ -n "${topicConfig[3]}" ]; then
3643
config="--config=cleanup.policy=${topicConfig[3]}"
3744
fi
45+
3846
COMMAND="JMX_PORT='' ${KAFKA_HOME}/bin/kafka-topics.sh \\
3947
--create \\
4048
--zookeeper ${KAFKA_ZOOKEEPER_CONNECT} \\
4149
--topic ${topicConfig[0]} \\
4250
--partitions ${topicConfig[1]} \\
4351
--replication-factor ${topicConfig[2]} \\
4452
${config} \\
45-
--if-not-exists &"
53+
${KAFKA_0_10_OPTS} &"
4654
eval "${COMMAND}"
4755
done
4856

docker_push

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash -e
2+
3+
BASE_IMAGE="wurstmeister/kafka"
4+
IMAGE_VERSION="$1"
5+
6+
if [ -z "$IMAGE_VERSION" ]; then
7+
echo "No IMAGE_VERSION var specified"
8+
exit 1
9+
fi
10+
11+
echo "$DOCKER_PASSWORD" | docker login -u "$DOCKER_USERNAME" --password-stdin
12+
TARGET="$BASE_IMAGE:$IMAGE_VERSION"
13+
docker tag "$BASE_IMAGE" "$TARGET"
14+
docker push "$TARGET"

download-kafka.sh

+15-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,23 @@
11
#!/bin/sh -e
22

3-
path="kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz"
4-
url=$(curl --stderr /dev/null "https://www.apache.org/dyn/closer.cgi?path=/${path}&as_json=1" | jq -r '"\(.preferred)\(.path_info)"')
3+
# shellcheck disable=SC1091
4+
source "/usr/bin/versions.sh"
5+
6+
FILENAME="kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz"
7+
8+
## Versions prior to 0.10.2.1 are not actively mirrored
9+
echo "Downloading kafka $MAJOR_VERSION.$MINOR_VERSION"
10+
if [[ "$MAJOR_VERSION" == "0" && "$MINOR_VERSION" -lt "11" ]]; then
11+
echo "Version prior to 0.10.2.1 - downloading direct"
12+
url="https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/${FILENAME}"
13+
else
14+
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)"')
15+
fi
516

617
if [[ -z "$url" ]]; then
718
echo "Unable to determine mirror for downloading Kafka, the service may be down"
819
exit 1
920
fi
1021

11-
wget -q "${url}" -O "/tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz"
22+
echo "Downloading Kafka from $url"
23+
wget "${url}" -O "/tmp/${FILENAME}"

start-kafka.sh

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ fi
2222
create-topics.sh &
2323
unset KAFKA_CREATE_TOPICS
2424

25-
# DEPRECATED: but maintained for compatibility with older brokers pre 0.9.0 (https://issues.apache.org/jira/browse/KAFKA-1809)
2625
if [[ -z "$KAFKA_ADVERTISED_PORT" && \
2726
-z "$KAFKA_LISTENERS" && \
2827
-z "$KAFKA_ADVERTISED_LISTENERS" && \

test/0.0/test.read-write.kafkacat.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash -e
22

3+
source version.functions
4+
35
testReadWrite() {
4-
echo 'foo,bar' | kafkacat -b "$BROKER_LIST" -P -D, -t readwrite
5-
kafkacat -b "$BROKER_LIST" -C -e -t readwrite
6+
echo 'foo,bar' | eval "kafkacat -b $BROKER_LIST $KAFKACAT_OPTS -P -D, -t readwrite"
7+
eval "kafkacat -b $BROKER_LIST $KAFKACAT_OPTS -C -e -t readwrite"
68
}
79

810
testReadWrite

test/0.9/test.snappy.kafkacat.sh

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash -e
22

3+
source version.functions
4+
35
testSnappy() {
4-
echo 'foo,bar' | kafkacat -X compression.codec=snappy -b "$BROKER_LIST" -P -D, -t snappy
5-
kafkacat -X compression.codec=snappy -b "$BROKER_LIST" -C -e -t snappy
6+
echo 'foo,bar' | eval "kafkacat -X compression.codec=snappy -b $BROKER_LIST $KAFKACAT_OPTS -P -D, -t snappy"
7+
eval "kafkacat -X compression.codec=snappy -b $BROKER_LIST $KAFKACAT_OPTS -C -e -t snappy"
68
}
79

810
testSnappy

test/docker-compose.yml

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ services:
99
ports:
1010
- "9092"
1111
environment:
12-
KAFKA_LISTENERS: PLAINTEXT://:9092
12+
HOSTNAME_COMMAND: "echo $$(hostname)"
13+
KAFKA_ADVERTISED_PORT: 9092
14+
KAFKA_PORT: 9092
15+
BROKER_ID_COMMAND: "docker inspect --format '{{ .Name }}' $$(hostname) | awk -F_ '{ printf $$NF }'"
1316
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
1417
volumes:
1518
- /var/run/docker.sock:/var/run/docker.sock
@@ -31,13 +34,12 @@ services:
3134
kafkacattest:
3235
image: confluentinc/cp-kafkacat
3336
environment:
34-
BROKER_LIST: ${BROKER_LIST}
37+
- BROKER_LIST
38+
- KAFKA_VERSION=${KAFKA_VERSION-1.1.0}
3539
volumes:
3640
- .:/tests
3741
working_dir: /tests
3842
entrypoint:
3943
- ./runTestPattern.sh
4044
command:
41-
- -v
42-
- ${KAFKA_VERSION-1.1.0}
4345
- "*/*.kafkacat.sh"

test/runTestPattern.sh

+2-27
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash -e
22

3+
source version.functions
4+
35
PATTERN=$1
46
VERSION=$KAFKA_VERSION
57

@@ -21,32 +23,6 @@ echo ""
2123
echo ""
2224
echo "Running tests for Kafka $VERSION with pattern $PATTERN"
2325

24-
# Modified from https://stackoverflow.com/a/4025065
25-
compareVersion() {
26-
# Only care about major / minor
27-
LEFT=$(echo "$1" | cut -d. -f1-2)
28-
RIGHT=$(echo "$2" | cut -d. -f1-2)
29-
if [[ "$LEFT" != "$RIGHT" ]]
30-
then
31-
local IFS=.
32-
local i ver1=($LEFT) ver2=($RIGHT)
33-
for ((i=0; i<${#ver1[@]}; i++))
34-
do
35-
if (( "${ver1[i]}" > "${ver2[i]}" ))
36-
then
37-
echo ">"
38-
return
39-
fi
40-
if (( "${ver1[i]}" < "${ver2[i]}" ))
41-
then
42-
echo "<"
43-
return
44-
fi
45-
done
46-
fi
47-
echo "="
48-
}
49-
5026
runPattern() {
5127
for t in $PATTERN; do
5228
echo
@@ -58,7 +34,6 @@ runPattern() {
5834
echo "Kafka $VERSION is '$RESULT' target $TARGET of test $t"
5935
if [[ "$RESULT" != "<" ]]; then
6036
echo " testing '$t'"
61-
# shellcheck disable=SC1090
6237
( source "$t" )
6338
status=$?
6439
if [[ -z "$status" || ! "$status" -eq 0 ]]; then

test/scenarios/jmx/docker-compose.yml

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ services:
1010
- "9092"
1111
- "1099"
1212
environment:
13-
KAFKA_LISTENERS: PLAINTEXT://kafka:9092
13+
KAFKA_ADVERTISED_HOST_NAME: kafka
14+
KAFKA_ADVERTISED_PORT: 9092
15+
KAFKA_PORT: 9092
16+
BROKER_ID_COMMAND: "docker inspect --format '{{ .Name }}' $$(hostname) | awk -F_ '{ printf $$NF }'"
1417
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
1518
KAFKA_JMX_OPTS: "-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false -Djava.rmi.server.hostname=kafka -Dcom.sun.management.jmxremote.rmi.port=1099"
1619
JMX_PORT: 1099

test/version.functions

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/bin/bash -e
2+
3+
# Modified from https://stackoverflow.com/a/4025065
4+
compareVersion() {
5+
# Only care about major / minor
6+
LEFT=$(echo "$1" | cut -d. -f1-2)
7+
RIGHT=$(echo "$2" | cut -d. -f1-2)
8+
if [[ "$LEFT" != "$RIGHT" ]]
9+
then
10+
local IFS=.
11+
local i ver1=($LEFT) ver2=($RIGHT)
12+
for ((i=0; i<${#ver1[@]}; i++))
13+
do
14+
if (( "${ver1[i]}" > "${ver2[i]}" ))
15+
then
16+
echo ">"
17+
return
18+
fi
19+
if (( "${ver1[i]}" < "${ver2[i]}" ))
20+
then
21+
echo "<"
22+
return
23+
fi
24+
done
25+
fi
26+
echo "="
27+
}
28+
29+
# https://github.com/edenhill/librdkafka/wiki/Broker-version-compatibility
30+
# To support different broker versions, we need to configure kafkacat differently
31+
VERSION_8=$(compareVersion "$KAFKA_VERSION" "0.8")
32+
VERSION_9=$(compareVersion "$KAFKA_VERSION" "0.9")
33+
34+
if [[ "$VERSION_8" == "=" || "$VERSION_9" == "=" ]]; then
35+
export KAFKACAT_OPTS="-Xapi.version.request=false -Xbroker.version.fallback=$KAFKA_VERSION"
36+
echo "[INFO] Using kafkacat opts on older version '$KAFKACAT_OPTS'"
37+
fi

versions.sh

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash -e
2+
3+
MAJOR_VERSION=$(echo "$KAFKA_VERSION" | cut -d. -f1)
4+
export MAJOR_VERSION
5+
6+
MINOR_VERSION=$(echo "$KAFKA_VERSION" | cut -d. -f2)
7+
export MINOR_VERSION

0 commit comments

Comments
 (0)