Skip to content

Commit 60dd9a4

Browse files
committed
Create github workflow to deploy backend services to AWS
1 parent 89cb0bb commit 60dd9a4

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed

.github/workflows/deployment.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Deploy Backend Services to Amazon ECS
2+
3+
on:
4+
push:
5+
branches: [ 'main' ]
6+
7+
workflow_dispatch:
8+
9+
permissions:
10+
id-token: write # This is required for requesting the JWT
11+
contents: read # This is required for actions/checkout
12+
13+
env:
14+
AWS_REGION: ap-southeast-1
15+
ECS_CLUSTER: backend-cluster
16+
17+
jobs:
18+
deploy:
19+
name: Deploy Backend Service
20+
runs-on: ubuntu-latest
21+
environment: production
22+
23+
strategy:
24+
matrix:
25+
service: [ 'match', 'question', 'user' ]
26+
27+
steps:
28+
- name: Checkout
29+
uses: actions/checkout@v4
30+
31+
- name: Configure AWS credentials
32+
id: aws-configure
33+
uses: aws-actions/[email protected]
34+
with:
35+
role-to-assume: arn:aws:iam::491085383176:role/github_ecs
36+
role-session-name: GitHub_to_AWS_via_FederatedOIDC
37+
aws-region: ${{ env.AWS_REGION }}
38+
39+
- name: Login to AWS ECR
40+
id: login-ecr
41+
uses: aws-actions/[email protected]
42+
43+
- name: Build and push ${{ matrix.service }} image to Amazon ECR
44+
id: build-image
45+
env:
46+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
47+
ECR_REPOSITORY: ${{ matrix.service }}
48+
IMAGE_TAG: latest
49+
run: |
50+
echo "Building $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
51+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./services/${{ matrix.service }}
52+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
53+
54+
- name: Update AWS Service (${{ matrix.service }}) # Trigger re-deployment with latest image
55+
id: update-service
56+
env:
57+
ECS_SERVICE: ${{ matrix.service }}-service
58+
run: |
59+
echo "Updating $ECS_SERVICE for $ECS_CLUSTER"
60+
aws ecs update-service \
61+
--cluster $ECS_CLUSTER \
62+
--service $ECS_SERVICE \
63+
--force-new-deployment \
64+
--region $AWS_REGION

0 commit comments

Comments
 (0)