Skip to content

Commit 41f4fee

Browse files
authored
Merge pull request #1934 from ChildMindInstitute/release/2025.08.1
Release/2025.08.1
2 parents 878e5cf + 40173f0 commit 41f4fee

23 files changed

Lines changed: 1149 additions & 1256 deletions

.github/workflows/_build.yaml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
21
name: Build
2+
33
on:
44
workflow_call:
55
inputs:
@@ -8,11 +8,16 @@ on:
88
required: false
99
default: latest
1010
type: string
11+
git-ref:
12+
description: Git Ref to build from
13+
required: false
14+
type: string
15+
default: develop
1116

1217
# Safe to cancel builds in progress
1318
concurrency:
1419
cancel-in-progress: true
15-
group: api-build
20+
group: api-build-${{ inputs.tag-name }}
1621

1722
permissions:
1823
id-token: write
@@ -41,6 +46,8 @@ jobs:
4146
steps:
4247
- name: Checkout repository
4348
uses: actions/checkout@v4
49+
with:
50+
ref: ${{ inputs.git-ref }}
4451

4552
- name: Set up Docker Buildx
4653
uses: docker/setup-buildx-action@v3
@@ -87,6 +94,7 @@ jobs:
8794
${{ env.ECR_REPO }}:${{ steps.sha.outputs.SHORT_SHA }}
8895
platforms: linux/amd64,linux/arm64
8996

97+
# TODO What is this used for? Leftover artifact from Jenkins
9098
- name: Extract Jira ticket numbers from commit message
9199
run: |
92100
tickets=$(git log -1 --pretty=%B | grep -io 'M2-[0-9]\+' | tr '[:lower:]' '[:upper:]' | sort | uniq | tr '\n' ' ')

.github/workflows/_deploy.yaml

Lines changed: 13 additions & 162 deletions
Original file line numberDiff line numberDiff line change
@@ -28,178 +28,29 @@ on:
2828
required: true
2929
type: string
3030
description: Docker tag
31+
secrets:
32+
slack-webhook:
33+
required: true
3134

3235
# Wait for other deploys to finish
3336
concurrency:
3437
cancel-in-progress: false
35-
group: api-deploy
38+
group: api-deploy-${{ inputs.env-name }}
3639

3740
permissions:
3841
id-token: write
3942
contents: read
4043
issues: write
4144

