forked from ChildMindInstitute/mindlogger-backend-refactor
-
Notifications
You must be signed in to change notification settings - Fork 0
120 lines (104 loc) · 4.27 KB
/
Copy pathrun_deploy_dev.yaml
File metadata and controls
120 lines (104 loc) · 4.27 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
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
name: Deploy to Dev
on:
workflow_dispatch:
inputs:
IMAGE_NAME:
required: true
type: string
description: Image tag
workflow_call:
inputs:
IMAGE_NAME:
required: true
type: string
permissions:
id-token: write
contents: read
issues: write
env:
AWS_REGION: us-east-1
ECS_CLUSTER_NAME: cmiml-dev
IMAGE_NAME: ${{ inputs.IMAGE_NAME }}
jobs:
deploy_to_ecs:
runs-on: ubuntu-latest
# needs: run_migration
name: Deploy ${{ matrix.apps.name }}
strategy:
fail-fast: true
matrix:
apps:
- { name: api, task-def: backend_api, service: backend, container: mind_logger }
- { name: worker, task-def: backend_worker, service: backend-worker, container: mind_logger_worker }
- { name: scheduler, task-def: backend_scheduler, service: backend-scheduler, container: mind_logger_scheduler }
steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: arn:aws:iam::017925157769:role/cmiml-dev-oidc-github-role
role-session-name: OIDC-GHA-session
aws-region: ${{ env.AWS_REGION }}
- name: Download task definition
run: |
aws ecs describe-task-definition --task-definition ${{ matrix.apps.task-def }} --query taskDefinition > task-definition.json
- name: Render Amazon ECS task definition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ matrix.apps.container }}
image: ${{ inputs.IMAGE_NAME }}
- name: Update Task Definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ matrix.apps.service }}
cluster: cmiml-dev
wait-for-service-stability: true
# - name: change image and register task definitions
# run: |
# for app in api worker scheduler; do
# export NEW_TASK_DEFINITION=$(aws ecs describe-task-definition --task-definition ${TASK_FAMILY_PREFIX}_${app} --region ${AWS_REGION} | jq --arg IMAGE "$IMAGE_NAME" '.taskDefinition | .containerDefinitions[0].image = $IMAGE | del(.taskDefinitionArn) | del(.revision) | del(.status) | del(.requiresAttributes) | del(.compatibilities) | del(.registeredAt) | del(.registeredBy)')
# aws ecs register-task-definition --region ${AWS_REGION} --cli-input-json "$NEW_TASK_DEFINITION"
# done
#
# - name: update services
# run: |
# for app in scheduler worker; do
# aws ecs update-service --cluster ${ECS_CLUSTER_NAME} --service ${ECS_SERVICE_NAME}-${app} --task-definition ${TASK_FAMILY_PREFIX}_${app}
# done
#
# #this step is separate because api service and task definition names are different, need to be changed
# aws ecs update-service --cluster ${ECS_CLUSTER_NAME} --service ${ECS_SERVICE_NAME} --task-definition ${TASK_FAMILY_PREFIX}_api
on-failure:
runs-on: ubuntu-latest
if: ${{ !cancelled() && (needs.deploy_to_ecs.result == 'failure' || needs.deploy_to_ecs.result == 'timed_out') }}
needs:
- deploy_to_ecs
steps:
- uses: actions/checkout@v4
- name: "Send Slack message on failure"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: failure
SLACK_WEBHOOK: ${{ secrets.DEV_SLACK_WEBHOOK }}
SLACK_CHANNEL: gha-deploy-to-dev
SLACK_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_TITLE: Deployment to DEV environment
SLACK_MESSAGE: 'Error when executing deployment!'
on-success:
runs-on: ubuntu-latest
if: ${{ !cancelled() && (needs.deploy_to_ecs.result == 'success') }}
needs:
- deploy_to_ecs
steps:
- uses: actions/checkout@v4
- name: "Send Slack message on success"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: success
SLACK_WEBHOOK: ${{ secrets.DEV_SLACK_WEBHOOK }}
SLACK_CHANNEL: gha-deploy-to-dev
SLACK_TOKEN: ${{ secrets.SLACK_BOT_TOKEN }}
SLACK_TITLE: Deployment to DEV environment
SLACK_MESSAGE: 'Deployment is successfull!'