forked from OfficeForProductSafetyAndStandards/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy.sh
executable file
·62 lines (50 loc) · 1.68 KB
/
deploy.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
#!/usr/bin/env bash
set -ex
# This is the CI server script to package and deploy Keycloak
#
# The working directory should be the git root
#
# The caller should have the following environment variables set:
#
# SPACE: the space to which you want to deploy
DOMAIN=opss-access.service.gov.uk
if [[ $SPACE == "prod" ]]; then
HOSTNAME=www
elif [[ $SPACE == "research" ]]; then
HOSTNAME="keycloak-research"
DOMAIN=london.cloudapps.digital
else
HOSTNAME=$SPACE
fi
APP=keycloak
APP_PREEXISTS=$(cf7 app $APP && echo 0 || echo 1)
if [[ $APP_PREEXISTS ]]; then
# We should deploy to a temporary location such that we can do a blue-green deployment
NEW_HOSTNAME=$HOSTNAME-temp
NEW_APP=$APP-temp
else
# We don't need to deploy to a temporary location
echo "No existing app found. Performing first-time setup."
NEW_HOSTNAME=$HOSTNAME
NEW_APP=$APP
fi
docker build --target keycloak-package -t keycloak-package:latest .
docker cp $(docker create keycloak-package):/tmp/keycloak/package .
# Copy the environment helper script
cp -a ./env ./package/env/
# Deploy the new app, set the hostname and start the app
cf7 push $NEW_APP -f manifest.yml --var hostname=$NEW_HOSTNAME.$DOMAIN
if [[ ! $APP_PREEXISTS ]]; then
# We don't need to go any further
exit 0
fi
# TODO smoke test or manual confirmation?
# Unmap the temporary hostname from the new app
cf7 unmap-route $NEW_APP $DOMAIN --hostname $NEW_HOSTNAME
# Map the live hostname to the new app
cf7 map-route $NEW_APP $DOMAIN --hostname $HOSTNAME
# Unmap the live hostanme from the old app
cf7 unmap-route $APP $DOMAIN --hostname $HOSTNAME
# Remove the old app and rename the new one
cf7 delete -f $APP
cf7 rename $NEW_APP $APP