-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup
More file actions
executable file
·247 lines (214 loc) · 6.5 KB
/
Copy pathsetup
File metadata and controls
executable file
·247 lines (214 loc) · 6.5 KB
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
#!/bin/bash
#
# Unified setup script for Kannika Armory tutorials
#
set -e
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TUTORIALS_DIR="${SCRIPT_DIR}/tutorials"
source "${SCRIPT_DIR}/scripts/env.sh"
source "${SCRIPT_DIR}/scripts/print-help.sh"
__env_load
export CLUSTER_NAME="${CLUSTER_NAME:-kannika-kind}"
# Colors
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'
print_info() { echo -e "${GREEN}[INFO]${NC} $1"; }
print_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; }
print_warning() { echo -e "${YELLOW}[WARNING]${NC} $1"; }
usage() {
cat << EOF
Usage: ./setup <command> [options]
Run a Kannika Armory tutorial or set up individual components.
COMMANDS:
<tutorial> Run the specified tutorial (sets up everything)
armory Set up Kannika Armory only (Kind cluster + Helm)
kafka Set up Kafka clusters only (docker-compose)
network Connect Kind cluster to Kafka network
tools Install kind, kubectl, and helm to .bin directory
list List available tutorials
OPTIONS:
-h, --help Show this help message
AVAILABLE TUTORIALS:
EOF
list_tutorials " "
echo ""
echo "EXAMPLES:"
echo " ./setup migrate-consumer-groups"
echo " ./setup armory"
echo " ./setup kafka"
echo " ./setup network"
echo " ./setup tools"
echo " ./setup list"
echo ""
}
list_tutorials() {
local prefix="${1:-}"
for dir in "${TUTORIALS_DIR}"/*/; do
[ -d "$dir" ] || continue
local name=$(basename "$dir")
local desc=""
if [ -f "${dir}README.md" ]; then
desc=$(head -1 "${dir}README.md" | sed 's/^#* *//')
fi
if [ -n "$desc" ]; then
printf "%s%-25s %s\n" "$prefix" "$name" "$desc"
else
echo "${prefix}${name}"
fi
done
}
setup_tools() {
print_info "Installing tools to .bin directory..."
"${SCRIPT_DIR}/scripts/install-kind.sh"
"${SCRIPT_DIR}/scripts/install-kubectl.sh"
"${SCRIPT_DIR}/scripts/install-helm.sh"
print_info "Tools installed to $(__env_bin_dir)"
}
install_armory() {
if kind get clusters 2>/dev/null | grep -q "^${CLUSTER_NAME}$"; then
print_warning "Cluster '${CLUSTER_NAME}' already exists, skipping armory setup."
return 0
fi
print_info "Setting up Kannika Armory..."
"${SCRIPT_DIR}/scripts/setup-kannika-armory.sh" "$@"
}
kafka_ready() {
docker exec kafka-source kafka-broker-api-versions --bootstrap-server localhost:9092 &>/dev/null && \
docker exec kafka-target kafka-broker-api-versions --bootstrap-server localhost:9093 &>/dev/null
}
setup_kafka() {
if kafka_ready; then
print_warning "Kafka clusters already running, skipping."
return 0
fi
print_info "Starting Kafka clusters..."
docker-compose -f "${SCRIPT_DIR}/docker-compose.yml" up -d
print_info "Waiting for Kafka to be ready..."
until kafka_ready; do
sleep 2
done
}
setup_network() {
print_info "Connecting Kind to Kafka network..."
"${SCRIPT_DIR}/scripts/connect-kafka-to-kind.sh"
}
apply_tutorial_k8s() {
local tutorial="$1"
local tutorial_dir="${TUTORIALS_DIR}/${tutorial}"
local k8s_dir="${TUTORIAL_DIR}/k8s"
if [ ! -d "$k8s_dir" ]; then
return 0
fi
print_info "Applying Kubernetes resources..."
kubectl apply -f "$k8s_dir"
}
print_help() {
local tutorial="$1"
local tutorial_dir="${TUTORIALS_DIR}/${tutorial}"
# Read credentials from secret
ARMORY_USERNAME=$(kubectl get secret api -n kannika-system -o jsonpath='{.data.username}' 2>/dev/null | base64 -d)
ARMORY_PASSWORD=$(kubectl get secret api -n kannika-system -o jsonpath='{.data.password}' 2>/dev/null | base64 -d)
echo ""
echo "=============================================="
echo "Setup Complete!"
echo "=============================================="
echo ""
print_armory_info
echo ""
print_kafka_info
echo ""
# Print tutorial-specific help if exists
if [ -f "${TUTORIAL_DIR}/help.txt" ]; then
echo "----------------------------------------------"
echo ""
cat "${TUTORIAL_DIR}/help.txt"
fi
echo ""
print_teardown_info
echo ""
print_license_info
echo ""
}
run_tutorial() {
local tutorial="$1"
shift
export TUTORIAL_DIR="${TUTORIALS_DIR}/${tutorial}"
export HOOKS_DIR="${TUTORIAL_DIR}"
if [ ! -d "$TUTORIAL_DIR" ]; then
print_error "Tutorial not found: ${tutorial}"
echo ""
echo "Available tutorials:"
list_tutorials " "
exit 1
fi
echo "=============================================="
echo "Setup: ${tutorial}"
echo "=============================================="
echo ""
if [ -f "${TUTORIAL_DIR}/values.yaml" ]; then
install_armory --values "${TUTORIAL_DIR}/values.yaml" "$@"
else
install_armory "$@"
fi
setup_kafka
setup_network
apply_tutorial_k8s "$tutorial"
print_help "$tutorial"
}
main() {
if [ $# -eq 0 ]; then
usage
exit 1
fi
case "$1" in
-h|--help)
usage
exit 0
;;
list)
echo "Available tutorials:"
echo ""
list_tutorials " "
echo ""
;;
armory)
shift
if kind get clusters 2>/dev/null | grep -q "^${CLUSTER_NAME}$"; then
print_warning "Cluster '${CLUSTER_NAME}' already exists."
read -p "Re-run armory setup anyway? [y/N] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 0
fi
# User confirmed, run directly bypassing skip check
"${SCRIPT_DIR}/scripts/setup-kannika-armory.sh" "$@"
else
install_armory "$@"
fi
;;
kafka)
setup_kafka
# Check if Kind cluster is running and offer to connect
if docker ps --format '{{.Names}}' | grep -q "${CLUSTER_NAME}-control-plane"; then
echo ""
read -p "Kind cluster detected. Connect Kafka to Kind network? [Y/n] " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Nn]$ ]]; then
setup_network
fi
fi
;;
network)
setup_network
;;
tools)
setup_tools
;;
*)
run_tutorial "$@"
;;
esac
}
main "$@"