-
Notifications
You must be signed in to change notification settings - Fork 0
277 lines (234 loc) · 11.6 KB
/
p2-aus.yml
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
################################################
# GITHUB ACTION WORKFLOW NAME
################################################
name: Deploy to p2-aus live environment
################################################
# GITHUB ACTION EVENT TRIGGER
################################################
on:
workflow_dispatch:
inputs:
BRANCH_TAG_NAME:
description: 'New tag version based on create-release-tag workflow'
required: true
default: ''
################################################
# GITHUB ACTION JOBS
################################################
jobs:
deploy-p2-aus-live:
name: deploy-p2-aus-live
runs-on: ubuntu-latest
permissions: write-all
environment: p2-aus
timeout-minutes: 15
################################################
# GITHUB ACTIONS GLOBAL ENV VARIABLES
################################################
env:
REGION : ap-southeast-2
ENV : live # Valid values are dev,test,live only
STACK_NAME: p2-aus # Valid values are au,us,uk,p2,lf,nu,p1-sandbox,p1-stage,p2-sandbox,shared only
ROOTSTACK: cutie-app
CFNS3BucketName: devops-cfn-templates
PRIVATES3BucketName: devops-shared-private
PUBLICZONENAME: aus.practera.com
BUILD_CONFIG: custom
STATUSREPORTS3Bucket: deployment-status.practera.com
STATUS: DEPLOYED
REQUESTOR: ${{ github.event.inputs.REQUESTOR }}
REASON: ${{ github.event.inputs.REASON }}
ENDPOINT: cutie-app.aus.practera.com
BRANCH_TAG_NAME: ${{ github.event.inputs.BRANCH_TAG_NAME }}
AWS_ACCOUNT_ID: ${{ secrets.AWS_ACCOUNT_ID }}
################################################
# GITHUB REPO CHECKOUT
################################################
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
ref: ${{ github.event.inputs.BRANCH_TAG_NAME }}
################################################
# NODE ENV
################################################
- name: Setup Node.js environment
uses: actions/setup-node@v2
with:
node-version: '14'
################################################
# NODE MODULES CACHE
################################################
- name: Cache node modules
uses: actions/cache@v2
id: cache-node-modules
env:
cache-name: cache
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: |
~/.npm
node_modules
*/*/node_modules
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('**/package.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
################################################
# NODE MODULES INSTALL
################################################
- name: Install dependencies
if: steps.cache-node-modules.outputs.cache-hit != 'true'
run: npm install
################################################
# GET P2AUS AWS ORGANIZATION NUMBER
################################################
- name: Get AWS Organization Number
id: AWS_ORG
run: |
P2AUS=$(echo $AWS_ACCOUNT_ID | jq -r .P2AUS)
echo "::add-mask::$P2AUS"
echo "P2AUS=$P2AUS" >> $GITHUB_OUTPUT
################################################
# AWS CLI CONFIGURATION - DEVOPS P2AUS
################################################
- name: Configure AWS Credentials from P2AUS account
uses: ./.github/actions/aws-oidc
with:
role-to-assume: arn:aws:iam::${{ steps.AWS_ORG.outputs.P2AUS }}:role/github-restricted-role-to-assume
region: ${{ env.REGION }}
##########################################################
# AWS S3 SYNC - SERVERLESS TEMPLATES
##########################################################
- name: AWS S3 Sync operation
run: |
aws s3 cp serverless.yml s3://$CFNS3BucketName/$STACK_NAME/$REGION/$ROOTSTACK/sls-templates/serverless.yml
##########################################################
# CLOUDFORMATION EXPORT VARIABLES
##########################################################
- name: Cloudformation Export variables
run: |
cat >> .env <<EOF
CDNSharedACMCertificateArn=$(aws cloudformation list-exports --query "Exports[?Name==\`$STACK_NAME-CDNSharedACMCertificateArn-$ENV\`].Value" --no-paginate --output text)
ChatBotSNSTopicARN=$(aws cloudformation list-exports --query "Exports[?Name==\`$STACK_NAME-ChatBotSNSTopicARN-$ENV\`].Value" --no-paginate --output text)
EOF
###############################################################
# SERVERLESS DEPLOYMENT
##############################################################
- name: Serverless deployment
run: |
echo "Serverless Deploying"
node_modules/.bin/serverless deploy
rm serverless.yml
env:
CUTIES3BUCKET: cutie-app.${{ env.PUBLICZONENAME }}
S3VERSIONING: true
NONCURRENTVERSION_EXPIREINDAYS: 30
# DEFAULT_EXPIREINDAYS: 0 # Mandatory to disable
###############################################################
# ANGULAR ENVIRONMENT CREATION
##############################################################
- name: Angular Environment creation
run: |
printf "Creating required secret variables for angular environment variable creation\n\n"
export CUSTOM_APPKEY=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-AppKeySecret-$ENV| jq --raw-output '.SecretString' | jq -r .appkey)
export CUSTOM_FILESTACK_SIGNATURE=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-FilestackSecret-$ENV| jq --raw-output '.SecretString' | jq -r .signature)
export CUSTOM_FILESTACK_VIRUS_DETECTION=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-FilestackSecret-$ENV| jq --raw-output '.SecretString' | jq -r .virusdetection)
export CUSTOM_FILESTACK_KEY=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-FilestackSecret-$ENV| jq --raw-output '.SecretString' | jq -r .apikey)
export CUSTOM_FILESTACK_POLICY=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-FilestackSecret-$ENV| jq --raw-output '.SecretString' | jq -r .policy)
export CUSTOM_PUSHER_APPID=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-PusherSecret-$ENV| jq --raw-output '.SecretString' | jq -r .app_id)
export CUSTOM_PUSHERKEY=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-PusherSecret-$ENV| jq --raw-output '.SecretString' | jq -r .key)
export CUSTOM_PUSHER_SECRET=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-PusherSecret-$ENV| jq --raw-output '.SecretString' | jq -r .secret)
export CUSTOM_PUSHER_CLUSTER=$(aws secretsmanager get-secret-value --secret-id $STACK_NAME-PusherSecret-$ENV| jq --raw-output '.SecretString' | jq -r .cluster)
printf "Angular environment variable creation complete\n\n"
printf "Executing env.sh script\n\n"
chmod +x env.sh && ./env.sh
env:
CUSTOM_APPENV: ${{ env.ENV }}
CUSTOM_AWS_REGION_CHINA: ap-northeast-2 #TODO CHECK
CUSTOM_S3_BUCKET_CHINA: practera-seoul-1 #TODO CHECK
CUSTOM_CHATGEAPHQLENDPOINT: https://chat-api.${{ env.PUBLICZONENAME }}/
CUSTOM_PATH_IMAGE: /cutie/image/uploads/
CUSTOM_AWS_REGION: ${{ env.REGION }}
CUSTOM_PATH_ANY: /cutie/any/uploads/
CUSTOM_S3_BUCKET: files.${{ env.PUBLICZONENAME }}
CUSTOM_APIENDPOINT: https://cutie-api.${{ env.PUBLICZONENAME }}/
CUSTOM_APIENDPOINTOLD: https://${{ env.PUBLICZONENAME }}/
CUSTOM_PRACTERCORE: https://${{ env.PUBLICZONENAME }}/
CUSTOM_PATH_VIDEO: /cutie/video/uploads/
CUSTOM_GEAPHQLENDPOINT: https://core-graphql-api.${{ env.PUBLICZONENAME }}/
###############################################################
# BUILD WEB PACKAGES
##############################################################
- name: Build Web Packages
run: |
printf '' > src/environments/environment.ts
node_modules/.bin/ng build --configuration=${{ env.BUILD_CONFIG }}
##########################################################
# AWS S3 SYNC OPERATIONS
##########################################################
- name: AWS S3 Sync Operations
run: |
CUTIEAPPS3=$(aws cloudformation list-exports --query "Exports[?Name==\`$STACK_NAME-CUTIES3BUCKET-$ENV\`].Value" --no-paginate --output text)
aws s3 sync www/ s3://$CUTIEAPPS3 --delete
##########################################################
# AWS CDN CACHE INVALIDATION
##########################################################
- name: AWS Cloudfront Cache invalidation
run: |
CUTIEAPPCDN=$(aws cloudformation list-exports --query "Exports[?Name==\`$STACK_NAME-CutieCloudFrontDistributionID-$ENV\`].Value" --no-paginate --output text)
for i in $CUTIEAPPCDN;do aws cloudfront create-invalidation --distribution-id $i --paths "/*";done
##########################################################
# SLACK NOTIFICATION
##########################################################
- name: Slack Notification
if: always() # Pick up events even if the job fails or is canceled.
uses: 8398a7/action-slack@v3
env:
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
MATRIX_CONTEXT: ${{ toJson(matrix) }} # required
with:
status: ${{ job.status }}
author_name: ${{ env.BRANCH_TAG_NAME }} - ${{ env.ROOTSTACK }} deployed to ${{ env.ENV }} environemnt in ${{ env.STACK_NAME }} AWS account
mention: 'here'
if_mention: failure,cancelled
job_name: deploy-p2-aus-live # Match the name above.
fields: repo,commit,eventName,ref,workflow,message,author,job,took
custom_payload: |
{
username: 'GitHub Action CI WorkFlow',
icon_emoji: ':github:',
attachments: [{
color: '${{ job.status }}' === 'success' ? 'good' : ${{ job.status }}' === 'failure' ? 'danger' : 'warning',
text:
`${process.env.AS_REPO}\n
${process.env.AS_COMMIT}\n
${process.env.AS_EVENT_NAME}\n
@${process.env.AS_REF}\n
@${process.env.AS_WORKFLOW}\n
${process.env.AS_MESSAGE}\n
${process.env.AS_AUTHOR}\n
${process.env.AS_JOB}\n
${process.env.AS_TOOK}`,
}]
}
# ################################################
# # STATUS VARIABLE UPDATE
# ################################################
- name: Deployment status variable update
if: ${{ failure() }}
run: |
echo "STATUS=FAILURE" >> $GITHUB_ENV
# ################################################
# # DEVOPS-DEPLOYMENT REPORT
# ################################################
- name: DevOps Deployment Reporting
if: always()
run: |
pip install --upgrade pip
pip install --upgrade csvtotable
export REASON=$(git log -2 --format=%s | sed -n 2p)
export REQUESTOR=${{ github.actor }}
aws s3 cp s3://$STATUSREPORTS3Bucket/deploy-reporting.sh deploy-reporting.sh
chmod +x deploy-reporting.sh && ./deploy-reporting.sh