-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcloudbreak-db.sh
60 lines (48 loc) · 1.33 KB
/
cloudbreak-db.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
#!/usr/bin/env bash
# TODO - the cloudbreak-setup.sh smoketest doesn't cover all of this - custom db case has been manually tested
main() {
(
set -e
cd ${CLOUDBREAK_HOME}
import-cb-variables
check-for-custom-db-or-exit
set -u
for db_name in cbdb uaadb periscopedb; do
if ! db-exists ${db_name}; then
echo "DB ${db_name} not found, creating!"
db-create ${db_name}
fi
done
)
}
import-cb-variables() {
$(cbd env export) &> /dev/null \
|| echo "Failed to import SOME Cloudbreak variables"
}
check-for-custom-db-or-exit() {
if [[ -z ${CB_DB_PORT_5432_TCP_ADDR} ]] || [[ -z ${CB_DB_PORT_5432_TCP_PORT} ]]; then
echo "No custom DB settings detected, exiting"
exit 0
fi
}
db-execute() {
local -xr PGHOST=${CB_DB_PORT_5432_TCP_ADDR}
local -xr PGPORT=${CB_DB_PORT_5432_TCP_PORT}
local -xr PGUSER=${CB_DB_ENV_USER}
local -xr PGPASSWORD=${CB_DB_ENV_PASS}
docker run \
--rm \
--env PGHOST \
--env PGPORT \
--env PGUSER \
--env PGPASSWORD \
postgres:${DOCKER_TAG_POSTGRES} \
bash -c "${1}"
}
db-create() {
db-execute "createdb ${1}"
}
db-exists() {
db-execute "psql -lqt" | cut -d \| -f 1 | grep -qw "${1}"
}
main "${@}"