forked from hotosm/tasking-manager
-
Notifications
You must be signed in to change notification settings - Fork 0
80 lines (69 loc) · 3.09 KB
/
backend-build-deploy.yml
File metadata and controls
80 lines (69 loc) · 3.09 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
name: Build and Deploy Backend to ECS
on:
push:
branches:
- main
- staging
- develop
paths:
- "backend/**"
workflow_dispatch:
env:
# NOTE: You can override these variables in the workflow file with GitHub Variables
# vars.TEAM is team name here in case you want to deploy for different team. Default is hotosm
# vars.INFRA_ENVIRONMENT is environment name here in case you have applied infrastructue with different environment name. Default is github.ref_name
AWS_REGION: ${{ vars.AWS_REGION || 'us-east-1' }}
OIDC_ROLE_ARN: ${{ secrets.AWS_OIDC_ROLE_ARN }}
ECS_CLUSTER: tasking-manager-${{ vars.INFRA_ENVIRONMENT || github.ref_name }}-cluster
TASK_DEFINITION_PREFIX: tasking-manager-${{ vars.TEAM || 'hotosm' }}-${{ vars.INFRA_ENVIRONMENT || github.ref_name }}
ECS_SERVICE_PREFIX: tasking-manager-${{ vars.TEAM || 'hotosm' }}-${{ vars.INFRA_ENVIRONMENT || github.ref_name }}
CONTAINER_NAME_PREFIX: tasking-manager-${{ vars.TEAM || 'hotosm' }}-${{ vars.INFRA_ENVIRONMENT || github.ref_name }}
jobs:
image-build-and-push:
uses: hotosm/gh-workflows/.github/workflows/image_build.yml@1.5.1
with:
image_name: ghcr.io/${{ github.repository }}/backend
build_target: prod
dockerfile: scripts/docker/Dockerfile
image_tags: |
ghcr.io/${{ vars.IMAGE_NAME || 'hotosm/tasking-manager/backend' }}:${{ github.ref_name }}
ghcr.io/${{ vars.IMAGE_NAME || 'hotosm/tasking-manager/backend' }}:${{ github.sha }}
deploy-service:
name: Deploy ${{ matrix.service }} to ECS
runs-on: ubuntu-latest
environment: ${{ github.ref_name }}
needs: image-build-and-push
permissions:
contents: read
id-token: write
strategy:
matrix:
service: [fastapi, cron]
fail-fast: false
steps:
- uses: actions/checkout@v4
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: ${{ env.OIDC_ROLE_ARN }}
role-session-name: gh-ci-ecs-deploy-${{ github.ref_name }}-${{ matrix.service }}
- name: Download task definition
run: |
aws ecs describe-task-definition --region ${{ env.AWS_REGION }} \
--task-definition ${{ env.TASK_DEFINITION_PREFIX }}-${{ matrix.service }} \
--query taskDefinition > task-definition.json
- name: Task definition rendition
id: task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: task-definition.json
container-name: ${{ env.CONTAINER_NAME_PREFIX }}-${{ matrix.service }}
image: ghcr.io/${{ vars.IMAGE_NAME || 'hotosm/tasking-manager/backend' }}:${{ github.sha }}
- name: Deploy task definition for ${{ matrix.service }}
uses: aws-actions/amazon-ecs-deploy-task-definition@v2
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE_PREFIX }}-${{ matrix.service }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true