-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_at.sh
executable file
·156 lines (133 loc) · 3.89 KB
/
run_at.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
#!/usr/bin/env bash
######################################
# RUN ACCEPTANCE TESTS
######################################
is_db_up() {
mysql_id=$(docker ps -a | grep modular-architecture-hexagonal-demo-project_mysql | awk {'print $1'})
x=1
logs=$(docker container logs 2>/dev/null --tail 100 "$mysql_id")
# shellcheck disable=SC2039
while [[ $logs != *"started."* ]] && [ ${x} -le 30 ]; do
sleep 1;
x=$(( x + 1 ))
printf "."
logs=$(docker container logs 2>/dev/null --tail 100 "$mysql_id")
done
logs=$(docker container logs 2>/dev/null --tail 100 "$mysql_id")
# shellcheck disable=SC2039
if [[ $logs != *"started."* ]]; then
printf " :> DB cannot be boot up in %s seconds, quited." "$x"
echo " :> \nLOGS:"
docker container logs 2>/dev/null --tail 100 "$mysql_id"
exit 1
else
printf " :> DB becomes up and running in %s seconds\n" "$x"
fi
}
is_api_up() {
echo " :> $1 monitoring started"
api_name=$1
x=1
while [[ $( cat "${api_name}.log" ) != *"Tomcat started"* ]] && [ ${x} -le 30 ]; do
sleep 1;
x=$(( x + 1 ))
printf "."
done
if [[ $( cat "${api_name}.log" ) != *"Tomcat started"* ]]; then
printf " :> ${api_name} cannot be boot up in %s seconds, quited." "$x"
exit 1
else
printf " :> ${api_name} becomes up and running in %s seconds\n" "$x"
fi
}
start_apis() {
echo " :> Api bootup is triggered"
./gradlew clean :payment-api:build -x test -PskipInfraSetup >payment-api.log
echo " :> Payment api is build"
./gradlew clean :ticket-api:build -x test -PskipInfraSetup >ticket-api.log
echo " :> Ticket api is build"
./gradlew :payment-api:bootRun -PskipInfraSetup --stacktrace >payment-api.log &
sleep 3
echo " :> Payment api boot is triggered"
./gradlew :ticket-api:bootRun -PskipInfraSetup --stacktrace >ticket-api.log &
sleep 3
echo " :> Ticket api boot is triggered"
is_api_up "payment-api"
echo " :> Payment api is started"
is_api_up "ticket-api"
echo " :> Ticket api is started"
}
stop_infra() {
docker compose -f docker-compose.yml down
echo " :> Infra is stopped at local"
}
stop_apis() {
# shellcheck disable=SC2046
# shellcheck disable=SC2009
pid_list=$(ps aux | grep gradlew | grep boot | awk '{print $2}')
if [ -n "$pid_list" ]; then
# shellcheck disable=SC2046
# shellcheck disable=SC2116
# shellcheck disable=SC2069
kill -9 $(echo "$pid_list") 2>/dev/null
echo " :> Api instances are killed"
rm payment-api.log 2> /dev/null
rm ticket-api.log 2> /dev/null
echo " :> Temp files are deleted"
fi
}
start_infra() {
docker compose -f docker-compose.yml up -d
echo " :> Infra is initializing"
sleep 5
is_db_up
echo " :> Infra is up and ready for acceptance tests at local"
}
test() {
echo " :> Acceptance test is going to start"
./gradlew :acceptance-test-suite:clean :acceptance-test-suite:cucumber -PskipInfraSetup -Dorg.gradle.daemon=false
echo " :> Acceptance test ended"
}
#####################################
# MAIN
#####################################
case "${1}" in
"start_apis")
start_apis;;
"start_infra")
start_infra;;
"start")
start_infra
start_apis;;
"stop_apis")
stop_apis;;
"stop_infra")
stop_infra;;
"stop")
stop_infra
stop_apis;;
"restart_infra")
stop_infra
start_infra;;
"restart_apis")
stop_apis
start_apis;;
"restart")
stop_apis
stop_infra
start_infra
start_apis;;
"test")
test;;
"run")
stop_apis
stop_infra
start_infra
start_apis
test
stop_apis
stop_infra
;;
*)
echo Unknown command! "${1}"
esac