This repository has been archived by the owner on Jul 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
run.sh
executable file
·190 lines (153 loc) · 4.75 KB
/
run.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
#/bin/bash
# A single entry point for building, running, stopping and testing Butterfly.
set -e;
JAVA_KAFKA_COMPOSE_FILE=./docker-compose.yml
USER_MANAGER_COMPOSE_FILE=./user-manager/docker-compose.yml
USER_MANAGER_DEV_COMPOSE_FILE=./user-manager/docker-compose.dev.yml
DOCKER_COMPOSE="./docker-compose.sh -f $JAVA_KAFKA_COMPOSE_FILE -f $USER_MANAGER_COMPOSE_FILE"
DOCKER_COMPOSE_DEV="$DOCKER_COMPOSE -f $USER_MANAGER_DEV_COMPOSE_FILE"
print_usage() {
echo "Usage:
$0 [OPTIONS] COMMAND
A single entry point for building, running, stopping and testing Butterfly.
Options:
-b|--build If specified, it creates the Java services' jar executables.
-h|--help Show this help.
Commands:
install Install Java services' and User Manager' dependencies.
prod Executes the services in production mode.
dev Executes the services in development mode and spins up
utility services too. The utility services are:
- pgadmin [localhost:8080];
- openapi [localhost:8082].
prune Deletes all the docker virtual networks, volumes and stops
the services if they're currently running.
stop Stops the services if they're running.
ps Shows the list of services running.
logs Fetches the logs for a service.
test Executes the test battery.
sonarcloud Collects code metrics and uploads them on SonarCloud.
" >&2;
}
print_logs_usage() {
echo "Usage:
$0 logs [OPTIONS] SERVICE
View output from Butterfly containers running on Docker.
Options:
-h|--help Show this help.
" >&2;
}
print_test_usage() {
echo "Usage:
$0 test [OPTIONS]
Executes the test battery.
Options:
-h|--help Show this help.
-u|--user-manager Only run User Manager's tests.
" >&2;
}
exec_install() {
echo "Installing Java services dependencies...";
cd ./butterfly;
./build.sh --install;
cd ..;
echo "Installing User Manager dependencies...";
cd ./user-manager;
docker-compose -f docker-compose.install.yml down -v;
docker-compose -f docker-compose.install.yml up --build;
cd ..;
}
exec_test() {
exec_stop;
echo "Executing butterfly tests...";
if [ -z ${SHOULD_TEST_USER_MANAGER_ONLY+x} ]; then
echo "Building and testing Java modules";
cd ./butterfly; ./build.sh --clean --install --test; cd ..;
fi;
echo "Building and testing User Manager module";
cd ./user-manager; ./test.sh; cd ..;
}
exec_ps() {
echo "Showing active services...";
$DOCKER_COMPOSE_DEV ps;
}
exec_prune() {
echo "Removing services data...";
$DOCKER_COMPOSE_DEV down -v;
}
exec_stop() {
echo "Stopping services...";
$DOCKER_COMPOSE_DEV down;
}
exec_dev() {
echo "Running services in development mode...";
$DOCKER_COMPOSE_DEV up -d --build;
}
exec_prod() {
echo "Running services in production mode...";
$DOCKER_COMPOSE up -d --build;
}
exec_logs() {
LOG_COMMAND="$DOCKER_COMPOSE logs $SERVICE_TO_LOG";
$LOG_COMMAND;
}
exec_sonarcloud() {
echo "Collecting SonarCloud code metrics...";
cd ./butterfly;
./sonarcloud.sh $SONAR_PROJECT_KEY $SONAR_PROJECT_ORGANIZATION $SONAR_TOKEN;
cd ..;
}
# show error if no argument is passed
if [ $# -eq 0 ]; then
echo "Error: a command is required" >&2;
print_usage;
exit 1;
fi
echo "Option: $1";
# parse optional options
case $1 in
-h|--help) print_usage; exit 0;;
-b|--build) SHOULD_BUILD=1; shift;;
-*) "Error: unknown option $1" >&2; print_usage; exit 1;;
esac;
# build Java services if "--build" option was passed
if [ ! -z ${SHOULD_BUILD+x} ]; then
echo "Building Java services...";
cd butterfly;
./build.sh
cd ..;
fi
echo "Command: $1";
# parse commands
case $1 in
install) exec_install;;
prod) exec_prod;;
dev) exec_dev;;
prune) exec_prune;;
stop) exec_stop;;
ps) exec_ps;;
logs) SHOULD_LOG=1; shift;;
test) SHOULD_TEST=1; shift;;
sonarcloud) exec_sonarcloud;;
*) "Error: unknown command $1" >&2; print_usage; exit 1;;
esac;
# parse logs command's options and service name to log
if [ ! -z ${SHOULD_LOG+x} ]; then
case $1 in
-h|--help) print_logs_usage; exit 0;;
-*) "Error: unknown option $1 for \"logs\" command" >&2; print_logs_usage; exit 1;;
*) SERVICE_TO_LOG="$1";;
esac;
exec_logs
fi
echo "Test options: $1";
# parse test command's options
if [ ! -z ${SHOULD_TEST+x} ]; then
case $1 in
-h|--help) print_test_usage; exit 0;;
-u|--user-manager) SHOULD_TEST_USER_MANAGER_ONLY=1;;
-*) "Error: unknown option $1 for \"test\" command" >&2; print_test_usage; exit 1;;
?) "Error: unknown command $1" >&2; print_test_usage; exit 1;;
esac;
exec_test
fi