-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeployment.sh
executable file
·216 lines (163 loc) · 6.32 KB
/
deployment.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
#!/bin/bash -x
#Create CodeCommit repo
REGION=$(aws configure get region)
aws codecommit get-repository --repository-name aws-saas-factory-ref-serverless-saas
if [[ $? -ne 0 ]]; then
echo "aws-saas-factory-ref-serverless-saas codecommit repo is not present, will create one now"
CREATE_REPO=$(aws codecommit create-repository --repository-name aws-saas-factory-ref-serverless-saas --repository-description "Serverless saas reference architecture repository")
echo $CREATE_REPO
REPO_URL="codecommit::${REGION}://aws-saas-factory-ref-serverless-saas"
git remote add cc $REPO_URL
if [[ $? -ne 0 ]]; then
echo "Setting url to remote cc"
git remote set-url cc $REPO_URL
fi
git push --set-upstream cc main
fi
#Deploying CI/CD pipeline
cd server/TenantPipeline/
npm install && npm run build
cdk bootstrap
cdk deploy
if [[ $? -ne 0 ]]; then
exit 1
fi
# Deploying bootstrap
cd ../
DEFAULT_SAM_S3_BUCKET=$(grep s3_bucket samconfig-bootstrap.toml|cut -d'=' -f2 | cut -d \" -f2)
echo "aws s3 ls s3://$DEFAULT_SAM_S3_BUCKET"
aws s3 ls s3://$DEFAULT_SAM_S3_BUCKET
if [ $? -ne 0 ]; then
echo "S3 Bucket: $DEFAULT_SAM_S3_BUCKET specified in samconfig-bootstrap.toml is not readable.
So creating a new S3 bucket and will update samconfig-bootstrap.toml with new bucket name."
UUID=$(uuidgen | awk '{print tolower($0)}')
SAM_S3_BUCKET=sam-bootstrap-bucket-$UUID
aws s3 mb s3://$SAM_S3_BUCKET --region $REGION
if [[ $? -ne 0 ]]; then
exit 1
fi
# Updating samconfig-bootstrap.toml with new bucket name
ex -sc '%s/s3_bucket = .*/s3_bucket = \"'$SAM_S3_BUCKET'\"/|x' samconfig-bootstrap.toml
fi
sam build -t bootstrap-template.yaml --use-container --region=$REGION
sam deploy --config-file samconfig-bootstrap.toml --region=$REGION --parameter-overrides AdminEmailParameter=$1
if [[ $? -ne 0 ]]; then
exit 1
fi
# Start CI/CD pipepline which loads tenant stack
aws codepipeline start-pipeline-execution --name serverless-saas-pipeline
ADMIN_SITE_BUCKET=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-AdminAppBucket'].Value" --output text )
APP_SITE_BUCKET=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-AppBucket'].Value" --output text )
LANDING_APP_SITE_BUCKET=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-LandingAppBucket'].Value" --output text )
ADMIN_SITE_URL=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-AdminAppSite'].Value" --output text )
APP_SITE_URL=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-ApplicationSite'].Value" --output text )
LANDING_APP_SITE_URL=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-LandingApplicationSite'].Value" --output text )
ADMIN_APPCLIENTID=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-AdminUserPoolClientId'].Value" --output text )
ADMIN_AUTHSERVERURL=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-AdminUserPoolProviderURL'].Value" --output text )
ADMIN_APIGATEWAYURL=$(aws cloudformation list-exports --query "Exports[?Name=='Serverless-SaaS-AdminApiGatewayUrl'].Value" --output text )
# Configuring admin UI
echo "aws s3 ls s3://$ADMIN_SITE_BUCKET"
aws s3 ls s3://$ADMIN_SITE_BUCKET
if [ $? -ne 0 ]; then
echo "Error! S3 Bucket: $ADMIN_SITE_BUCKET not readable"
exit 1
fi
cd ../
CURRENT_DIR=$(pwd)
echo "Current Dir: $CURRENT_DIR"
cd clients/Admin
echo "Configuring environment for Admin Client"
cat << EoF > ./src/environments/environment.prod.ts
export const environment = {
production: true,
clientId: '$ADMIN_APPCLIENTID',
issuer: '$ADMIN_AUTHSERVERURL',
apiGatewayUrl: '$ADMIN_APIGATEWAYURL',
domain: ''
};
EoF
cat << EoF > ./src/environments/environment.ts
export const environment = {
production: true,
clientId: '$ADMIN_APPCLIENTID',
issuer: '$ADMIN_AUTHSERVERURL',
apiGatewayUrl: '$ADMIN_APIGATEWAYURL',
domain: ''
};
EoF
npm install --legacy-peer-deps && npm run build
echo "aws s3 sync --delete --cache-control no-store dist s3://$ADMIN_SITE_BUCKET"
aws s3 sync --delete --cache-control no-store dist s3://$ADMIN_SITE_BUCKET
if [[ $? -ne 0 ]]; then
exit 1
fi
echo "Completed configuring environment for Admin Client"
# Configuring application UI
echo "aws s3 ls s3://$APP_SITE_BUCKET"
aws s3 ls s3://$APP_SITE_BUCKET
if [ $? -ne 0 ]; then
echo "Error! S3 Bucket: $APP_SITE_BUCKET not readable"
exit 1
fi
cd ../
CURRENT_DIR=$(pwd)
echo "Current Dir: $CURRENT_DIR"
cd Application
echo "Configuring environment for App Client"
cat << EoF > ./src/environments/environment.prod.ts
export const environment = {
production: true,
regApiGatewayUrl: '$ADMIN_APIGATEWAYURL',
domain: ''
};
EoF
cat << EoF > ./src/environments/environment.ts
export const environment = {
production: true,
regApiGatewayUrl: '$ADMIN_APIGATEWAYURL',
domain: ''
};
EoF
npm install --legacy-peer-deps && npm run build
echo "aws s3 sync --delete --cache-control no-store dist s3://$APP_SITE_BUCKET"
aws s3 sync --delete --cache-control no-store dist s3://$APP_SITE_BUCKET
if [[ $? -ne 0 ]]; then
exit 1
fi
echo "Completed configuring environment for App Client"
# Configuring landing UI
echo "aws s3 ls s3://$LANDING_APP_SITE_BUCKET"
aws s3 ls s3://$LANDING_APP_SITE_BUCKET
if [ $? -ne 0 ]; then
echo "Error! S3 Bucket: $LANDING_APP_SITE_BUCKET not readable"
exit 1
fi
cd ../
CURRENT_DIR=$(pwd)
echo "Current Dir: $CURRENT_DIR"
cd Landing
echo "Configuring environment for Landing Client"
cat << EoF > ./src/environments/environment.prod.ts
export const environment = {
production: true,
apiGatewayUrl: '$ADMIN_APIGATEWAYURL'
};
EoF
cat << EoF > ./src/environments/environment.ts
export const environment = {
production: true,
apiGatewayUrl: '$ADMIN_APIGATEWAYURL'
};
EoF
npm install --legacy-peer-deps && npm run build
echo "aws s3 sync --delete --cache-control no-store dist s3://$LANDING_APP_SITE_BUCKET"
aws s3 sync --delete --cache-control no-store dist s3://$LANDING_APP_SITE_BUCKET
if [[ $? -ne 0 ]]; then
exit 1
fi
cd ../..
echo "Completed configuring environment for Landing Client"
echo "Admin site URL: https://$ADMIN_SITE_URL"
echo "Application site URL: https://$APP_SITE_URL"
echo "Landing site URL: https://$LANDING_APP_SITE_URL"
echo "Successfully completed deployment"