Skip to content

Commit

Permalink
refactor: cleanup script up
Browse files Browse the repository at this point in the history
  • Loading branch information
fhussonnois committed Oct 10, 2023
1 parent 66b6e5b commit 299c988
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 23 deletions.
54 changes: 47 additions & 7 deletions README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,48 @@ toc::[]
* AKHQ (https://akhq.io/)
* ZooNavigator (https://zoonavigator.elkozmon.com/en/stable/)

== Usage

[source, bash]
----
$ ./up -h
--------------------------------------------------------------------------------
____ __ _____ __ _
/ __ \____ _/ /_____ _ / ___// /_________ ____ _____ ___ (_)___ ____ _
/ / / / __ `/ __/ __ `/ \__ \/ __/ ___/ _ \/ __ `/ __ `__ \/ / __ \/ __ `/
/ /_/ / /_/ / /_/ /_/ / ___/ / /_/ / / __/ /_/ / / / / / / / / / / /_/ /
/_____/\__,_/\__/\__,_/ /____/\__/_/ \___/\__,_/_/ /_/ /_/_/_/ /_/\__, /
/____/

Powered by Apache Kafka!

--------------------------------------------------------------------------------
Usage: ./up [options]
-n <[NAME]> : Name of the stack to deploy (required)
-s <[SERVICE]> : Service names to deploy (run all services if empty)
-h : Print this Help.
The table below lists the available docker-compose stacks:
NAME (./up -n <NAME>) | FILE (docker compose -f <FILE> up -d)
===================================+==================================================
zk-kafka-multiple-nodes-sasl | zk-kafka-multiple-nodes-sasl-stack.yml
zk-kafka-multiple-nodes | zk-kafka-multiple-nodes-stack.yml
zk-kafka-single-node-full | zk-kafka-single-node-full-stack.yml
zk-kafka-single-node-sasl | zk-kafka-single-node-sasl-stack.yml
zk-kafka-single-node | zk-kafka-single-node-stack.yml
zkless-kafka-multiple-nodes | zkless-kafka-multiple-nodes-stack.yml
----

=== Examples

**To deploy a Kafka Cluster (Kraft)**
[source, bash]
----
$ ./up -n zkless-kafka-multiple-nodes
----

== Getting Started

**1. Clone the Kafka Monitoring Suite repository.**
Expand Down Expand Up @@ -169,16 +211,14 @@ Security are :

Prometheus is accessible at the address : http://localhost:9090

== Contributions
== 💡 Contributions

Any feedback, bug reports and PRs are greatly appreciated!

== Licence

Copyright 2020-2023 StreamThoughts.
== 🙏 Show your support

Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
Please ⭐ this repository to support us!

http://www.apache.org/licenses/LICENSE-2.0["http://www.apache.org/licenses/LICENSE-2.0"]
== Licence

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License
This code base is available under the Apache License, version 2.
58 changes: 42 additions & 16 deletions up
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ BASEDIR=$(dirname "$(readlink -f $0)")
DOCKERDIR="$BASEDIR"

line() {
echo -e "\n----------------------------------------------------------------------------------------------------------------------------------------\n"
echo ""
printf "%.0s-" {1..80};
echo ""
}
banner() {
line
Expand All @@ -36,11 +38,33 @@ banner() {

usage() {
echo "Usage: $0 [options]" 1>&2 && \
echo -e "\t -n <[NAME]> \t: Name of stack to deploy" 1>&2 && \
echo -e "\t -s <[SERVICE]> \t: Service names to deploy" 1>&2 && \
echo -e "\t -h \t: Print this Help." 1>&2; exit 1;
echo -e "\t -n <[NAME]> \t: Name of the stack to deploy (required)" 1>&2 && \
echo -e "\t -s <[SERVICE]> \t: Service names to deploy (run all services if empty)" 1>&2 && \
echo -e "\t -h \t: Print this Help." 1>&2 && \
print_available_stacks && \
exit 1;
}

print_available_stacks() {
echo -e "\nThe table below lists the available docker-compose stacks:\n"
printf "%-35s|\t%-50s\n" "NAME (./up -n <NAME>)" "FILE (docker compose -f <FILE> up -d)";
printf "=%.0s" {1..35};
echo -n "+";
printf "=%.0s" {1..50};
echo ""
for COMPOSE in "$DOCKERDIR/"*.yml; do
RELATIVE_PATH=$(realpath --relative-to="$BASEDIR" "$COMPOSE");
if [[ "$COMPOSE" =~ .*/(.*)-stack.yml ]]
then
NAME="${BASH_REMATCH[1]}";
printf "%-35s|\t%-50s\n" "$NAME" "$RELATIVE_PATH";
fi
done
}

# Printf
banner

STACK_NAME=""
SERVICE=""
while getopts "dhc:s:n:" o; do
Expand All @@ -53,31 +77,33 @@ while getopts "dhc:s:n:" o; do
esac
done

# Check required arguments
if [[ -z "$STACK_NAME" ]]; then
usage
exit 2
fi

DOCKER_STACK="$DOCKERDIR/$STACK_NAME-stack.yml"

# Check docker compose fil exists
if [[ ! -f "$DOCKER_STACK" ]]; then
echo "Cannot find docker-compose file $STACK_NAME-stack.yml. Available stacks are:"
for COMPOSE in "$DOCKERDIR/"*.yml; do
if [[ "$COMPOSE" =~ .*/(.*).yml ]]
then
NAME="${BASH_REMATCH[1]}"
echo -e " - $NAME";
fi
done
exit 1;
echo "Error: Cannot find docker-compose file '$STACK_NAME-stack.yml'."
print_available_stacks
exit 2
fi

banner

echo -e "\n🐳 Stopping previous Kafka Docker-Compose stacks..."
# Stop any previous stack
echo -e "\n🐳 Stopping Kafka Docker-Compose stacks..."
for COMPOSE in "$DOCKERDIR/"*.yml; do
echo "Removing stack for $COMPOSE"
(cd "$BASEDIR"; docker compose -f "$COMPOSE" down --remove-orphans)
done

# Start
echo -e "\n🐳 Starting Kafka Docker-Compose stack..."
(cd "$BASEDIR"; docker compose -f "$DOCKER_STACK" up -d $SERVICE)

# Printf
line
echo -e "Grafana (Login : admin / Password : kafka) : http://localhost:3000"
echo -e "Prometheus : http://localhost:9090"
Expand Down

0 comments on commit 299c988

Please sign in to comment.