Skip to content

Commit f746d67

Browse files
authored
KAFKA-16373: KIP-1028: Adding 3.7.0 docker official images static assets (apache#16267)
This PR aims to add the static Dockerfile and scripts for AK 3.7.0 version. As mentioned in KIP-1028 this PR aims to start the release of the kafka:3.7.0 Docker Official image. This will also help us validate the process and allow us to address any changes suggested by Dockerhub before the 3.8.0 release. The static Dockerfile and scripts have been generated via the github actions workflows and scripts added as part of apache#16027. The reports of build and testing the 3.7.0 Docker official image are below. Reviewers: Manikumar Reddy <[email protected]>, Vedarth Sharma <[email protected]>
1 parent 99eacf1 commit f746d67

File tree

7 files changed

+422
-0
lines changed

7 files changed

+422
-0
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
###############################################################################
2+
# Licensed to the Apache Software Foundation (ASF) under one
3+
# or more contributor license agreements. See the NOTICE file
4+
# distributed with this work for additional information
5+
# regarding copyright ownership. The ASF licenses this file
6+
# to you under the Apache License, Version 2.0 (the
7+
# "License"); you may not use this file except in compliance
8+
# with the License. You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
###############################################################################
18+
19+
FROM eclipse-temurin:21-jre-alpine AS build-jsa
20+
21+
USER root
22+
23+
# Get Kafka from https://downloads.apache.org/kafka, url passed as env var, for version 3.7.0
24+
ENV kafka_url https://downloads.apache.org/kafka/3.7.0/kafka_2.13-3.7.0.tgz
25+
26+
COPY jsa_launch /etc/kafka/docker/jsa_launch
27+
28+
RUN set -eux ; \
29+
apk update ; \
30+
apk upgrade ; \
31+
apk add --no-cache wget gcompat gpg gpg-agent procps bash; \
32+
mkdir opt/kafka; \
33+
wget -nv -O kafka.tgz "$kafka_url"; \
34+
wget -nv -O kafka.tgz.asc "$kafka_url.asc"; \
35+
tar xfz kafka.tgz -C /opt/kafka --strip-components 1; \
36+
wget -nv -O KEYS https://downloads.apache.org/kafka/KEYS; \
37+
gpg --import KEYS; \
38+
gpg --batch --verify kafka.tgz.asc kafka.tgz
39+
40+
# Generate jsa files using dynamic CDS for kafka server start command and kafka storage format command
41+
RUN /etc/kafka/docker/jsa_launch
42+
43+
44+
FROM eclipse-temurin:21-jre-alpine
45+
46+
# exposed ports
47+
EXPOSE 9092
48+
49+
USER root
50+
51+
# Get Kafka from https://downloads.apache.org/kafka, url passed as env var, for version 3.7.0
52+
ENV kafka_url https://downloads.apache.org/kafka/3.7.0/kafka_2.13-3.7.0.tgz
53+
ENV build_date 2024-06-10
54+
55+
56+
LABEL org.label-schema.name="kafka" \
57+
org.label-schema.description="Apache Kafka" \
58+
org.label-schema.build-date="${build_date}" \
59+
org.label-schema.vcs-url="https://github.com/apache/kafka" \
60+
maintainer="Apache Kafka"
61+
62+
RUN set -eux ; \
63+
apk update ; \
64+
apk upgrade ; \
65+
apk add --no-cache wget gcompat gpg gpg-agent procps bash; \
66+
mkdir opt/kafka; \
67+
wget -nv -O kafka.tgz "$kafka_url"; \
68+
wget -nv -O kafka.tgz.asc "$kafka_url.asc"; \
69+
tar xfz kafka.tgz -C /opt/kafka --strip-components 1; \
70+
wget -nv -O KEYS https://downloads.apache.org/kafka/KEYS; \
71+
gpg --import KEYS; \
72+
gpg --batch --verify kafka.tgz.asc kafka.tgz; \
73+
mkdir -p /var/lib/kafka/data /etc/kafka/secrets; \
74+
mkdir -p /etc/kafka/docker /usr/logs /mnt/shared/config; \
75+
adduser -h /home/appuser -D --shell /bin/bash appuser; \
76+
chown appuser:appuser -R /usr/logs /opt/kafka /mnt/shared/config; \
77+
chown appuser:root -R /var/lib/kafka /etc/kafka/secrets /etc/kafka; \
78+
chmod -R ug+w /etc/kafka /var/lib/kafka /etc/kafka/secrets; \
79+
cp /opt/kafka/config/log4j.properties /etc/kafka/docker/log4j.properties; \
80+
cp /opt/kafka/config/tools-log4j.properties /etc/kafka/docker/tools-log4j.properties; \
81+
cp /opt/kafka/config/kraft/server.properties /etc/kafka/docker/server.properties; \
82+
rm kafka.tgz kafka.tgz.asc KEYS; \
83+
apk del wget gpg gpg-agent; \
84+
apk cache clean;
85+
86+
COPY --from=build-jsa kafka.jsa /opt/kafka/kafka.jsa
87+
COPY --from=build-jsa storage.jsa /opt/kafka/storage.jsa
88+
COPY --chown=appuser:appuser resources/common-scripts /etc/kafka/docker
89+
COPY --chown=appuser:appuser launch /etc/kafka/docker/launch
90+
91+
USER appuser
92+
93+
VOLUME ["/etc/kafka/secrets", "/var/lib/kafka/data", "/mnt/shared/config"]
94+
95+
CMD ["/etc/kafka/docker/run"]
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
KAFKA_CLUSTER_ID="$(opt/kafka/bin/kafka-storage.sh random-uuid)"
18+
TOPIC="test-topic"
19+
20+
KAFKA_JVM_PERFORMANCE_OPTS="-XX:ArchiveClassesAtExit=storage.jsa" opt/kafka/bin/kafka-storage.sh format -t $KAFKA_CLUSTER_ID -c opt/kafka/config/kraft/server.properties
21+
22+
KAFKA_JVM_PERFORMANCE_OPTS="-XX:ArchiveClassesAtExit=kafka.jsa" opt/kafka/bin/kafka-server-start.sh opt/kafka/config/kraft/server.properties &
23+
24+
check_timeout() {
25+
if [ $TIMEOUT -eq 0 ]; then
26+
echo "Server startup timed out"
27+
exit 1
28+
fi
29+
echo "Check will timeout in $(( TIMEOUT-- )) seconds"
30+
sleep 1
31+
}
32+
33+
opt/kafka/bin/kafka-topics.sh --create --topic $TOPIC --bootstrap-server localhost:9092
34+
[ $? -eq 0 ] || exit 1
35+
36+
echo "test" | opt/kafka/bin/kafka-console-producer.sh --topic $TOPIC --bootstrap-server localhost:9092
37+
[ $? -eq 0 ] || exit 1
38+
39+
opt/kafka/bin/kafka-console-consumer.sh --topic $TOPIC --from-beginning --bootstrap-server localhost:9092 --max-messages 1 --timeout-ms 20000
40+
[ $? -eq 0 ] || exit 1
41+
42+
opt/kafka/bin/kafka-server-stop.sh
43+
44+
# Wait until jsa file is generated
45+
TIMEOUT=20
46+
until [ -f /kafka.jsa ]
47+
do
48+
check_timeout
49+
done
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Override this section from the script to include the com.sun.management.jmxremote.rmi.port property.
18+
if [ -z "${KAFKA_JMX_OPTS-}" ]; then
19+
export KAFKA_JMX_OPTS="-Dcom.sun.management.jmxremote=true \
20+
-Dcom.sun.management.jmxremote.authenticate=false \
21+
-Dcom.sun.management.jmxremote.ssl=false "
22+
fi
23+
24+
# The JMX client needs to be able to connect to java.rmi.server.hostname.
25+
# The default for bridged n/w is the bridged IP so you will only be able to connect from another docker container.
26+
# For host n/w, this is the IP that the hostname on the host resolves to.
27+
28+
# If you have more than one n/w configured, hostname -i gives you all the IPs,
29+
# the default is to pick the first IP (or network).
30+
export KAFKA_JMX_HOSTNAME=${KAFKA_JMX_HOSTNAME:-$(hostname -i | cut -d" " -f1)}
31+
32+
if [ "${KAFKA_JMX_PORT-}" ]; then
33+
# This ensures that the "if" section for JMX_PORT in kafka launch script does not trigger.
34+
export JMX_PORT=$KAFKA_JMX_PORT
35+
export KAFKA_JMX_OPTS="${KAFKA_JMX_OPTS-} -Djava.rmi.server.hostname=$KAFKA_JMX_HOSTNAME \
36+
-Dcom.sun.management.jmxremote.local.only=false \
37+
-Dcom.sun.management.jmxremote.rmi.port=$JMX_PORT \
38+
-Dcom.sun.management.jmxremote.port=$JMX_PORT"
39+
fi
40+
41+
# Make a temp env variable to store user provided performance otps
42+
if [ -z "${KAFKA_JVM_PERFORMANCE_OPTS-}" ]; then
43+
export TEMP_KAFKA_JVM_PERFORMANCE_OPTS=""
44+
else
45+
export TEMP_KAFKA_JVM_PERFORMANCE_OPTS="$KAFKA_JVM_PERFORMANCE_OPTS"
46+
fi
47+
48+
# We will first use CDS for storage to format storage
49+
export KAFKA_JVM_PERFORMANCE_OPTS="${KAFKA_JVM_PERFORMANCE_OPTS-} -XX:SharedArchiveFile=/opt/kafka/storage.jsa"
50+
51+
echo "===> Using provided cluster id $CLUSTER_ID ..."
52+
53+
# Invoke the docker wrapper to setup property files and format storage
54+
result=$(/opt/kafka/bin/kafka-run-class.sh kafka.docker.KafkaDockerWrapper setup \
55+
--default-configs-dir /etc/kafka/docker \
56+
--mounted-configs-dir /mnt/shared/config \
57+
--final-configs-dir /opt/kafka/config 2>&1) || \
58+
echo $result | grep -i "already formatted" || \
59+
{ echo $result && (exit 1) }
60+
61+
# Using temp env variable to get rid of storage CDS command
62+
export KAFKA_JVM_PERFORMANCE_OPTS="$TEMP_KAFKA_JVM_PERFORMANCE_OPTS"
63+
64+
# Now we will use CDS for kafka to start kafka server
65+
export KAFKA_JVM_PERFORMANCE_OPTS="$KAFKA_JVM_PERFORMANCE_OPTS -XX:SharedArchiveFile=/opt/kafka/kafka.jsa"
66+
67+
# Start kafka broker
68+
exec /opt/kafka/bin/kafka-server-start.sh /opt/kafka/config/server.properties
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one or more
2+
# contributor license agreements. See the NOTICE file distributed with
3+
# this work for additional information regarding copyright ownership.
4+
# The ASF licenses this file to You under the Apache License, Version 2.0
5+
# (the "License"); you may not use this file except in compliance with
6+
# the License. You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
16+
set -o nounset \
17+
-o errexit
18+
19+
# Trace may expose passwords/credentials by printing them to stdout, so turn on with care.
20+
if [ "${TRACE:-}" == "true" ]; then
21+
set -o verbose \
22+
-o xtrace
23+
fi
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
ensure() {
18+
if [[ -z "${!1}" ]]; then
19+
echo "$1 environment variable not set"
20+
exit 1
21+
fi
22+
}
23+
24+
path() {
25+
if [[ $2 == "writable" ]]; then
26+
if [[ ! -w "$1" ]]; then
27+
echo "$1 file not writable"
28+
exit 1
29+
fi
30+
elif [[ $2 == "existence" ]]; then
31+
if [[ ! -e "$1" ]]; then
32+
echo "$1 file does not exist"
33+
exit 1
34+
fi
35+
fi
36+
}
37+
38+
# unset KAFKA_ADVERTISED_LISTENERS from ENV in KRaft mode when running as controller only
39+
if [[ -n "${KAFKA_PROCESS_ROLES-}" ]]
40+
then
41+
echo "Running in KRaft mode..."
42+
ensure CLUSTER_ID
43+
if [[ $KAFKA_PROCESS_ROLES == "controller" ]]
44+
then
45+
if [[ -n "${KAFKA_ADVERTISED_LISTENERS-}" ]]
46+
then
47+
echo "KAFKA_ADVERTISED_LISTENERS is not supported on a KRaft controller."
48+
exit 1
49+
else
50+
# Unset in case env variable is set with empty value
51+
unset KAFKA_ADVERTISED_LISTENERS
52+
fi
53+
fi
54+
fi
55+
56+
# By default, LISTENERS is derived from ADVERTISED_LISTENERS by replacing
57+
# hosts with 0.0.0.0. This is good default as it ensures that the broker
58+
# process listens on all ports.
59+
if [[ -z "${KAFKA_LISTENERS-}" ]] && ( [[ -z "${KAFKA_PROCESS_ROLES-}" ]] || [[ $KAFKA_PROCESS_ROLES != "controller" ]] ) && [[ -n "${KAFKA_ADVERTISED_LISTENERS-}" ]]
60+
then
61+
export KAFKA_LISTENERS
62+
KAFKA_LISTENERS=$(echo "$KAFKA_ADVERTISED_LISTENERS" | sed -e 's|://[^:]*:|://0.0.0.0:|g')
63+
fi
64+
65+
path /opt/kafka/config/ writable
66+
67+
# Set if ADVERTISED_LISTENERS has SSL:// or SASL_SSL:// endpoints.
68+
if [[ -n "${KAFKA_ADVERTISED_LISTENERS-}" ]] && [[ $KAFKA_ADVERTISED_LISTENERS == *"SSL://"* ]]
69+
then
70+
echo "SSL is enabled."
71+
72+
ensure KAFKA_SSL_KEYSTORE_FILENAME
73+
export KAFKA_SSL_KEYSTORE_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_KEYSTORE_FILENAME"
74+
path "$KAFKA_SSL_KEYSTORE_LOCATION" existence
75+
76+
ensure KAFKA_SSL_KEY_CREDENTIALS
77+
KAFKA_SSL_KEY_CREDENTIALS_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_KEY_CREDENTIALS"
78+
path "$KAFKA_SSL_KEY_CREDENTIALS_LOCATION" existence
79+
export KAFKA_SSL_KEY_PASSWORD
80+
KAFKA_SSL_KEY_PASSWORD=$(cat "$KAFKA_SSL_KEY_CREDENTIALS_LOCATION")
81+
82+
ensure KAFKA_SSL_KEYSTORE_CREDENTIALS
83+
KAFKA_SSL_KEYSTORE_CREDENTIALS_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_KEYSTORE_CREDENTIALS"
84+
path "$KAFKA_SSL_KEYSTORE_CREDENTIALS_LOCATION" existence
85+
export KAFKA_SSL_KEYSTORE_PASSWORD
86+
KAFKA_SSL_KEYSTORE_PASSWORD=$(cat "$KAFKA_SSL_KEYSTORE_CREDENTIALS_LOCATION")
87+
88+
if [[ -n "${KAFKA_SSL_CLIENT_AUTH-}" ]] && ( [[ $KAFKA_SSL_CLIENT_AUTH == *"required"* ]] || [[ $KAFKA_SSL_CLIENT_AUTH == *"requested"* ]] )
89+
then
90+
ensure KAFKA_SSL_TRUSTSTORE_FILENAME
91+
export KAFKA_SSL_TRUSTSTORE_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_TRUSTSTORE_FILENAME"
92+
path "$KAFKA_SSL_TRUSTSTORE_LOCATION" existence
93+
94+
ensure KAFKA_SSL_TRUSTSTORE_CREDENTIALS
95+
KAFKA_SSL_TRUSTSTORE_CREDENTIALS_LOCATION="/etc/kafka/secrets/$KAFKA_SSL_TRUSTSTORE_CREDENTIALS"
96+
path "$KAFKA_SSL_TRUSTSTORE_CREDENTIALS_LOCATION" existence
97+
export KAFKA_SSL_TRUSTSTORE_PASSWORD
98+
KAFKA_SSL_TRUSTSTORE_PASSWORD=$(cat "$KAFKA_SSL_TRUSTSTORE_CREDENTIALS_LOCATION")
99+
fi
100+
fi
101+
102+
# Set if KAFKA_ADVERTISED_LISTENERS has SASL_PLAINTEXT:// or SASL_SSL:// endpoints.
103+
if [[ -n "${KAFKA_ADVERTISED_LISTENERS-}" ]] && [[ $KAFKA_ADVERTISED_LISTENERS =~ .*SASL_.*://.* ]]
104+
then
105+
echo "SASL" is enabled.
106+
107+
ensure KAFKA_OPTS
108+
109+
if [[ ! $KAFKA_OPTS == *"java.security.auth.login.config"* ]]
110+
then
111+
echo "KAFKA_OPTS should contain 'java.security.auth.login.config' property."
112+
fi
113+
fi
114+
115+
if [[ -n "${KAFKA_JMX_OPTS-}" ]]
116+
then
117+
if [[ ! $KAFKA_JMX_OPTS == *"com.sun.management.jmxremote.rmi.port"* ]]
118+
then
119+
echo "KAFKA_OPTS should contain 'com.sun.management.jmxremote.rmi.port' property. It is required for accessing the JMX metrics externally."
120+
fi
121+
fi
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
# Licensed to the Apache Software Foundation (ASF) under one or more
3+
# contributor license agreements. See the NOTICE file distributed with
4+
# this work for additional information regarding copyright ownership.
5+
# The ASF licenses this file to You under the Apache License, Version 2.0
6+
# (the "License"); you may not use this file except in compliance with
7+
# the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
declare -A env_defaults
18+
env_defaults=(
19+
# Replace CLUSTER_ID with a unique base64 UUID using "bin/kafka-storage.sh random-uuid"
20+
["CLUSTER_ID"]="5L6g3nShT-eMCtK--X86sw"
21+
)
22+
23+
for key in "${!env_defaults[@]}"; do
24+
if [[ -z "${!key:-}" ]]; then
25+
echo ${key} not set. Setting it to default value: \"${env_defaults[$key]}\"
26+
export "$key"="${env_defaults[$key]}"
27+
fi
28+
done

0 commit comments

Comments
 (0)