-
Notifications
You must be signed in to change notification settings - Fork 38
556 lines (556 loc) · 22.3 KB
/
ci.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
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
name: ci
on:
push:
pull_request:
types: [opened, reopened]
env:
PRODUCTION_BRANCH: refs/heads/release
STAGING_BRANCH: refs/heads/edge
EB_APP_PRODUCTION: gosg-production
EB_ENV_PRODUCTION: go-production
EB_ENV_EDU_PRODUCTION: edu-production
EB_ENV_HEALTH_PRODUCTION: health-production
EB_APP_STAGING: gosg-stag
EB_ENV_STAGING: go-staging
EB_ENV_EDU_STAGING: edu-staging
EB_ENV_HEALTH_STAGING: health-staging
ECR_URL: 116366738264.dkr.ecr.ap-southeast-1.amazonaws.com
ECR_REPO: gogovsg
SENTRY_URL: https://sentry.io/
SENTRY_ORG: gogovsg
SENTRY_PROJECT_PRODUCTION: gogovsg-prod
SENTRY_PROJECT_STAGING: gogovsg-staging
SENTRY_DNS_PRODUCTION: https://a76d61749b824d8fa8ad84eee7ecc882@o372043.ingest.sentry.io/5193500
SENTRY_DNS_STAGING: https://5adc575a35d8443fb6ae6c83cee91a07@o372043.ingest.sentry.io/5185989
jobs:
ci:
name: CI
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --legacy-peer-deps
- run: npm run lint
- run: npx lockfile-lint --type npm --path package-lock.json --validate-https --allowed-hosts npm
- run: npm run build
env:
ASSET_VARIANT: gov
test:
name: Test
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --legacy-peer-deps
- run: npm run test
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
testcafe:
name: End To End Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --legacy-peer-deps
- run: echo CLOUDMERSIVE_KEY=${{secrets.CLOUDMERSIVE_KEY}} >> .env
- run: npm run test:e2e-headless
integration:
name: Integration Tests
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --legacy-peer-deps
- run: npm run dev &
- run: sleep 270
- run: npm run test:integration
gatekeep:
name: Determine if Build & Deploy is needed
outputs:
proceed: ${{ steps.determine_proceed.outputs.proceed }}
runs-on: ubuntu-22.04
if: github.event_name == 'push'
steps:
- shell: python
id: determine_proceed
run: |
import os
ref = os.environ['GITHUB_REF']
prod = os.environ['PRODUCTION_BRANCH']
stage = os.environ['STAGING_BRANCH']
if ref == prod or ref == stage:
print('::set-output name=proceed::true')
else:
print('::set-output name=proceed::false')
sentry:
name: Upload sourcemap to Sentry
runs-on: ubuntu-22.04
needs: [gatekeep]
if: needs.gatekeep.outputs.proceed == 'true'
steps:
- uses: actions/checkout@v2
- name: Use Node.js
uses: actions/setup-node@v1
with:
node-version: '16.x'
- name: Cache Node.js modules
uses: actions/cache@v2
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.OS }}-node-
${{ runner.OS }}-
- run: npm ci --legacy-peer-deps
- name: Select Sentry variables
shell: python
run: |
import os
branch = os.environ['GITHUB_REF']
staging = os.environ['STAGING_BRANCH']
production = os.environ['PRODUCTION_BRANCH']
sentry_project_staging = os.environ['SENTRY_PROJECT_STAGING']
sentry_dns_staging = os.environ['SENTRY_DNS_STAGING']
sentry_project_production = os.environ['SENTRY_PROJECT_PRODUCTION']
sentry_dns_production = os.environ['SENTRY_DNS_PRODUCTION']
github_env = os.environ['GITHUB_ENV']
file = open(github_env, 'a')
if branch == staging:
file.write('SENTRY_PROJECT={}\n'.format(sentry_project_staging))
file.write('SENTRY_DNS={}\n'.format(sentry_dns_staging))
elif branch == production:
file.write('SENTRY_PROJECT={}\n'.format(sentry_project_production))
file.write('SENTRY_DNS={}\n'.format(sentry_dns_production))
file.close()
- name: Upload to Sentry
run: npm run build
env:
ASSET_VARIANT: gov
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
build-gogov:
name: Build and push for gogov
runs-on: ubuntu-22.04
needs: [gatekeep]
if: needs.gatekeep.outputs.proceed == 'true'
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
tag: ${{steps.extract_tag.outputs.tag}}
steps:
- uses: actions/checkout@v2
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Extract ECR tag
shell: bash
run: echo "##[set-output name=tag;]$(echo ghactions-${BRANCH}-${SHA})"
id: extract_tag
env:
BRANCH: ${{ steps.extract_branch.outputs.branch }}
SHA: ${{ github.sha }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1
- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1
- run: |
if [[ $GITHUB_REF == $STAGING_BRANCH ]]; then
echo SERVERLESS_STAGE=staging >> $GITHUB_ENV;
elif [[ $GITHUB_REF == $PRODUCTION_BRANCH ]]; then
echo SERVERLESS_STAGE=production >> $GITHUB_ENV;
fi
- name: Build, tag, and push image to Amazon ECR
env:
REPO: ${{ env.ECR_URL }}/${{ env.ECR_REPO }}
TAG: ${{ steps.extract_tag.outputs.tag }}
run: |
docker build --tag my-image --build-arg __ASSET_VARIANT=gov --build-arg __DD_SERVICE=go-gov --build-arg __DD_ENV=${SERVERLESS_STAGE} .
docker tag my-image ${REPO}:${TAG}
docker push ${REPO}:${TAG}
deploy-gogov:
name: Deploy to Elastic Beanstalk and AWS Lambda for gogov
runs-on: ubuntu-22.04
needs: [ci, test, integration, gatekeep, build-gogov]
if: needs.gatekeep.outputs.proceed == 'true'
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: '16.x'
- run: |
echo SERVERLESS_SERVICE=gogovsg >> $GITHUB_ENV;
if [[ $GITHUB_REF == $STAGING_BRANCH ]]; then
echo BRANCH_ENV=staging >> $GITHUB_ENV;
elif [[ $GITHUB_REF == $PRODUCTION_BRANCH ]]; then
echo BRANCH_ENV=production >> $GITHUB_ENV;
fi
- name: Package Dockerrun.aws.json
run: |
sed -i -e "s|@REPO|$REPO|g" Dockerrun.aws.json
sed -i -e "s|@TAG|$TAG|g" Dockerrun.aws.json
sed -i -e "s|@DD_API_KEY|$DD_API_KEY|g" -e "s|@DD_SERVICE|$DD_SERVICE|g" -e "s|@DD_ENV|$DD_ENV|g" .ebextensions/99datadog.config
zip -r "deploy.zip" .ebextensions Dockerrun.aws.json
env:
REPO: ${{env.ECR_URL}}/${{env.ECR_REPO}}
TAG: ${{ needs.build-gogov.outputs.tag }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
DD_ENV: ${{ env.BRANCH_ENV }}
DD_SERVICE: go-gov
- name: Get timestamp
shell: bash
run: echo "##[set-output name=timestamp;]$(env TZ=Asia/Singapore date '+%Y%m%d%H%M%S')"
id: get_timestamp
- name: Get Elastic Beanstalk label
shell: bash
run: echo "##[set-output name=label;]$(echo ${TAG}-${TIMESTAMP})"
id: get_label
env:
TAG: ${{ needs.build-gogov.outputs.tag }}
TIMESTAMP: ${{ steps.get_timestamp.outputs.timestamp }}
- name: Select Elastic Beanstalk variables
shell: python
run: |
import os
branch = os.environ['GITHUB_REF']
staging = os.environ['STAGING_BRANCH']
production = os.environ['PRODUCTION_BRANCH']
eb_app_staging = os.environ['EB_APP_STAGING']
eb_env_staging = os.environ['EB_ENV_STAGING']
eb_app_production = os.environ['EB_APP_PRODUCTION']
eb_env_production = os.environ['EB_ENV_PRODUCTION']
if branch == staging:
print('::set-output name=eb_app::' + eb_app_staging)
print('::set-output name=eb_env::' + eb_env_staging)
elif branch == production:
print('::set-output name=eb_app::' + eb_app_production)
print('::set-output name=eb_env::' + eb_env_production)
id: select_eb_vars
- name: Deploy to EB
uses: opengovsg/beanstalk-deploy@v11
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ steps.select_eb_vars.outputs.eb_app }}
environment_name: ${{ steps.select_eb_vars.outputs.eb_env }}
version_label: ${{ steps.get_label.outputs.label }}
region: ap-southeast-1
deployment_package: deploy.zip
wait_for_deployment: false
wait_for_environment_recovery: false
- name: serverless deploy
uses: opengovsg/serverless-github-action@v3.0.0
with:
args: -c "serverless plugin install --name serverless-plugin-include-dependencies && serverless deploy --stage=$BRANCH_ENV --conceal --verbose"
entrypoint: /bin/bash
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SERVERLESS_SERVICE: ${{ env.SERVERLESS_SERVICE }}
build-edu:
name: Build and push for edu
runs-on: ubuntu-22.04
needs: [gatekeep]
if: needs.gatekeep.outputs.proceed == 'true'
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
tag: ${{steps.extract_tag.outputs.tag}}
steps:
- uses: actions/checkout@v2
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Extract ECR tag
shell: bash
run: echo "##[set-output name=tag;]$(echo ghactions-${BRANCH}-${SHA}-edu)"
id: extract_tag
env:
BRANCH: ${{ steps.extract_branch.outputs.branch }}
SHA: ${{ github.sha }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1
- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1
- run: |
if [[ $GITHUB_REF == $STAGING_BRANCH ]]; then
echo SERVERLESS_STAGE=staging >> $GITHUB_ENV;
elif [[ $GITHUB_REF == $PRODUCTION_BRANCH ]]; then
echo SERVERLESS_STAGE=production >> $GITHUB_ENV;
fi
- name: Build, tag, and push image to Amazon ECR
env:
REPO: ${{ env.ECR_URL }}/${{ env.ECR_REPO }}
TAG: ${{ steps.extract_tag.outputs.tag }}
run: |
docker build --tag my-image --build-arg __ASSET_VARIANT=edu --build-arg __DD_SERVICE=go-edu --build-arg __DD_ENV=${SERVERLESS_STAGE} .
docker tag my-image ${REPO}:${TAG}
docker push ${REPO}:${TAG}
deploy-edu:
name: Deploy to Elastic Beanstalk and AWS Lambda for edu
runs-on: ubuntu-22.04
needs: [ci, test, integration, gatekeep, build-edu]
if: needs.gatekeep.outputs.proceed == 'true'
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: '16.x'
- run: |
echo SERVERLESS_SERVICE=edu >> $GITHUB_ENV;
if [[ $GITHUB_REF == $STAGING_BRANCH ]]; then
echo BRANCH_ENV=staging >> $GITHUB_ENV;
elif [[ $GITHUB_REF == $PRODUCTION_BRANCH ]]; then
echo BRANCH_ENV=production >> $GITHUB_ENV;
fi
- name: Package Dockerrun.aws.json
run: |
sed -i -e "s|@REPO|$REPO|g" Dockerrun.aws.json
sed -i -e "s|@TAG|$TAG|g" Dockerrun.aws.json
sed -i -e "s|@DD_API_KEY|$DD_API_KEY|g" -e "s|@DD_SERVICE|$DD_SERVICE|g" -e "s|@DD_ENV|$DD_ENV|g" .ebextensions/99datadog.config
zip -r "deploy.zip" .ebextensions Dockerrun.aws.json
env:
REPO: ${{env.ECR_URL}}/${{env.ECR_REPO}}
TAG: ${{ needs.build-edu.outputs.tag }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
DD_ENV: ${{ env.BRANCH_ENV }}
DD_SERVICE: go-edu
- name: Get timestamp
shell: bash
run: echo "##[set-output name=timestamp;]$(env TZ=Asia/Singapore date '+%Y%m%d%H%M%S')"
id: get_timestamp
- name: Get Elastic Beanstalk label
shell: bash
run: echo "##[set-output name=label;]$(echo ${TAG}-${TIMESTAMP})"
id: get_label
env:
TAG: ${{ needs.build-edu.outputs.tag }}
TIMESTAMP: ${{ steps.get_timestamp.outputs.timestamp }}
- name: Select Elastic Beanstalk variables
shell: python
run: |
import os
branch = os.environ['GITHUB_REF']
staging = os.environ['STAGING_BRANCH']
production = os.environ['PRODUCTION_BRANCH']
eb_app_staging = os.environ['EB_APP_STAGING']
eb_env_edu_staging = os.environ['EB_ENV_EDU_STAGING']
eb_app_production = os.environ['EB_APP_PRODUCTION']
eb_env_edu_production = os.environ['EB_ENV_EDU_PRODUCTION']
if branch == staging:
print('::set-output name=eb_app::' + eb_app_staging)
print('::set-output name=eb_env_edu::' + eb_env_edu_staging)
elif branch == production:
print('::set-output name=eb_app::' + eb_app_production)
print('::set-output name=eb_env_edu::' + eb_env_edu_production)
id: select_eb_vars
- name: Deploy to EB edu
uses: opengovsg/beanstalk-deploy@v11
if: steps.select_eb_vars.outputs.eb_env_edu
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ steps.select_eb_vars.outputs.eb_app }}
environment_name: ${{ steps.select_eb_vars.outputs.eb_env_edu }}
version_label: ${{ steps.get_label.outputs.label }}
region: ap-southeast-1
deployment_package: deploy.zip
use_existing_version_if_available: true
wait_for_deployment: false
wait_for_environment_recovery: false
- name: serverless deploy
uses: opengovsg/serverless-github-action@v3.0.0
with:
args: -c "serverless plugin install --name serverless-plugin-include-dependencies && serverless deploy --stage=$BRANCH_ENV --conceal --verbose"
entrypoint: /bin/bash
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SERVERLESS_SERVICE: ${{ env.SERVERLESS_SERVICE }}
build-health:
name: Build and push for health
runs-on: ubuntu-22.04
needs: [gatekeep]
if: needs.gatekeep.outputs.proceed == 'true'
outputs:
branch: ${{ steps.extract_branch.outputs.branch }}
tag: ${{steps.extract_tag.outputs.tag}}
steps:
- uses: actions/checkout@v2
- name: Extract branch name
shell: bash
run: echo "##[set-output name=branch;]$(echo ${GITHUB_REF#refs/heads/})"
id: extract_branch
- name: Extract ECR tag
shell: bash
run: echo "##[set-output name=tag;]$(echo ghactions-${BRANCH}-${SHA}-health)"
id: extract_tag
env:
BRANCH: ${{ steps.extract_branch.outputs.branch }}
SHA: ${{ github.sha }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ap-southeast-1
- name: Login to Amazon ECR
id: login_ecr
uses: aws-actions/amazon-ecr-login@v1
- run: |
if [[ $GITHUB_REF == $STAGING_BRANCH ]]; then
echo SERVERLESS_STAGE=staging >> $GITHUB_ENV;
elif [[ $GITHUB_REF == $PRODUCTION_BRANCH ]]; then
echo SERVERLESS_STAGE=production >> $GITHUB_ENV;
fi
- name: Build, tag, and push image to Amazon ECR
env:
REPO: ${{ env.ECR_URL }}/${{ env.ECR_REPO }}
TAG: ${{ steps.extract_tag.outputs.tag }}
run: |
docker build --tag my-image --build-arg __ASSET_VARIANT=health --build-arg __DD_SERVICE=go-health --build-arg __DD_ENV=${SERVERLESS_STAGE} .
docker tag my-image ${REPO}:${TAG}
docker push ${REPO}:${TAG}
deploy-health:
name: Deploy to Elastic Beanstalk and AWS Lambda for health
runs-on: ubuntu-22.04
needs: [ci, test, integration, gatekeep, build-health]
if: needs.gatekeep.outputs.proceed == 'true'
steps:
- uses: actions/checkout@v2
- name: Use Node.js 16.x
uses: actions/setup-node@v1
with:
node-version: '16.x'
- run: |
echo SERVERLESS_SERVICE=health >> $GITHUB_ENV;
if [[ $GITHUB_REF == $STAGING_BRANCH ]]; then
echo BRANCH_ENV=staging >> $GITHUB_ENV;
elif [[ $GITHUB_REF == $PRODUCTION_BRANCH ]]; then
echo BRANCH_ENV=production >> $GITHUB_ENV;
fi
- name: Package Dockerrun.aws.json
run: |
sed -i -e "s|@REPO|$REPO|g" Dockerrun.aws.json
sed -i -e "s|@TAG|$TAG|g" Dockerrun.aws.json
sed -i -e "s|@DD_API_KEY|$DD_API_KEY|g" -e "s|@DD_SERVICE|$DD_SERVICE|g" -e "s|@DD_ENV|$DD_ENV|g" .ebextensions/99datadog.config
zip -r "deploy.zip" .ebextensions Dockerrun.aws.json
env:
REPO: ${{env.ECR_URL}}/${{env.ECR_REPO}}
TAG: ${{ needs.build-health.outputs.tag }}
DD_API_KEY: ${{ secrets.DD_API_KEY }}
DD_ENV: ${{ env.BRANCH_ENV }}
DD_SERVICE: go-health
- name: Get timestamp
shell: bash
run: echo "##[set-output name=timestamp;]$(env TZ=Asia/Singapore date '+%Y%m%d%H%M%S')"
id: get_timestamp
- name: Get Elastic Beanstalk label
shell: bash
run: echo "##[set-output name=label;]$(echo ${TAG}-${TIMESTAMP})"
id: get_label
env:
TAG: ${{ needs.build-health.outputs.tag }}
TIMESTAMP: ${{ steps.get_timestamp.outputs.timestamp }}
- name: Select Elastic Beanstalk variables
shell: python
run: |
import os
branch = os.environ['GITHUB_REF']
staging = os.environ['STAGING_BRANCH']
production = os.environ['PRODUCTION_BRANCH']
eb_app_staging = os.environ['EB_APP_STAGING']
eb_env_health_staging = os.environ['EB_ENV_HEALTH_STAGING']
eb_app_production = os.environ['EB_APP_PRODUCTION']
eb_env_health_production = os.environ['EB_ENV_HEALTH_PRODUCTION']
if branch == staging:
print('::set-output name=eb_app::' + eb_app_staging)
print('::set-output name=eb_env_health::' + eb_env_health_staging)
elif branch == production:
print('::set-output name=eb_app::' + eb_app_production)
print('::set-output name=eb_env_health::' + eb_env_health_production)
id: select_eb_vars
- name: Deploy to EB health
uses: opengovsg/beanstalk-deploy@v11
if: steps.select_eb_vars.outputs.eb_env_health
with:
aws_access_key: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws_secret_key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
application_name: ${{ steps.select_eb_vars.outputs.eb_app }}
environment_name: ${{ steps.select_eb_vars.outputs.eb_env_health }}
version_label: ${{ steps.get_label.outputs.label }}
region: ap-southeast-1
deployment_package: deploy.zip
use_existing_version_if_available: true
wait_for_deployment: false
wait_for_environment_recovery: false
- name: serverless deploy
uses: opengovsg/serverless-github-action@v3.0.0
with:
args: -c "serverless plugin install --name serverless-plugin-include-dependencies && serverless deploy --stage=$BRANCH_ENV --conceal --verbose"
entrypoint: /bin/bash
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
SERVERLESS_SERVICE: ${{ env.SERVERLESS_SERVICE }}