-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli.sh
executable file
·250 lines (228 loc) · 6.77 KB
/
cli.sh
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
248
249
250
#!/bin/bash
source cli_autocomplete.sh
CONFIG_FILE="./config/common/kafka.yml"
JAVA_PROJECTS=("market-matcher" "order-book" "order-stream" "trade-stream" "quickfix-server")
PYTHON_PROJECTS=("pre-processing" "website-backend")
CLIENT_PYTHON_PROJECTS=("quickfix-client" "graphical-user-interface")
NPM_PROJECTS=("website-frontend")
function docker_single() {
base_command=("docker" "compose" "-f" "docker-compose.base.yml" "-f" "docker-compose.single.yml")
if [ "$1" == "start" ]; then
"${base_command[@]}" up -d
elif [ "$1" == "restart" ]; then
"${base_command[@]}" restart
elif [ "$1" == "stop" ]; then
"${base_command[@]}" stop
elif [ "$1" == "down" ]; then
"${base_command[@]}" down
else
echo "Invalid action for docker: $1"
echo "Valid actions: start, restart, stop, down"
exit 1
fi
BOOTSTRAP_SERVERS="localhost:9092"
sed -i 's/^\(\s*bootstrap.servers\s*:\s*\).*/\1'"$BOOTSTRAP_SERVERS"'/' "$CONFIG_FILE"
}
function docker_multi() {
base_command=("docker" "compose" "-f" "docker-compose.base.yml" "-f" "docker-compose.multi.yml")
if [ "$1" == "start" ]; then
"${base_command[@]}" up -d
elif [ "$1" == "restart" ]; then
"${base_command[@]}" restart
elif [ "$1" == "stop" ]; then
"${base_command[@]}" stop
elif [ "$1" == "down" ]; then
"${base_command[@]}" down
else
echo "Invalid action for docker in kafka multi node: $1"
echo "Valid actions: start, restart, stop, down"
exit 1
fi
BOOTSTRAP_SERVERS="localhost:9092,localhost:9093,localhost:9094"
sed -i 's/^\(\s*bootstrap.servers\s*:\s*\).*/\1'"$BOOTSTRAP_SERVERS"'/' "$CONFIG_FILE"
}
function project() {
project=$1
action=$2
# If action is not specified, then default to run
if [ -z "$action" ]; then
action="run"
fi
args=("$@")
# Test if project is java
if [[ " ${JAVA_PROJECTS[*]} " =~ ${project} ]]; then
if [ "$action" == "test" ]; then
./gradlew :components:"$project":test "${args[@]:2}"
elif [ "$action" == "run" ]; then
./gradlew :components:"$project":run
elif [ "$action" == "build" ]; then
./gradlew :components:"$project":build
elif [ "$action" == "coverage" ]; then
./gradlew :components:"$project":jacocoTestReport
else
echo "Invalid action for project: $action"
echo "Valid actions: build, run, test coverage"
exit 1
fi
# Test if project is python
elif [[ " ${PYTHON_PROJECTS[*]} " =~ ${project} ]]; then
if [ "$action" == "run" ]; then
if [ "$project" == "website-backend" ]; then
(
cd components/"$project" || exit
DB_TYPE=POSTGRES poetry run uvicorn app.main:app --port 8001
)
else
(
cd components/"$project" || exit
poetry run "$project" "${args[@]:2}"
)
fi
elif [ "$action" == "test" ]; then
(
cd components/"$project" || exit
poetry run pytest tests/ "${args[@]:2}"
)
else
echo "Invalid action for project: $action"
echo "Valid actions: run, test"
exit 1
fi
# Test if project is npm
elif [[ " ${NPM_PROJECTS[*]} " =~ ${project} ]]; then
if [ "$action" == "run" ]; then
(
cd components/"$project" || exit
npm run dev
)
elif [ "$action" == "build" ]; then
(
cd components/"$project" || exit
npm run build
)
elif [ "$action" == "start" ]; then
(
cd components/"$project" || exit
npm start
)
elif [ "$action" == "test" ]; then
(
cd components/"$project" || exit
npm run test
)
else
echo "Invalid action for project: $action"
echo "Valid actions: run build start test"
exit 1
fi
else
echo "Invalid project: $project"
echo "Valid projects: ${JAVA_PROJECTS[*]} ${PYTHON_PROJECTS[*]}"
exit 1
fi
}
function reload_grafana() {
curl -X POST "http://admin:admin@localhost:3000/api/admin/provisioning/dashboards/reload"
echo ""
}
function reload_prometheus() {
curl -X POST "http://localhost:9090/-/reload"
echo "Prometheus config reloaded"
}
function version() {
version=$1
# Step 1: Update the java projects in the gradle.properties
echo "Updating version for java projects to $version"
sed -i 's/^\(\s*version\s*=\s*\).*/\1'"$version"'/' gradle.properties
# Step 2: Find all python projects and update their version in their pyproject.toml
for project in "${CLIENT_PYTHON_PROJECTS[@]}"; do
(
echo "Updating version for $project client to $version"
cd clients/"$project" || exit
poetry version "$version"
)
done
for project in "${PYTHON_PROJECTS[@]}"; do
(
echo "Updating version for $project to $version"
cd components/"$project" || exit
poetry version "$version"
)
done
# Step 2.5: For all python projects, update the lock file
for project in "${PYTHON_PROJECTS[@]}"; do
(
echo "Updating lock file for $project"
cd components/"$project" || exit
poetry lock --no-update
)
done
for project in "${CLIENT_PYTHON_PROJECTS[@]}"; do
(
echo "Updating lock file for $project"
cd clients/"$project" || exit
poetry lock --no-update
)
done
# Step 3: Find all npm projects and update their version in their package.json
for project in "${NPM_PROJECTS[@]}"; do
(
echo "Updating version for $project to $version"
cd components/"$project" || exit
npm version "$version"
)
done
}
help_text="Usage: $0 <command> [options]
Commands:
docker <action> Manage docker containers with kafka having single node
docker_multi <action> Manage docker containers with kafka having multiple nodes
reload_grafana Reload grafana dashboards
reload_prometheus Reload prometheus config
help Show this help text
project <project> <action> [options] Manage projects
version <version> Set version for all components
Docker actions:
start Start containers
restart Restart containers
stop Stop containers
down Stop and remove containers
Project actions:
build Build project
run Run project
test Run tests
coverage Run tests and generate coverage report"
if [ "$#" -lt 1 ]; then
echo "$help_text"
exit 1
fi
command="$1"
shift
case "$command" in
"docker")
docker_single "$@"
;;
"docker_multi")
docker_multi "$@"
;;
"reload_grafana")
reload_grafana
;;
"reload_prometheus")
reload_prometheus
;;
"project")
project "$@"
;;
"version")
version "$@"
;;
"help" | "-h" | "--help")
echo "$help_text"
;;
*)
echo "Invalid command: $command"
echo "$help_text"
exit 1
;;
esac