42-
env:
43-
ECR_REPO: 917902836630.dkr.ecr.us-east-1.amazonaws.com/api-server
44-
ECR_ADDRESS: 917902836630.dkr.ecr.us-east-1.amazonaws.com
45-
4645
jobs:
4746
setup-vars:
48-
runs-on: ubuntu-latest
49-
50-
steps:
51-
- name: Map env to AWS Role
52-
id: role
53-
run: |
54-
ENV_NAME="${{ inputs.env-name }}"
55-
case "$ENV_NAME" in
56-
"dev")
57-
echo 'role=arn:aws:iam::017925157769:role/cmiml-dev-oidc-github-role' >> "$GITHUB_OUTPUT"
58-
;;
59-
"test")
60-
echo 'role=arn:aws:iam::641513112151:role/cmiml-test-oidc-github-role' >> "$GITHUB_OUTPUT"
61-
;;
62-
"uat")
63-
echo 'role=arn:aws:iam::641513112151:role/cmiml-uat-oidc-github-role' >> "$GITHUB_OUTPUT"
64-
;;
65-
"stage")
66-
echo 'role=arn:aws:iam::641513112151:role/cmiml-stage-oidc-github-role' >> "$GITHUB_OUTPUT"
67-
;;
68-
"prod")
69-
echo 'role=arn:aws:iam::410431445687:role/cmiml-prod-oidc-github-role' >> "$GITHUB_OUTPUT"
70-
;;
71-
"prod-dr")
72-
echo 'role=arn:aws:iam::973422231492:role/cmiml-dr-oidc-github-role' >> "$GITHUB_OUTPUT"
73-
;;
74-
*)
75-
echo "Bad environment name"
76-
exit 1;
77-
esac
78-
79-
- name: Map env to AWS Region
80-
id: region
81-
run: |
82-
ENV_NAME="${{ inputs.env-name }}"
83-
case "$ENV_NAME" in
84-
"prod-dr")
85-
echo "region=us-west-2" >> "$GITHUB_OUTPUT"
86-
;;
87-
*)
88-
echo "region=us-east-1" >> "$GITHUB_OUTPUT"
89-
;;
90-
esac
91-
- name: Map env to ECS cluster
92-
id: cluster
93-
run: |
94-
ENV_NAME="${{ inputs.env-name }}"
95-
case "$ENV_NAME" in
96-
"prod-dr")
97-
echo "cluster=prod-dr-us-west-2" >> "$GITHUB_OUTPUT"
98-
;;
99-
*)
100-
echo "cluster=cmiml-${ENV_NAME}" >> "$GITHUB_OUTPUT"
101-
;;
102-
esac
103-
104-
outputs:
105-
role: ${{ steps.role.outputs.role }}
106-
region: ${{ steps.region.outputs.region }}
107-
cluster: ${{ steps.cluster.outputs.cluster }}
108-
109-
110-
run-migration:
111-
runs-on: ubuntu-latest
112-
needs: [setup-vars]
113-
env:
114-
AWS_REGION: ${{ needs.setup-vars.outputs.region }}
115-
steps:
116-
- name: configure aws credentials
117-
uses: aws-actions/configure-aws-credentials@v4
118-
with:
119-
role-to-assume: ${{ needs.setup-vars.outputs.role }}
120-
role-session-name: OIDC-GHA-migration-session
121-
aws-region: ${{ needs.setup-vars.outputs.region }}
122-
- name: Download task definition
123-
run: |
124-
aws ecs describe-task-definition --task-definition migration --query taskDefinition > task-definition.json
125-
126-
- name: Render Amazon ECS task definition
127-
id: task-def
128-
uses: aws-actions/amazon-ecs-render-task-definition@v1
129-
with:
130-
task-definition: task-definition.json
131-
container-name: migrate
132-
image: ${{ env.ECR_REPO }}:${{ inputs.image-tag }}
133-
command: /fastapi-migrate
134-
environment-variables: |
135-
DD_VERSION=${{ inputs.image-tag }}
136-
docker-labels: |
137-
com.datadoghq.tags.version=${{ inputs.image-tag }}
138-
- name: Update Task Definition
139-
id: taskdef
140-
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
141-
with:
142-
task-definition: ${{ steps.task-def.outputs.task-definition }}
143-
- name: Run migration
144-
run: |-
145-
CONTAINER_NAME=migrate
146-
start=`date +%s`
147-
148-
echo "Starting migration task"
149-
TASK_ID=$(aws ecs run-task --task-definition "${{ steps.taskdef.outputs.task-definition-arn }}" --cluster ${{ needs.setup-vars.outputs.cluster }} | jq -r '.tasks[0].taskArn')
150-
151-
echo "Waiting for task ${{ steps.taskdef.outputs.task-definition-arn }} to finish..."
152-
aws ecs wait tasks-stopped --cluster ${{ needs.setup-vars.outputs.cluster }} --tasks "$TASK_ID"
153-
154-
TASK_EXIT_CODE=$(aws ecs describe-tasks --cluster ${{ needs.setup-vars.outputs.cluster }} --tasks "$TASK_ID" --query "tasks[0].containers[?name=='$CONTAINER_NAME'].exitCode" --output text)
155-
156-
end=`date +%s`
157-
runtime=$((end-start))
158-
159-
echo "Task finished with exit code $TASK_EXIT_CODE after $runtime"
160-
161-
echo "exit-code=${TASK_EXIT_CODE}" >> $GITHUB_OUTPUT
162-
echo "task-time=${runtime}" >> $GITHUB_OUTPUT
163-
164-
if [ $TASK_EXIT_CODE -gt 0 ]; then
165-
exit 1;
166-
fi
167-
168-
on-migration-failure:
169-
runs-on: ubuntu-latest
170-
if: ${{ !cancelled() && (needs.run-migration.result == 'failure' || needs.run-migration.result == 'timed_out') }}
171-
needs:
172-
- run-migration
173-
steps:
174-
- uses: actions/checkout@v4
175-
- name: "Send Slack message on failure"
176-
uses: rtCamp/action-slack-notify@v2
177-
env:
178-
SLACK_COLOR: failure
179-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_DEPLOY_TO_DEV }}
180-
MSG_MINIMAL: actions url
181-
SLACK_TITLE: Database Migration in DEV environment
182-
SLACK_MESSAGE: '🚨 Error when executing migration!'
183-
184-
on-migration-success:
185-
runs-on: ubuntu-latest
186-
if: ${{ !cancelled() && (needs.run-migration.result == 'success') }}
187-
needs:
188-
- run-migration
189-
steps:
190-
- uses: actions/checkout@v4
191-
- name: "Send Slack message on success"
192-
uses: rtCamp/action-slack-notify@v2
193-
env:
194-
SLACK_COLOR: success
195-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_DEPLOY_TO_DEV }}
196-
MSG_MINIMAL: actions url
197-
SLACK_TITLE: Database Migration in DEV environment
198-
SLACK_MESSAGE: '🎉 Migration was successful!'
47+
uses: ./.github/workflows/_setup.yaml
48+
with:
49+
env-name: ${{ inputs.env-name }}
19950

