-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathsam-deploy-authdevs.sh
More file actions
executable file
·280 lines (230 loc) · 8.54 KB
/
sam-deploy-authdevs.sh
File metadata and controls
executable file
·280 lines (230 loc) · 8.54 KB
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
#!/usr/bin/env bash
set -euo pipefail
# Ensure we're in the root directory of the repo
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
environments=("authdev1" "authdev2" "authdev3" "dev")
# -------------
# Prerequisites
# -------------
if ! command -v rain &> /dev/null; then
echo "Merging templates requires rain to be installed. See https://github.com/aws-cloudformation/rain for installation instructions."
exit 1
fi
if ! command -v sam &> /dev/null; then
echo "Deploying template requires AWS sam cli to be installed. See https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.html for installation instructions."
exit 1
fi
function usage() {
cat <<- USAGE
Usage:
$0 [options]
Options:
-a --AccMgmt deploy the Account Management APIs
-b, --build run gradle and buildZip tasks
--no-build do not run gradle and buildZip tasks
-p, --prompt prompt for confirmation before sam deploy
-c, --clean run gradle clean before build
-h, --help display this help message
-x, --authapi deploy the Auth Int & ext API
-s --Stubsapi deploy the Stubs API
-d --actdataapi deploy the Account data API
-u, --utils deploy the Utils stack
Dependencies:
AWS CLI, AWS SAM, rain
USAGE
}
if [ $# -lt 1 ]; then
usage
exit 1
fi
function sso_login() {
export AWS_ACCOUNT=di-authentication-development
export AWS_PROFILE=di-authentication-development-AdministratorAccessPermission
export AWS_REGION="eu-west-2"
if ! aws sts get-caller-identity &> /dev/null; then
aws sso login --profile "${AWS_PROFILE}"
fi
}
O_DEPLOYAM=0 # -a, --accmgmt
O_BUILD=0 # -b, --build
O_CLEAN="" # -c, --clean
O_DEPLOYAUTHAPI=0 # -x, --auth-internal-external-api
O_DEPLOYSTUBSAPI=0 # -s, --stubs-api
O_DEPLOYUTILS=0 # -u, --utils
O_DEPLOYACTDATAAPI=0 # -d, --accdata-api
AMAPI_TEMPLATE_FILE="${TEMPLATE_FILE:-${DIR}/am-template.yaml}"
AUTHAPI_TEMPLATE_FILE="${TEMPLATE_FILE:-${DIR}/auth-template.yaml}"
ADAPI_TEMPLATE_FILE="${TEMPLATE_FILE:-${DIR}/ad-template.yaml}"
STUBSAPI_TEMPLATE_FILE="${TEMPLATE_FILE:-${DIR}/stubs-template.yaml}"
UTILS_TEMPLATE_FILE="${TEMPLATE_FILE:-${DIR}/utils-template.yaml}"
SAMCONFIG_FILE=${SAMCONFIG_FILE:-${DIR}/scripts/dev-samconfig.toml}
CONFIRM_CHANGESET_OPTION="--no-confirm-changeset"
while [[ $# -gt 0 ]]; do
case "${1}" in
-a | --accmgmt) O_DEPLOYAM=1 ;;
-b | --build) O_BUILD=1 ;;
--no-build) O_BUILD=0 ;;
-p | --prompt) CONFIRM_CHANGESET_OPTION="--confirm-changeset" ;;
-c | --clean) O_CLEAN="clean" ;;
-x | --authapi) O_DEPLOYAUTHAPI=1 ;;
-s | --stubsapi) O_DEPLOYSTUBSAPI=1 ;;
-d | --actdataapi) O_DEPLOYACTDATAAPI=1 ;;
-u | --utils) O_DEPLOYUTILS=1 ;;
-h | --help)
usage
exit 0
;;
-*)
usage
exit 1
;;
*)
echo "Error: Unknown argument: $1"
usage
exit 1
;;
esac
shift
done
echo "Select environment:"
select env in "${environments[@]}"; do
if [[ -n ${env} ]]; then
ENVIRONMENT=${env}
break
else
echo "Invalid selection. Please try again."
fi
done
echo "You are going to deploy in ${ENVIRONMENT}"
read -r -p "Press enter to continue or Ctrl+C to abort"
echo "Environment: ${ENVIRONMENT}"
if [[ ${O_BUILD} -eq 1 ]]; then
echo "Building deployment artefacts ... "
./gradlew --no-daemon --parallel ${O_CLEAN} buildZip
echo "done!"
fi
if [[ ${O_DEPLOYAUTHAPI} -eq 1 ]]; then
sso_login
echo "Merging all ${DIR}/ci/cloudformation/auth templates into a single ${AUTHAPI_TEMPLATE_FILE}"
# shellcheck disable=SC2046
rain merge $(find "${DIR}/ci/cloudformation/auth" -type f \( -name "*.yaml" -o -name "*.yml" \) -print) -o "${AUTHAPI_TEMPLATE_FILE}"
echo "Lint template file"
sam validate --lint --template-file="${AUTHAPI_TEMPLATE_FILE}"
echo "Running sam build on template file"
sam build --parallel --template-file="${AUTHAPI_TEMPLATE_FILE}"
sam deploy \
--no-fail-on-empty-changeset \
--config-env "${ENVIRONMENT}" \
--config-file "${SAMCONFIG_FILE}" \
${CONFIRM_CHANGESET_OPTION}
echo "Deployment complete!"
fi
if [[ ${O_DEPLOYAM} -eq 1 ]]; then
sso_login
if [[ ${ENVIRONMENT} == "dev" ]]; then
SAM_CONFIG_ENV="devam"
elif [[ ${ENVIRONMENT} == "authdev1" ]]; then
SAM_CONFIG_ENV="authdev1am"
elif [[ ${ENVIRONMENT} == "authdev2" ]]; then
SAM_CONFIG_ENV="authdev2am"
elif [[ ${ENVIRONMENT} == "authdev3" ]]; then
SAM_CONFIG_ENV="authdev3am"
else
SAM_CONFIG_ENV="${ENVIRONMENT}"
fi
echo "Merging all ${DIR}/ci/cloudformation/account-management templates into a single ${AMAPI_TEMPLATE_FILE}"
# shellcheck disable=SC2046
rain merge $(find "${DIR}/ci/cloudformation/account-management" -type f \( -name "*.yaml" -o -name "*.yml" \) -print) -o "${AMAPI_TEMPLATE_FILE}"
echo "Lint template file"
sam validate --lint --template-file="${AMAPI_TEMPLATE_FILE}"
echo "Running sam build on template file"
sam build --parallel --template-file="${AMAPI_TEMPLATE_FILE}"
sam deploy \
--no-fail-on-empty-changeset \
--config-env "${SAM_CONFIG_ENV}" \
--config-file "${SAMCONFIG_FILE}" \
${CONFIRM_CHANGESET_OPTION}
echo "Deployment complete!"
fi
if [[ ${O_DEPLOYSTUBSAPI} -eq 1 ]]; then
sso_login
if [[ ${ENVIRONMENT} == "dev" ]]; then
SAM_CONFIG_ENV="devstubs"
elif [[ ${ENVIRONMENT} == "authdev1" ]]; then
SAM_CONFIG_ENV="authdev1stubs"
elif [[ ${ENVIRONMENT} == "authdev2" ]]; then
SAM_CONFIG_ENV="authdev2stubs"
elif [[ ${ENVIRONMENT} == "authdev3" ]]; then
SAM_CONFIG_ENV="authdev3stubs"
else
SAM_CONFIG_ENV="${ENVIRONMENT}"
fi
echo "Merging all ${DIR}/ci/cloudformation/stubs templates into a single ${STUBSAPI_TEMPLATE_FILE}"
# shellcheck disable=SC2046
rain merge $(find "${DIR}/ci/cloudformation/stubs" -type f \( -name "*.yaml" -o -name "*.yml" \) -print) -o "${STUBSAPI_TEMPLATE_FILE}"
echo "Lint template file"
sam validate --lint --template-file="${STUBSAPI_TEMPLATE_FILE}"
echo "Running sam build on template file"
sam build --parallel --template-file="${STUBSAPI_TEMPLATE_FILE}"
sam deploy \
--no-fail-on-empty-changeset \
--config-env "${SAM_CONFIG_ENV}" \
--config-file "${SAMCONFIG_FILE}" \
${CONFIRM_CHANGESET_OPTION}
echo "Deployment complete!"
fi
if [[ ${O_DEPLOYACTDATAAPI} -eq 1 ]]; then
sso_login
if [[ ${ENVIRONMENT} == "dev" ]]; then
SAM_CONFIG_ENV="devad"
elif [[ ${ENVIRONMENT} == "authdev1" ]]; then
SAM_CONFIG_ENV="authdev1ad"
elif [[ ${ENVIRONMENT} == "authdev2" ]]; then
SAM_CONFIG_ENV="authdev2ad"
elif [[ ${ENVIRONMENT} == "authdev3" ]]; then
SAM_CONFIG_ENV="authdev3ad"
else
SAM_CONFIG_ENV="${ENVIRONMENT}"
fi
echo "Merging all ${DIR}/ci/cloudformation/account-datas templates into a single ${ADAPI_TEMPLATE_FILE}"
# shellcheck disable=SC2046
rain merge $(find "${DIR}/ci/cloudformation/account-data" -type f \( -name "*.yaml" -o -name "*.yml" \) -print) -o "${ADAPI_TEMPLATE_FILE}"
echo "Lint template file"
sam validate --lint --template-file="${ADAPI_TEMPLATE_FILE}"
echo "Running sam build on template file"
sam build --parallel --template-file="${ADAPI_TEMPLATE_FILE}"
sam deploy \
--no-fail-on-empty-changeset \
--config-env "${SAM_CONFIG_ENV}" \
--config-file "${SAMCONFIG_FILE}" \
${CONFIRM_CHANGESET_OPTION}
echo "Deployment complete!"
fi
if [[ ${O_DEPLOYUTILS} -eq 1 ]]; then
sso_login
if [[ ${ENVIRONMENT} == "dev" ]]; then
SAM_CONFIG_ENV="devutils"
elif [[ ${ENVIRONMENT} == "authdev1" ]]; then
SAM_CONFIG_ENV="authdev1utils"
elif [[ ${ENVIRONMENT} == "authdev2" ]]; then
SAM_CONFIG_ENV="authdev2utils"
elif [[ ${ENVIRONMENT} == "authdev3" ]]; then
SAM_CONFIG_ENV="authdev3utils"
else
SAM_CONFIG_ENV="${ENVIRONMENT}"
fi
echo "Merging all ${DIR}/ci/cloudformation/utils templates into a single ${UTILS_TEMPLATE_FILE}"
# shellcheck disable=SC2046
rain merge $(find "${DIR}/ci/cloudformation/utils" -type f \( -name "*.yaml" -o -name "*.yml" \) -print) -o "${UTILS_TEMPLATE_FILE}"
sed -i '' 's/Mode: OFF/Mode: "OFF"/g' "${UTILS_TEMPLATE_FILE}"
echo "Lint template file"
sam validate --lint --template-file="${UTILS_TEMPLATE_FILE}"
echo "Running sam build on template file"
sam build --parallel --template-file="${UTILS_TEMPLATE_FILE}"
sam deploy \
--no-fail-on-empty-changeset \
--config-env "${SAM_CONFIG_ENV}" \
--config-file "${SAMCONFIG_FILE}" \
${CONFIRM_CHANGESET_OPTION}
echo "Deployment complete!"
fi