-
Notifications
You must be signed in to change notification settings - Fork 7
105 lines (89 loc) · 3.91 KB
/
deploy.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
# This workflow will build and push a new container image to Amazon ECR,
# and then will deploy a new task definition for each of the services to Amazon ECS.
# Note: The names of repository, cluster, services match what is configured in https://github.com/dimagi/ocs-deploy
name: Deploy to Amazon ECS
on:
workflow_dispatch:
# push:
# branches: [ "main" ]
env:
AWS_REGION: ${{ vars.DEPLOY_AWS_REGION }}
ECR_REPOSITORY: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-ecr-repo
ECS_CLUSTER: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-Cluster
permissions:
contents: read
jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production
steps:
- name: Checkout
uses: actions/checkout@v4
- name: configure aws credentials
uses: aws-actions/[email protected]
with:
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT }}:role/github_deploy
role-session-name: GithubDeploy
aws-region: ${{ env.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/[email protected]
- name: Build, tag, and push image to Amazon ECR
id: build-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG -f Dockerfile.web .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Update ECS task def for Django web container
id: django-web-def
uses: aws-actions/[email protected]
with:
task-definition-family: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-Django
container-name: web
image: ${{ steps.build-image.outputs.image }}
- name: Update ECS task def for Django migrations container
id: django-migrations-def
uses: aws-actions/[email protected]
with:
task-definition: ${{ steps.django-web-def.outputs.task-definition }}
container-name: migrate
image: ${{ steps.build-image.outputs.image }}
- name: Update ECS task def for Celery worker container
id: celery-worker-def
uses: aws-actions/[email protected]
with:
task-definition-family: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-CeleryWorkerTask
container-name: celery-worker
image: ${{ steps.build-image.outputs.image }}
- name: Update ECS task def for Celery beat container
id: celery-beat-def
uses: aws-actions/[email protected]
with:
task-definition-family: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-CeleryBeatTask
container-name: celery-beat
image: ${{ steps.build-image.outputs.image }}
- name: Deploy Django Web
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.django-migrations-def.outputs.task-definition }}
service: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-Django
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
- name: Deploy Celery Worker
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.celery-worker-def.outputs.task-definition }}
service: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-Celery
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: false # don't wait for this one but wait for the next one
- name: Deploy Celery Beat
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.celery-beat-def.outputs.task-definition }}
service: ${{ vars.DEPLOY_APP_NAME }}-${{ vars.DEPLOY_ENV }}-CeleryBeat
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true