This repository has been archived by the owner on Dec 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
launch-or-update-azure.sh
executable file
·357 lines (335 loc) · 11.4 KB
/
launch-or-update-azure.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
#!/bin/bash
# Help Text
function displayHelp {
printf "usage: ./launch-or-update-azure.sh [OPTIONS]
-h, --help
Display help
-c, --chart [local|local-cache|remote]
chart is (default) remote(gpitfuturesdevacr/buyingcatalogue), or local (src/buyingcatalogue)
-l, --helm-repo <Helm Repo>
Container Repository where images are to be updated from (defaults to gpitfuturesdevacr/buyingcatalogue)
-n, --namespace <namespace>
Namespace to deploy to; otherwise generated to be a random 8 characters
-d, --db-server <database server>
[REQUIRED] SQL database server to deploy to
-u, --db-admin-user <user name>
[REQUIRED] SQL Admin User Name
-p, --db-admin-pass <password>
[REQUIRED] SQL Admin Password
-v, --version <version>
Version to deploy (Remote Chart Only)
-w --wait
wait for deployment to complete successfully (up to 10 minutes)
-b, --base-path <path>
Base path to application, will default to '\$namespace-dev.buyingcatalogue.digital.nhs.uk'
-s, --sql-package-args
-a, --azure-storage-connection-string <connection string>
[REQUIRED] Azure Storage Connection String
-i, --ip <IP Address>
Overrides host config and sets IP for the given base path
-r, --redis-server <redis host url>
[REQUIRED] Url to connect to Redis
-q, --redis-password <redis host password>
[REQUIRED] Password connect to Redis
-f, --file-overrides
A comma-separated list of file names. These are the names of override files to apply.
NOTE: these files are expected to be in the 'environments' directory
E.g: '-f public.yaml,no-data-insert.yaml' will apply environments/public.yaml & environments/no-data-insert.yaml
--client-secret <client secret>
The client secret to use for the cookie encryption. Default 'NodeClientSecret'
--cookie-secret <cookie secret>
The cookie secret to use for the cookie encryption. Default 'secret squirrel'
--db-user-pass <pass>
The password for use by the api db users Default 'DisruptTheMarket1!'
--email-server
If set, disable the internal email server, and use external. Email Username & password must also be set.
--email-user
Email username if email-server is set
--email-pass
Email password if email-server is set
--helm-upgrade-args <arguments>
Pass additional arguments to helm upgrade
"
exit
}
# Option strings
SHORT="hc:l:n:d:u:p:v:wb:s:a:i:r:q:f:"
LONG="help,chart:,helm-repo:,namespace:,db-server:,db-admin-user:,db-admin-pass:,version:,wait,base-path:,sql-package-args:,azure-storage-connection-string:,ip,redis-server:,redis-password:,file-overrides:,client-secret:,cookie-secret:,db-user-pass:,email-server:,email-user:,email-pass:,helm-upgrade-args:"
# read the options
OPTS=$(getopt --options $SHORT --long $LONG --name "$0" -- "$@")
if [ $? != 0 ] ; then echo "Failed to parse options...exiting." >&2 ; exit 1 ; fi
eval set -- "$OPTS"
# set initial values
chart="gpitfuturesdevacr/buyingcatalogue"
wait="false"
dbUserPassword="DisruptTheMarket1!"
clientSecret="NodeClientSecret"
cookieSecret="secret squirrel"
# extract options and their arguments into variables.
while true ; do
case "$1" in
-h | --help )
displayHelp
shift
;;
-c | --chart )
if [ "$2" = "local" ]
then
chart="src/buyingcatalogue"
rm $chart/charts/*.tgz
helm dependency update $chart
elif [ "$2" = "local-cache" ]
then
chart="src/buyingcatalogue"
fi
shift 2
;;
-l | --helm-repo )
repo="$2"
shift 2
;;
-n | --namespace )
namespace="$2"
shift 2
;;
-d | --db-server )
dbServer="$2"
shift 2
;;
-u | --db-admin-user )
saUserName="$2"
shift 2
;;
-p | --db-admin-pass )
saPassword="$2"
shift 2
;;
-v | --version )
version="$2"
shift 2
;;
-w | --wait )
wait="true"
shift 1
;;
-b | --base-path )
basePath="$2"
shift 2
;;
-s | --sql-package-args )
sqlPackageArgs="$2"
shift 2
;;
-a | --azure-storage-connection-string )
azureStorageConnectionString="$2"
shift 2
;;
-i | --ip )
ipOverride="$2"
shift 2
;;
-r | --redis-server )
redisServer="$2"
shift 2
;;
-q | --redis-password )
redisPassword="$2"
shift 2
;;
-f | --file-overrides )
overrideFiles="$2"
shift 2
;;
--client-secret )
clientSecret="$2"
shift 2
;;
--cookie-secret )
cookieSecret="$2"
shift 2
;;
--db-user-pass )
dbUserPassword="$2"
shift 2
;;
--email-server )
emailServer="$2"
shift 2
;;
--email-user )
emailUser="$2"
shift 2
;;
--email-pass )
emailPassword="$2"
shift 2
;;
--helm-upgrade-args )
helmUpgradeArgs="$2"
shift 2
;;
-- )
shift
break
;;
*)
echo "Internal error!"
exit 1
;;
esac
done
context=$(kubectl config current-context)
if [[ "$context" = "docker-desktop" ]]; then
>&2 echo "Error - Local Context - $context"
exit 1
fi
if [ -z ${namespace+x} ]
then
namespace=$(cat /dev/urandom | tr -dc 'a-zA-Z' | fold -w 8 | head -n 1)
echo "namespace not set: generated $namespace"
else #truncate to 63 chars && convert to lowercase to be DNS compliant
namespace=$(echo "$namespace" | cut -c 1-63)
namespace=$(echo "$namespace" | tr '[:upper:]' '[:lower:]')
fi
if [ -z ${dbServer+x} ] || [ -z ${saUserName+x} ] || [ -z ${saPassword+x} ]
then
echo "db server not set"
exit
fi
if [ -z ${redisServer+x} ] || [ -z ${redisPassword+x} ]; then
echo "redis server not set properly"
exit
fi
if [ -n "$repo" ] && [[ $chart == *"acr/buyingcatalogue"* ]]
then
chart="$repo"
fi
if [ -n "$version" ] && [[ $chart == *"acr/buyingcatalogue"* ]]
then
versionArg="--version $version"
fi
if [ "$wait" = "true" ]
then
waitArg="--wait"
fi
if [ -n "$overrideFiles" ]; then
fileOverrideArgs=""
IFS=',' read -ra FILES <<< "$overrideFiles"
for file in "${FILES[@]}"; do
fileOverrideArgs="$fileOverrideArgs -f environments/$file"
done
fi
basePath=${basePath:-"$namespace.dev.buyingcatalogue.digital.nhs.uk"}
if [ -z ${emailServer+x} ] || [ -z ${emailUser+x} ] || [ -z ${emailPassword+x} ]
then
#no email set, so use internal
emailArg="--set email.ingress.hosts[0].host=$basePath"
else
#email set
emailArg="--set email.enabled=false
--set email.disabledUrl=$emailServer
--set email.disabledUserName=$emailUser
--set email.disabledPassword=$emailPassword
--set isapi.serviceDependencies.email.authenticationRequired=true
--set isapi.serviceDependencies.email.allowInvalidCertificate=true
--set isapi.passwordReset.emailMessage.senderAddress=$emailUser
--set isapi.registration.emailMessage.senderAddress=$emailUser
--set ordapi.serviceDependencies.email.authenticationRequired=true
--set ordapi.serviceDependencies.email.allowInvalidCertificate=true
--set ordapi.purchasing.emailMessage.senderAddress=$emailUser"
fi
if [ -n "$ipOverride" ]
then
hostAliases="--set isapi.hostAliases[0].ip=$ipOverride
--set isapi.hostAliases[0].hostnames[0]=$basePath
--set oapi.hostAliases[0].ip=$ipOverride
--set oapi.hostAliases[0].hostnames[0]=$basePath
--set ordapi.hostAliases[0].ip=$ipOverride
--set ordapi.hostAliases[0].hostnames[0]=$basePath
--set pb.hostAliases[0].ip=$ipOverride
--set pb.hostAliases[0].hostnames[0]=$basePath
--set admin.hostAliases[0].ip=$ipOverride
--set admin.hostAliases[0].hostnames[0]=$basePath
--set of.hostAliases[0].ip=$ipOverride
--set of.hostAliases[0].hostnames[0]=$basePath
--set pb-ac-tests.hostAliases[0].ip=$ipOverride
--set pb-ac-tests.hostAliases[0].hostnames[0]=$basePath"
fi
baseUrl="https://$basePath"
baseIdentityUrl="$baseUrl/identity"
dbName=bc-$namespace
saUserStart=$(echo $saUserName | cut -c-3)
saPassStart=$(echo $saPassword | cut -c-3)
dbPassStart=$(echo $dbUserPassword | cut -c-3)
redisPassStart=$(echo $redisPassword | cut -c-3)
azureStorageConnectionStringStart=$(echo $azureStorageConnectionString | cut -c-10)
clientSecretStart=$(echo $clientSecret | cut -c-3)
cookieSecretStart=$(echo $cookieSecret | cut -c-3)
emailPassStart=$(echo $emailPassword | cut -c-3)
printf "launch-or-update-azure.sh
chart = $chart
namespace = $namespace
db-server = $dbServer
db-admin-user = $saUserStart*
db-admin-pass = $saPassStart*
version = $version
wait = $wait
base-path = $basePath
sql-package-args = $sqlPackageArgs
azure-storage-connection-string = $azureStorageConnectionStringStart*
ip = $ipOverride
redis-server = $redisServer
redis-password = $redisPassStart*
file-overrides = $overrideFiles
client-secret = $clientSecretStart*
cookie-secret = $cookieSecretStart*
db-user-pass = $dbPassStart*
email-server = $emailServer
email-user = $emailUser
email-pass = $emailPassStart*
"
sed "s/REPLACENAMESPACE/$namespace/g" environments/azure-namespace-template.yml > namespace.yaml
cat namespace.yaml
kubectl apply -f namespace.yaml
helm upgrade bc $chart -n $namespace -i -f environments/azure.yaml \
$fileOverrideArgs \
--timeout 10m0s \
--set saUserName="$saUserName" \
--set saPassword="$saPassword" \
--set dbPassword="$dbUserPassword" \
--set db.dbs.bapi.name=$dbName-bapi \
--set bapi-db-deploy.db.name=$dbName-bapi \
--set bapi-db-deploy.db.sqlPackageArgs="$sqlPackageArgs" \
--set db.dbs.isapi.name=$dbName-isapi \
--set isapi-db-deploy.db.name=$dbName-isapi \
--set isapi-db-deploy.db.sqlPackageArgs="$sqlPackageArgs" \
--set db.dbs.ordapi.name=$dbName-ordapi \
--set ordapi-db-deploy.db.name=$dbName-ordapi \
--set ordapi-db-deploy.db.sqlPackageArgs="$sqlPackageArgs" \
--set db.disabledUrl=$dbServer \
--set clientSecret="$clientSecret" \
--set cookieSecret="$cookieSecret" \
--set appBaseUrl=$baseUrl \
--set baseIsapiEnabledUrl=$baseIdentityUrl \
--set isapi.clients[0].redirectUrls[0]=$baseUrl/oauth/callback \
--set isapi.clients[0].redirectUrls[1]=$baseUrl/admin/oauth/callback \
--set isapi.clients[0].redirectUrls[2]=$baseUrl/order/oauth/callback \
--set isapi.clients[0].postLogoutRedirectUrls[0]=$baseUrl/signout-callback-oidc \
--set isapi.clients[0].postLogoutRedirectUrls[1]=$baseUrl/admin/signout-callback-oidc \
--set isapi.clients[0].postLogoutRedirectUrls[2]=$baseUrl/order/signout-callback-oidc \
--set isapi.ingress.hosts[0].host=$basePath \
--set mp.ingress.hosts[0].host=$basePath \
--set pb.ingress.hosts[0].host=$basePath \
--set pb.baseUri=$baseUrl \
--set admin.ingress.hosts[0].host=$basePath \
--set of.ingress.hosts[0].host=$basePath \
--set redis-commander.ingress.hosts[0].host=$basePath \
--set azurite.connectionString="$azureStorageConnectionString" \
--set redis.disabledUrl=$redisServer \
--set redisPassword="$redisPassword" \
--set allure.ingress.hosts[0].host=$basePath \
$versionArg \
$waitArg \
$emailArg \
$helmUpgradeArgs \
$hostAliases