-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkong.sh
executable file
·211 lines (153 loc) · 4.77 KB
/
kong.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
#!/bin/sh
set -eu
Show_Help() {
cat <<EOF
A bash script to wrap the Docker stack for the Kong API Gateway.
---> MUST BE USED FROM THE ROOT OF THE PROJECT <---
SIGNATURE:
./kong [options] <command> [arguments]
OPTIONS:
--project-name Sets the project to be used by docker compose.
$ ./kong --project-name <project-name-here> <command> [arguments]
$ ./kong --project-name approov up
COMMANDS:
demo Starts the Kong Docker Stack and configures Kong for the demo.
$ ./kong demo
destroy Does the same as \`down\`, and also removes the associated docker volume.
$ ./kong destroy
down Stops and removes the services for Kong and the Database.
$ ./kong down
logs Tails the logs for all services or just for the given one.
$ ./kong logs
$ ./kong logs kong
$ ./kong logs db
logs-find Find all ocurrences of a string in the logs for a specific service.
$ ./kong logs <service> <word to find>
$ ./kong logs kong approov
shell Gives a bash shell inside the Docker container for the Kong service.
$ ./kong shell
status Shows the status for the services, volume and network.
$ ./kong status
up Starts Kong and the Databas\e services in Docker containers.
$ ./kong up
EOF
}
Print_Message() {
printf "\n---> ${1}\n"
}
Print_Error() {
printf "\n---> ERROR: ${1} <---\n"
}
Docker_Container_Is_Running() {
sudo docker container ls -a | grep -w "${1}" - | grep -qw Up -
return $?
}
Docker_Container_Is_Stopped() {
sudo docker container ls -a | grep -w "${1}" - | grep -qw Exited -
return $?
}
Docker_Compose() {
sudo docker-compose \
--project-name "${PROJECT_NAME}" \
--file "${DOCKER_COMPOSE_FILE}" \
${@}
}
Kong_Up() {
if Docker_Container_Is_Running "${PROJECT_NAME}_kong_1"; then
return
fi
Docker_Compose up --detach
# Give time for the database to start and run the migrations.
sleep 5
}
Kong_Down() {
Docker_Compose down
}
Kong_Destroy() {
Kong_Down
sudo docker volume rm "${PROJECT_NAME}_kong_data"
}
Kong_Status() {
printf "\nSERVICES STATUS:\n"
Docker_Compose ps
printf "\nVOLUME STATUS:\n"
sudo docker volume ls | grep -i "${PROJECT_NAME}" -
printf "\nNETWORK STATUS:\n"
sudo docker network ls | grep -i "${PROJECT_NAME}" -
echo
}
Main() {
############################################################################
# SETUP
############################################################################
# Docker compose uses this to prefix the names for services, networks, volumes, etc.
local PROJECT_NAME=kong-approov
if [ -f ./.bash.vars ]; then
. ./.bash.vars
fi
if [ -f ./.bash.vars.local ]; then
. ./.bash.vars.local
fi
if [ ! -f ./.env ] && [ -f ./.env.example ]; then
cp ./.env.example .env
fi
if [ -f ./.env ]; then
. ./.env
fi
local DOCKER_COMPOSE_FILE=./docker/kong-api-gateway/docker-compose.yml
############################################################################
# INPUT
############################################################################
for input in in "${@}"; do
case "${input}" in
--project-name )
PROJECT_NAME="${2? Missing project name.}"
;;
demo )
Kong_Up
./kong-admin approov:demo-setup
exit $?
;;
destroy )
Kong_Destroy
exit $?
;;
down )
Kong_Down
exit $?
;;
help | -h | --help )
Show_Help
exit 0
;;
logs )
Docker_Compose logs --follow ${2:-}
exit $?
;;
logs-find )
Docker_Compose logs ${3:-} | grep -in "${2}" -
exit $?
;;
quick-start )
Kong_Up
./kong-admin approov:quick-start
exit $?
;;
shell )
Kong_Up
Docker_Compose exec kong sh
exit 0
;;
status )
Kong_Status
exit 0
;;
up )
Kong_Up
exit $?
;;
esac
done
Show_Help
}
Main $@