forked from aws-solutions/performance-dashboard-on-aws
-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·144 lines (124 loc) · 3.99 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
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
#!/bin/bash
set -e
# Set workspace paths
WORKSPACE=$(pwd)
CDK_DIR=$WORKSPACE/cdk
FRONTEND_DIR=$WORKSPACE/frontend
BACKEND_DIR=$WORKSPACE/backend
EXAMPLES_DIR=$WORKSPACE/examples
# Validate environment name from input
environment=$1
if [ "$environment" != "" ]; then
echo "Environment = $environment"
export CDK_ENV_NAME=$environment
else
echo "Please specify environment name as first argument (i.e. dev)"
exit 0
fi
exampleLanguage=${2:-english}
if [ "$exampleLanguage" != "" ]; then
echo "Example Language = $exampleLanguage"
else
echo "Please specify an example language name as second argument (i.e. english|spanish|portuguese)"
exit 0
fi
authenticationRequired=${3:-no}
if [ "$authenticationRequired" != "" ]; then
echo "Authentication Required = $authenticationRequired"
export AUTHENTICATION_REQUIRED=$authenticationRequired
else
echo "Please specify if authentication is required (true|false)"
exit 0
fi
cname=${4:-}
if [ "$authenticationRequired" != "" ]; then
echo "CNAME = $cname"
export CNAME=$cname
else
echo "No CNAME passed"
fi
verify_prereqs() {
# Verify necessary commands
echo "node version"
node --version
echo "npm version"
npm --version
echo "cdk version"
$CDK_DIR/node_modules/aws-cdk/bin/cdk --version
}
create_build_directories() {
# CDK complains if the backend/build, frontend/build, and examples/build
# directories don't exist during synth. So we need to trick
# CDK by creating empty directories for now. Later on, these
# directories will be populated by building the backend and
# frontend for real.
mkdir -p $FRONTEND_DIR/build
mkdir -p $BACKEND_DIR/build
mkdir -p $EXAMPLES_DIR/build
}
deploy_auth() {
# Deploys the Authentication stack with CDK.
# Auth stack definition is in cdk/lib/auth-stack.ts
echo "Deploying auth stack"
cd $CDK_DIR
npm run cdk -- deploy Auth --require-approval never --parameters authenticationRequired=$authenticationRequired
}
deploy_authz() {
# Deploys the Authorization stack with CDK.
# Authz stack definition is in cdk/lib/authz-stack.ts
echo "Deploying authz stack"
cd $CDK_DIR
if [ "$CDK_ADMIN_EMAIL" != "" ]; then
npm run cdk -- deploy Authz --require-approval never --parameters PerformanceDash-${environment}-Authz:adminEmail=$CDK_ADMIN_EMAIL --parameters authenticationRequired=$authenticationRequired
else
npm run cdk -- deploy Authz --require-approval never --parameters authenticationRequired=$authenticationRequired
fi
}
deploy_backend() {
echo "Building backend application"
cd $BACKEND_DIR
npm run build
cd $CDK_DIR
echo "Deploying backend stack"
npm run cdk -- deploy Backend --require-approval never --outputs-file outputs-backend.json --parameters authenticationRequired=$authenticationRequired --parameters PerformanceDash-${environment}-Backend:domainName=$cname
}
deploy_frontend() {
echo "Building frontend application"
cd $FRONTEND_DIR
npm run build
cd $CDK_DIR
echo "Deploying frontend stack"
npm run cdk -- deploy Frontend --require-approval never --parameters PerformanceDash-${environment}-Frontend:domainName=$cname
}
deploy_frontendConfig() {
cd $CDK_DIR
echo "Deploying frontendConfig stack"
npm run cdk -- deploy FrontendConfig --require-approval never --parameters authenticationRequired=$authenticationRequired
}
deploy_examples() {
echo "Deploying examples"
cd $EXAMPLES_DIR
npm run build
cd $CDK_DIR
npm run cdk -- deploy DashboardExamples --require-approval never --parameters PerformanceDash-${environment}-DashboardExamples:exampleLanguage=$exampleLanguage
}
deploy_ops() {
echo "Deploying ops stack"
cd $CDK_DIR
npm run cdk -- deploy Ops --require-approval never
}
build_cdk() {
cd $CDK_DIR
npm run build
}
# Start execution
verify_prereqs
create_build_directories
build_cdk
deploy_auth
deploy_authz
deploy_frontend
deploy_backend
deploy_frontendConfig
deploy_examples
deploy_ops