forked from zebrunner/mcloud
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zebrunner.sh
executable file
·202 lines (164 loc) · 4.48 KB
/
zebrunner.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
#!/bin/bash
setup() {
# PREREQUISITES: valid values inside ZBR_PROTOCOL, ZBR_HOSTNAME and ZBR_PORT env vars!
local url="$ZBR_PROTOCOL://$ZBR_HOSTNAME:$ZBR_PORT"
cp .env.original .env
replace .env "localhost" "${ZBR_HOSTNAME}"
cp variables.env.original variables.env
replace variables.env "http://localhost:8082" "${url}"
replace variables.env "localhost" "${ZBR_HOSTNAME}"
if [[ $ZBR_MINIO_ENABLED -eq 0 ]]; then
# use case with AWS S3
replace variables.env "S3_REGION=us-east-1" "S3_REGION=${ZBR_STORAGE_REGION}"
replace variables.env "S3_ENDPOINT=http://minio:9000" "S3_ENDPOINT=${ZBR_STORAGE_ENDPOINT_PROTOCOL}://${ZBR_STORAGE_ENDPOINT_HOST}"
replace variables.env "S3_BUCKET=zebrunner" "S3_BUCKET=${ZBR_STORAGE_BUCKET}"
replace variables.env "S3_ACCESS_KEY_ID=zebrunner" "S3_ACCESS_KEY_ID=${ZBR_STORAGE_ACCESS_KEY}"
replace variables.env "S3_SECRET=J33dNyeTDj" "S3_SECRET=${ZBR_STORAGE_SECRET_KEY}"
replace variables.env "S3_TENANT=" "S3_TENANT=${ZBR_STORAGE_TENANT}"
fi
}
shutdown() {
if [[ -f .disabled ]]; then
rm -f .disabled
exit 0 #no need to proceed as nothing was configured
fi
docker-compose --env-file .env -f docker-compose.yml down -v
rm -f .env
rm -f variables.env
}
start() {
if [[ -f .disabled ]]; then
exit 0
fi
# create infra network only if not exist
docker network inspect infra >/dev/null 2>&1 || docker network create infra
if [[ ! -f variables.env ]]; then
cp variables.env.original variables.env
fi
if [[ ! -f .env ]]; then
cp .env.original .env
fi
docker-compose --env-file .env -f docker-compose.yml up -d
}
stop() {
if [[ -f .disabled ]]; then
exit 0
fi
docker-compose --env-file .env -f docker-compose.yml stop
}
down() {
if [[ -f .disabled ]]; then
exit 0
fi
docker-compose --env-file .env -f docker-compose.yml down
}
backup() {
if [[ -f .disabled ]]; then
exit 0
fi
cp variables.env variables.env.bak
cp .env .env.bak
docker run --rm --volumes-from rethinkdb -v $(pwd)/backup:/var/backup "ubuntu" tar -czvf /var/backup/rethinkdb.tar.gz /data
}
restore() {
if [[ -f .disabled ]]; then
exit 0
fi
stop
cp variables.env.bak variables.env
cp .env.bak .env
docker run --rm --volumes-from rethinkdb -v $(pwd)/backup:/var/backup "ubuntu" bash -c "cd / && tar -xzvf /var/backup/rethinkdb.tar.gz"
down
}
version() {
if [[ -f .disabled ]]; then
exit 0
fi
source .env
echo "mcloud: ${TAG_STF}"
}
echo_warning() {
echo "
WARNING! $1"
}
echo_telegram() {
echo "
For more help join telegram channel: https://t.me/zebrunner
"
}
echo_help() {
echo "
Usage: ./zebrunner.sh [option]
Flags:
--help | -h Print help
Arguments:
start Start container
stop Stop and keep container
restart Restart container
down Stop and remove container
shutdown Stop and remove container, clear volumes
backup Backup container
restore Restore container
version Version of container"
echo_telegram
exit 0
}
replace() {
#TODO: https://github.com/zebrunner/zebrunner/issues/328 organize debug logging for setup/replace
file=$1
#echo "file: $file"
content=$(<$file) # read the file's content into
#echo "content: $content"
old=$2
#echo "old: $old"
new=$3
#echo "new: $new"
content=${content//"$old"/$new}
#echo "content: $content"
printf '%s' "$content" >$file # write new content to disk
}
BASEDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd ${BASEDIR}
case "$1" in
setup)
if [[ $ZBR_INSTALLER -eq 1 ]]; then
setup
else
echo_warning "Setup procedure is supported only as part of Zebrunner Server (Community Edition)!"
echo_telegram
fi
;;
start)
start
;;
stop)
stop
;;
restart)
down
start
;;
down)
down
;;
shutdown)
shutdown
;;
backup)
backup
;;
restore)
restore
;;
version)
version
;;
--help | -h)
echo_help
;;
*)
echo "Invalid option detected: $1"
echo_help
exit 1
;;
esac