Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCKER] fix controller port #1859

Merged
merged 3 commits into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions docker/docker_build_common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,24 @@ function getRandomPort() {
echo $(($(($RANDOM%10000))+10000))
}


# we need to parse the controller port from pre-defined `VOTERS`
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function is removed within in 9fab2a0.

function generateControllerPort() {
if [[ -n "$VOTERS" ]]; then
port=""
IFS=',' read -ra ADDR <<< "$VOTERS"
for voter in "${ADDR[@]}"; do
if [[ "$voter" == "$NODE_ID"* ]]; then
port=${voter##*:}
break
fi
done
echo "$port"
else
echo "$(getRandomPort)"
fi
}

# don't change the length as it is expected 16 bytes of a base64-encoded UUID
function randomString() {
echo $(cat /dev/random | env LC_CTYPE=C tr -dc 'a-zA-Z0-9' | fold -w 22 | head -n 1)
Expand Down
6 changes: 3 additions & 3 deletions docker/start_broker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ source $DOCKER_FOLDER/docker_build_common.sh
declare -r ACCOUNT=${ACCOUNT:-opensource4you}
declare -r VERSION=${VERSION:-main}
declare -r KAFKA_ACCOUNT=${KAFKA_ACCOUNT:-apache}
declare -r KAFKA_VERSION=${KAFKA_REVISION:-${KAFKA_VERSION:-3.8.1}}
declare -r KAFKA_VERSION=${KAFKA_REVISION:-${KAFKA_VERSION:-3.9.0}}
declare -r DOCKERFILE=$DOCKER_FOLDER/broker.dockerfile
declare -r DATA_FOLDER_IN_CONTAINER_PREFIX="/tmp/log-folder"
declare -r EXPORTER_VERSION="0.16.1"
Expand Down Expand Up @@ -65,7 +65,7 @@ function showHelp() {
echo " ACCOUNT=opensource4you set the github account for astraea repo"
echo " HEAP_OPTS=\"-Xmx2G -Xms2G\" set broker JVM memory"
echo " KAFKA_REVISION=trunk set revision of kafka source code to build container"
echo " KAFKA_VERSION=3.8.1 set version of kafka distribution"
echo " KAFKA_VERSION=3.9.0 set version of kafka distribution"
echo " BUILD=false set true if you want to build image locally"
echo " RUN=false set false if you want to build/pull image only"
echo " DATA_FOLDERS=/tmp/folder1 set host folders used by broker"
Expand Down Expand Up @@ -124,7 +124,7 @@ function generateDockerfileByVersion() {
local kafka_url="https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_2.13-${KAFKA_VERSION}.tgz"
local version=$KAFKA_VERSION
if [[ "$KAFKA_VERSION" == *"rc"* ]]; then
## `3.8.1-rc1` the rc release does not exist in archive repo
## `3.9.0-rc1` the rc release does not exist in archive repo
version=${KAFKA_VERSION%-*}
kafka_url="https://dist.apache.org/repos/dist/dev/kafka/${KAFKA_VERSION}/kafka_2.13-${version}.tgz"
fi
Expand Down
27 changes: 16 additions & 11 deletions docker/start_controller.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,13 @@ source $DOCKER_FOLDER/docker_build_common.sh
# ===============================[global variables]===============================
declare -r ACCOUNT=${ACCOUNT:-opensource4you}
declare -r KAFKA_ACCOUNT=${KAFKA_ACCOUNT:-apache}
declare -r KAFKA_VERSION=${KAFKA_REVISION:-${KAFKA_VERSION:-3.8.1}}
declare -r KAFKA_VERSION=${KAFKA_REVISION:-${KAFKA_VERSION:-3.9.0}}
declare -r DOCKERFILE=$DOCKER_FOLDER/controller.dockerfile
declare -r EXPORTER_VERSION="0.16.1"
declare -r CLUSTER_ID=${CLUSTER_ID:-"$(randomString)"}
declare -r EXPORTER_PORT=${EXPORTER_PORT:-"$(getRandomPort)"}
declare -r NODE_ID=${NODE_ID:-"$(getRandomPort)"}
declare -r VOTERS=${VOTERS:-""}
declare -r CONTROLLER_PORT=${CONTROLLER_PORT:-"$(generateControllerPort)"}
declare -r CONTAINER_NAME="controller-$CONTROLLER_PORT"
declare -r CONTROLLER_JMX_PORT="${CONTROLLER_JMX_PORT:-"$(getRandomPort)"}"
Expand Down Expand Up @@ -53,7 +54,7 @@ function showHelp() {
echo " ACCOUNT=opensource4you set the github account for astraea repo"
echo " HEAP_OPTS=\"-Xmx2G -Xms2G\" set controller JVM memory"
echo " KAFKA_REVISION=trunk set revision of kafka source code to build container"
echo " KAFKA_VERSION=3.8.1 set version of kafka distribution"
echo " KAFKA_VERSION=3.9.0 set version of kafka distribution"
echo " BUILD=false set true if you want to build image locally"
echo " RUN=false set false if you want to build/pull image only"
echo " META_FOLDER=/tmp/folder1 set host folder used by controller"
Expand Down Expand Up @@ -102,7 +103,7 @@ function generateDockerfileByVersion() {
local kafka_url="https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_2.13-${KAFKA_VERSION}.tgz"
local version=$KAFKA_VERSION
if [[ "$KAFKA_VERSION" == *"rc"* ]]; then
## `3.8.1-rc1` the rc release does not exist in archive repo
## `3.9.0-rc1` the rc release does not exist in archive repo
version=${KAFKA_VERSION%-*}
kafka_url="https://dist.apache.org/repos/dist/dev/kafka/${KAFKA_VERSION}/kafka_2.13-${version}.tgz"
fi
Expand Down Expand Up @@ -244,11 +245,15 @@ docker run -d --init \
-p $EXPORTER_PORT:$EXPORTER_PORT \
"$IMAGE_NAME" sh -c "./bin/kafka-storage.sh format -t $CLUSTER_ID $release_version -c /tmp/controller.properties --standalone --ignore-formatted && ./bin/kafka-server-start.sh /tmp/controller.properties"

echo "================================================="
[[ -n "$META_FOLDER" ]] && echo "mount $META_FOLDER to container: $CONTAINER_NAME"
echo "controller address: ${ADDRESS}:$CONTROLLER_PORT"
echo "jmx address: ${ADDRESS}:$CONTROLLER_JMX_PORT"
echo "exporter address: ${ADDRESS}:$EXPORTER_PORT"
echo "================================================="
echo "run CLUSTER_ID=$CLUSTER_ID $DOCKER_FOLDER/start_broker.sh controller.quorum.bootstrap.servers=${ADDRESS}:$CONTROLLER_PORT to join broker"
echo "================================================="
if [ "$(echo $?)" -eq 0 ]; then
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add error check.

echo "================================================="
[[ -n "$META_FOLDER" ]] && echo "mount $META_FOLDER to container: $CONTAINER_NAME"
echo "controller address: ${ADDRESS}:$CONTROLLER_PORT"
echo "jmx address: ${ADDRESS}:$CONTROLLER_JMX_PORT"
echo "exporter address: ${ADDRESS}:$EXPORTER_PORT"
echo "================================================="
echo "run CLUSTER_ID=$CLUSTER_ID $DOCKER_FOLDER/start_broker.sh controller.quorum.bootstrap.servers=${ADDRESS}:$CONTROLLER_PORT to join broker"
echo "================================================="
else
echo "Start up fail"
fi
6 changes: 3 additions & 3 deletions docker/start_worker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ source $DOCKER_FOLDER/docker_build_common.sh
# ===============================[global variables]===============================
declare -r ACCOUNT=${ACCOUNT:-opensource4you}
declare -r KAFKA_ACCOUNT=${KAFKA_ACCOUNT:-apache}
declare -r KAFKA_VERSION=${KAFKA_REVISION:-${KAFKA_VERSION:-3.8.1}}
declare -r KAFKA_VERSION=${KAFKA_REVISION:-${KAFKA_VERSION:-3.9.0}}
declare -r DOCKERFILE=$DOCKER_FOLDER/worker.dockerfile
declare -r WORKER_PORT=${WORKER_PORT:-"$(getRandomPort)"}
declare -r CONTAINER_NAME="worker-$WORKER_PORT"
Expand Down Expand Up @@ -50,7 +50,7 @@ function showHelp() {
echo " ACCOUNT=opensource4you set the github account for astraea repo"
echo " HEAP_OPTS=\"-Xmx2G -Xms2G\" set worker JVM memory"
echo " KAFKA_REVISION=trunk set revision of kafka source code to build container"
echo " KAFKA_VERSION=3.8.1 set version of kafka distribution"
echo " KAFKA_VERSION=3.9.0 set version of kafka distribution"
echo " BUILD=false set true if you want to build image locally"
echo " RUN=false set false if you want to build/pull image only"
echo " WORKER_PLUGIN_PATH=/tmp/worker-plugins set plugin path to kafka worker"
Expand Down Expand Up @@ -114,7 +114,7 @@ function generateDockerfileByVersion() {
local kafka_url="https://archive.apache.org/dist/kafka/${KAFKA_VERSION}/kafka_2.13-${KAFKA_VERSION}.tgz"
local version=$KAFKA_VERSION
if [[ "$KAFKA_VERSION" == *"rc"* ]]; then
## `3.8.1-rc1` the rc release does not exist in archive repo
## `3.9.0-rc1` the rc release does not exist in archive repo
version=${KAFKA_VERSION%-*}
kafka_url="https://dist.apache.org/repos/dist/dev/kafka/${KAFKA_VERSION}/kafka_2.13-${version}.tgz"
fi
Expand Down
Loading