-
Notifications
You must be signed in to change notification settings - Fork 76
/
up
executable file
·115 lines (99 loc) · 3.35 KB
/
up
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/bash
# Copyright 2023 The original authors
#
# Licensed 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
# http://www.apache.org/licenses/LICENSE-2.0
#
# 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.
set -e
BASEDIR=$(dirname "$(readlink -f $0)")
DOCKERDIR="$BASEDIR"
line() {
echo ""
printf "%.0s-" {1..80};
echo ""
}
banner() {
line
echo -e " ____ __ _____ __ _ "
echo -e " / __ \____ _/ /_____ _ / ___// /_________ ____ _____ ___ (_)___ ____ _ "
echo -e " / / / / __ \`/ __/ __ \`/ \__ \/ __/ ___/ _ \/ __ \`/ __ \`__ \/ / __ \/ __ \`/ "
echo -e " / /_/ / /_/ / /_/ /_/ / ___/ / /_/ / / __/ /_/ / / / / / / / / / / /_/ / "
echo -e " /_____/\__,_/\__/\__,_/ /____/\__/_/ \___/\__,_/_/ /_/ /_/_/_/ /_/\__, / "
echo -e " /____/ "
echo ""
echo " Powered by Apache Kafka!"
line
}
usage() {
echo "Usage: $0 [options]" 1>&2 && \
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
case "${o}" in
n) STACK_NAME="${OPTARG}";;
s) SERVICE="${OPTARG}";;
h|*)
usage
;;
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 "Error: Cannot find docker-compose file '$STACK_NAME-stack.yml'."
print_available_stacks
exit 2
fi
# 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"
line
echo -e "\n Use the below client config properties for connecting to Kafka:"
echo -e "\tbootstrap.servers=localhost:9092"
exit 0