20051
deploy:
20152
runs-on: ubuntu-latest
202-
needs: [setup-vars, run-migration]
53+
needs: [setup-vars]
20354

20455
name: Deploy ${{ matrix.apps.name }}
20556
strategy:
@@ -231,7 +82,7 @@ jobs:
23182
with:
23283
task-definition: task-definition.json
23384
container-name: ${{ matrix.apps.container }}
234-
image: ${{ env.ECR_REPO }}:${{ inputs.image-tag }}
85+
image: ${{ needs.setup-vars.outputs.ecr-repo }}/api-server:${{ inputs.image-tag }}
23586

23687
- name: Update Task Definition
23788
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
@@ -253,9 +104,9 @@ jobs:
253104
uses: rtCamp/action-slack-notify@v2
254105
env:
255106
SLACK_COLOR: failure
256-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_DEPLOY_TO_DEV }}
107+
SLACK_WEBHOOK: ${{ secrets.slack-webhook }}
257108
MSG_MINIMAL: actions url
258-
SLACK_TITLE: Deployment to DEV environment
109+
SLACK_TITLE: Deployment to ${{ inputs.env-name }} environment
259110
SLACK_MESSAGE: '🚨 Error when executing deployment!'
260111

261112
on-deploy-success:
@@ -269,7 +120,7 @@ jobs:
269120
uses: rtCamp/action-slack-notify@v2
270121
env:
271122
SLACK_COLOR: success
272-
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK_DEPLOY_TO_DEV }}
123+
SLACK_WEBHOOK: ${{ secrets.slack-webhook }}
273124
MSG_MINIMAL: actions url
274-
SLACK_TITLE: Deployment to DEV environment
125+
SLACK_TITLE: Deployment to ${{ inputs.env-name }} environment
275126
SLACK_MESSAGE: '🚀 Deployment was successful!'

