forked from aws-samples/aws-alien-attack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.frontend.sh
More file actions
executable file
·85 lines (78 loc) · 2.91 KB
/
deploy.frontend.sh
File metadata and controls
executable file
·85 lines (78 loc) · 2.91 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
#!/bin/bash
##
# Deploys the front-end
##
txtgrn=$(tput setaf 2) # Green
txtylw=$(tput setaf 3) # Yellow
txtblu=$(tput setaf 4) # Blue
txtpur=$(tput setaf 5) # Purple
txtcyn=$(tput setaf 6) # Cyan
txtwht=$(tput setaf 7) # White
txtrst=$(tput sgr0) # Text reset
_DEBUG="on"
function EXECUTE() {
[ "$_DEBUG" == "on" ] && echo $@ || $@
}
function title() {
tput rev
showHeader $@
tput sgr0
}
function showHeader() {
input=$@
echo ${txtgrn}
printf "%0.s-" $(seq 1 ${#input})
printf "\n"
echo $input
printf "%0.s-" $(seq 1 ${#input})
echo ${txtrst}
}
function showSectionTitle() {
echo
echo --- ${txtblu} $@ ${txtrst}
echo
}
envnameuppercase=$(echo $envname | tr 'a-z' 'A-Z')
envnamelowercase=$(echo $envname | tr 'A-Z' 'a-z')
#-------------------------------------------
# Introduction
#-------------------------------------------
title "DEPLOYING THE FRONT-END FOR THE ENVIRONMENT $envnameuppercase"
## Fixing Cognito is required only for the workshop
#showHeader Fixing Cognito
#source fixcognito.sh
#-------------------------------------------
# Retrieving parameters from CloudFormation
#-------------------------------------------
apigtw=$(eval $(echo "aws cloudformation list-exports --query 'Exports[?contains(ExportingStackId,\`$envname\`) && Name==\`${envnamelowercase}:apigtw\`].Value | [0]' | xargs -I {} echo {}"))
region=$(eval $(echo "aws cloudformation list-exports --query 'Exports[?contains(ExportingStackId,\`$envname\`) && Name==\`${envnamelowercase}:region\`].Value | [0]' | xargs -I {} echo {}"))
url=$(eval $(echo "aws cloudformation list-exports --query 'Exports[?contains(ExportingStackId,\`$envname\`) && Name==\`${envnamelowercase}:url\`].Value | [0]' | xargs -I {} echo {}"))
resetpassurl=$(eval $(echo "aws cloudformation list-exports --query 'Exports[?contains(ExportingStackId,\`$envname\`) && Name==\`${envnamelowercase}:resetpassurl\`].Value | [0]' | xargs -I {} echo {}"))
#-------------------------------------------
# UPDATING /application/resources/js/awsconfig.js
#-------------------------------------------
showHeader "UPDATING /application/resources/js/awsconfig.js"
cat <<END > ./../application/resources/js/awsconfig.js
const DEBUG = true;
const AWS_CONFIG = {
"region" : "$region",
"API_ENDPOINT" : "$apigtw",
"APPNAME" : "$envnameuppercase",
"RESET_PASS_URL" : "$resetpassurl"
};
END
more ./../application/resources/js/awsconfig.js
#-------------------------------------------
# DEPLOYING THE WEBSITE ON S3
#-------------------------------------------
showHeader "DEPLOYING THE WEBSITE ON S3"
aws s3 cp ./../application s3://$envnamelowercase.app --recursive
#-------------------------------------------
# Finalization
#-------------------------------------------
title "Environment $envnameuppercase deployed"
if [ "$url" == "" ]; then
echo "You DON'T have a CloudFront distribution deployed. Please deploy it."
else
echo "URL: https://$url"
fi