-
Notifications
You must be signed in to change notification settings - Fork 8
147 lines (131 loc) · 4.55 KB
/
Copy path_deploy.yaml
File metadata and controls
147 lines (131 loc) · 4.55 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
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
name: Deploy
on:
# Keep this for someday in the future
# workflow_dispatch:
# inputs:
# image-tag:
# required: true
# type: string
# description: Docker tag
# env-name:
# required: true
# type: choice
# description: Environment name
# options:
# - dev
# - test
# - uat
# - stage
# - prod
# - prod-dr
workflow_call:
inputs:
env-name:
required: true
type: string
image-tag:
required: true
type: string
description: Docker tag
secrets:
slack-webhook:
required: true
# Wait for other deploys to finish
concurrency:
cancel-in-progress: false
group: api-deploy-${{ inputs.env-name }}
permissions:
id-token: write
contents: read
issues: write
jobs:
setup-vars:
uses: ./.github/workflows/_setup.yaml
with:
env-name: ${{ inputs.env-name }}
deploy:
runs-on: ubuntu-latest
needs: [setup-vars]
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 }
env:
AWS_REGION: ${{ needs.setup-vars.outputs.region }}
steps:
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: ${{ needs.setup-vars.outputs.role }}
role-session-name: OIDC-GHA-session-deploy
aws-region: ${{ needs.setup-vars.outputs.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: ${{ needs.setup-vars.outputs.ecr-repo }}/api-server:${{ inputs.image-tag }}
environment-variables: |
VERSION=${{ inputs.image-tag }}
DD_VERSION=${{ inputs.image-tag }}
COMMIT_ID=${{ github.sha }}
docker-labels: |
com.datadoghq.tags.version=${{ inputs.image-tag }}
- 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: ${{ needs.setup-vars.outputs.cluster }}
wait-for-service-stability: true
on-deploy-failure:
runs-on: ubuntu-latest
if: ${{ !cancelled() && (needs.deploy.result == 'failure' || needs.deploy.result == 'timed_out') }}
needs:
- deploy
steps:
- uses: actions/checkout@v7
- name: "Send Slack message on failure"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: failure
SLACK_WEBHOOK: ${{ secrets.slack-webhook }}
MSG_MINIMAL: actions url
SLACK_TITLE: Backend deployed to ${{ inputs.env-name }}
SLACK_MESSAGE: '🚨 Error when executing deployment!'
on-deploy-success:
runs-on: ubuntu-latest
if: ${{ !cancelled() && (needs.deploy.result == 'success') }}
needs:
- deploy
steps:
- name: "Send Slack message on success"
uses: rtCamp/action-slack-notify@v2
env:
SLACK_COLOR: success
SLACK_WEBHOOK: ${{ secrets.slack-webhook }}
MSG_MINIMAL: actions url
SLACKIFY_MARKDOWN: true
SLACK_TITLE: Backend deployed to ${{ inputs.env-name }}
SLACK_MESSAGE: '🚀 Deployment was successful. Version: *${{ inputs.image-tag }}*'
- name: configure aws credentials
uses: aws-actions/configure-aws-credentials@v6
with:
role-to-assume: arn:aws:iam::917902836630:role/github-oidc-ssm-version
role-session-name: OIDC-GHA-session-version
aws-region: us-east-1
- name: Store version in SSM
run: |
aws ssm put-parameter \
--name "/curious/app/backend/${{ inputs.env-name }}/version" \
--value "${{ inputs.image-tag }}" \
--type "String" \
--overwrite