.github/workflows/_migrations.yaml

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
name: Run Migrations
2+
3+
on:
4+
workflow_call:
5+
inputs:
6+
env-name:
7+
required: true
8+
type: string
9+
description: Environment name
10+
image-tag:
11+
required: true
12+
type: string
13+
description: Docker image tag
14+
secrets:
15+
slack-webhook:
16+
required: true
17+
18+
19+
concurrency:
20+
cancel-in-progress: false
21+
group: api-migrations-${{ inputs.env-name }}
22+
23+
permissions:
24+
id-token: write
25+
contents: read
26+
27+
28+
jobs:
29+
setup-vars:
30+
uses: ./.github/workflows/_setup.yaml
31+
with:
32+
env-name: ${{ inputs.env-name }}
33+
34+
run-migration:
35+
runs-on: ubuntu-latest
36+
needs: [ setup-vars ]
37+
env:
38+
AWS_REGION: ${{ needs.setup-vars.outputs.region }}
39+
steps:
40+
- name: configure aws credentials
41+
uses: aws-actions/configure-aws-credentials@v4
42+
with:
43+
role-to-assume: ${{ needs.setup-vars.outputs.role }}
44+
role-session-name: OIDC-GHA-migration-session
45+
aws-region: ${{ needs.setup-vars.outputs.region }}
46+
- name: Download task definition
47+
run: |
48+
aws ecs describe-task-definition --task-definition migration --query taskDefinition > task-definition.json
49+
50+
- name: Render Amazon ECS task definition
51+
id: task-def
52+
uses: aws-actions/amazon-ecs-render-task-definition@v1
53+
with:
54+
task-definition: task-definition.json
55+
container-name: migrate
56+
image: ${{ needs.setup-vars.outputs.ecr-repo }}/api-server:${{ inputs.image-tag }}
57+
command: /fastapi-migrate
58+
environment-variables: |
59+
DD_VERSION=${{ inputs.image-tag }}
60+
docker-labels: |
61+
com.datadoghq.tags.version=${{ inputs.image-tag }}
62+
- name: Update Task Definition
63+
id: taskdef
64+
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
65+
with:
66+
task-definition: ${{ steps.task-def.outputs.task-definition }}
67+
- name: Run migration
68+
run: |-
69+
set -e
70+
CONTAINER_NAME=migrate
71+
start=`date +%s`
72+
73+
echo "Starting migration task"
74+
TASK_ID=$(aws ecs run-task --task-definition "${{ steps.taskdef.outputs.task-definition-arn }}" --cluster ${{ needs.setup-vars.outputs.cluster }} | jq -r '.tasks[0].taskArn')
75+
76+
echo "Waiting for task ${{ steps.taskdef.outputs.task-definition-arn }} with ID ${TASK_ID} to finish..."
77+
aws ecs wait tasks-stopped --cluster ${{ needs.setup-vars.outputs.cluster }} --tasks "$TASK_ID"
78+
79+
TASK_EXIT_CODE=$(aws ecs describe-tasks --cluster ${{ needs.setup-vars.outputs.cluster }} --tasks "$TASK_ID" --query "tasks[0].containers[?name=='$CONTAINER_NAME'].exitCode" --output text)
80+
81+
end=`date +%s`
82+
runtime=$((end-start))
83+
84+
echo "Task finished with exit code $TASK_EXIT_CODE after ${runtime} seconds."
85+
86+
echo "exit-code=${TASK_EXIT_CODE}" >> $GITHUB_OUTPUT
87+
echo "task-time=${runtime}" >> $GITHUB_OUTPUT
88+
89+
if [ -z "$TASK_EXIT_CODE" ] || [ "$TASK_EXIT_CODE" -gt "0" ]; then
90+
exit 1;
91+
fi
92+
93+
on-migration-failure:
94+
runs-on: ubuntu-latest
95+
if: ${{ !cancelled() && (needs.run-migration.result == 'failure' || needs.run-migration.result == 'timed_out') }}
96+
needs:
97+
- run-migration
98+
steps:
99+
- uses: actions/checkout@v4
100+
- name: "Send Slack message on failure"
101+
uses: rtCamp/action-slack-notify@v2
102+
env:
103+
SLACK_COLOR: failure
104+
SLACK_WEBHOOK: ${{ secrets.slack-webhook }}
105+
MSG_MINIMAL: actions url
106+
SLACK_TITLE: Database Migration in ${{ inputs.env-name }} environment
107+
SLACK_MESSAGE: '🚨 Error when executing migration!'
108+
109+
on-migration-success:
110+
runs-on: ubuntu-latest
111+
if: ${{ !cancelled() && (needs.run-migration.result == 'success') }}
112+
needs:
113+
- run-migration
114+
steps:
115+
- uses: actions/checkout@v4
116+
- name: "Send Slack message on success"
117+
uses: rtCamp/action-slack-notify@v2
118+
env:
119+
SLACK_COLOR: success
120+
SLACK_WEBHOOK: ${{ secrets.slack-webhook }}
121+
MSG_MINIMAL: actions url
122+
SLACK_TITLE: Database Migration in ${{ inputs.env-name }} environment
123+
SLACK_MESSAGE: '🎉 Migration was successful!'

0 commit comments

Comments
 (0)