-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsetup_databases.sh
executable file
·143 lines (115 loc) · 4.11 KB
/
setup_databases.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
#!/bin/bash
function parse_arguments() {
# NAMESPACE
if [ -z "${NAMESPACE}" ]; then
echo "NAMESPACE not set. Using parameter \"$1\"";
NAMESPACE=$1;
fi
}
function create_namespace(){
EXISTING_NS="$(oc project $NAMESPACE -q)"
if [ "$EXISTING_NS" == "$NAMESPACE" ]; then
echo "${NAMESPACE} already exists"
oc project ${NAMESPACE}
else
oc new-project ${NAMESPACE}
fi
}
function add_scc(){
oc adm policy add-scc-to-user anyuid system:serviceaccount:${NAMESPACE}:default
oc adm policy add-scc-to-user privileged system:serviceaccount:${NAMESPACE}:default
}
function create_secrets(){
oc apply --recursive --filename secrets/
}
function create_configmaps(){
oc apply --recursive --filename configmaps/
}
function deploy_db() {
oc apply --recursive --filename deployments/
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
MYSQL_ROLLOUT_STATUS_CMD="oc rollout status deployment/inventory-mysql -n ${NAMESPACE}"
until $MYSQL_ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$MYSQL_ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
ES_ROLLOUT_STATUS_CMD="oc rollout status deployment/elasticsearch -n ${NAMESPACE}"
until $ES_ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$ES_ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
COUCHDB_ROLLOUT_STATUS_CMD="oc rollout status statefulset/customer-couchdb-couchdb -n ${NAMESPACE}"
until $COUCHDB_ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$COUCHDB_ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
MARIADB_ROLLOUT_STATUS_CMD="oc rollout status statefulset/orders-mariadb -n ${NAMESPACE}"
until $MARIADB_ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$MARIADB_ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
}
function create_services(){
oc apply --recursive --filename services/
}
function populate_db() {
oc apply --recursive --filename jobs/
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
MYSQL_ROLLOUT_STATUS_CMD="oc wait --for=condition=complete --timeout=30s job/inventory-populate-mysql -n ${NAMESPACE}"
until $MYSQL_ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$MYSQL_ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
# Check deployment rollout status every 10 seconds (max 10 minutes) until complete.
ATTEMPTS=0
COUCHDB_ROLLOUT_STATUS_CMD="oc wait --for=condition=complete --timeout=30s job/customer-create-user -n ${NAMESPACE}"
until $COUCHDB_ROLLOUT_STATUS_CMD || [ $ATTEMPTS -eq 60 ]; do
$COUCHDB_ROLLOUT_STATUS_CMD
ATTEMPTS=$((attempts + 1))
sleep 10
done
}
# Setup
parse_arguments $1
echo "========================================================================="
# create project namespace
echo "Set namespace"
create_namespace
echo "========================================================================="
# Adding security constraints
echo "Adding security constraints"
add_scc
echo "========================================================================="
# Creating secrets
echo "Generating necessary secrets"
create_secrets
echo "========================================================================="
# Creating configmaps
echo "Generating necessary configmaps"
create_configmaps
echo "========================================================================="
# Deploying databases
echo "Deploying the databases"
deploy_db
echo "========================================================================="
# Create database services
echo "Creating database services"
create_services
echo "========================================================================="
# Populate database with info
echo "Populating data in database"
populate_db
echo "========================================================================="