Skip to content

Commit ef9d448

Browse files
committed
Add workflow scripts that can only be triggered manually for frontend and backend
1 parent 862b5bd commit ef9d448

File tree

2 files changed

+109
-0
lines changed

2 files changed

+109
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# Deploys all backend services regardless of file changes.
2+
# Can only be triggered manually.
3+
4+
name: Force Deploy All Backend Services
5+
6+
on:
7+
# Allows you to run this workflow manually from the Actions tab
8+
workflow_dispatch:
9+
10+
permissions:
11+
id-token: write # This is required for requesting the JWT
12+
contents: read # This is required for actions/checkout
13+
14+
env:
15+
AWS_REGION: ap-southeast-1
16+
ECS_CLUSTER: backend-cluster
17+
18+
jobs:
19+
deploy:
20+
name: Deploy Backend Service
21+
runs-on: ubuntu-latest
22+
environment: production
23+
24+
strategy:
25+
matrix:
26+
service: [ 'question', 'user', 'match', 'collaboration' ]
27+
28+
steps:
29+
- name: Checkout
30+
uses: actions/checkout@v4
31+
32+
- name: Configure AWS credentials
33+
id: aws-configure
34+
uses: aws-actions/[email protected]
35+
with:
36+
role-to-assume: ${{ secrets.AWS_BACKEND_ROLE }}
37+
role-session-name: GitHub_to_AWS_via_FederatedOIDC
38+
aws-region: ${{ env.AWS_REGION }}
39+
40+
- name: Login to AWS ECR
41+
id: login-ecr
42+
uses: aws-actions/[email protected]
43+
44+
- name: Build and push ${{ matrix.service }} image to AWS ECR
45+
id: build-image
46+
env:
47+
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
48+
ECR_REPOSITORY: ${{ matrix.service }}
49+
IMAGE_TAG: latest
50+
run: |
51+
echo "Building $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG"
52+
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG ./services/${{ matrix.service }}
53+
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
54+
55+
- name: Update AWS Service (${{ matrix.service }}) # Trigger re-deployment with latest image
56+
id: update-service
57+
env:
58+
ECS_SERVICE: ${{ matrix.service }}-service
59+
run: |
60+
echo "Updating $ECS_SERVICE for $ECS_CLUSTER"
61+
aws ecs update-service \
62+
--cluster $ECS_CLUSTER \
63+
--service $ECS_SERVICE \
64+
--force-new-deployment \
65+
--region $AWS_REGION
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Deploys frontend regardless of file changes.
2+
# Can only be triggered manually.
3+
4+
name: Force Deploy Frontend
5+
6+
on:
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+
S3_BUCKET_NAME: app.peerprep.org
16+
17+
jobs:
18+
deploy:
19+
name: Deploy Frontend
20+
runs-on: ubuntu-latest
21+
environment: production
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Configure AWS credentials
27+
id: aws-configure
28+
uses: aws-actions/[email protected]
29+
with:
30+
role-to-assume: ${{ secrets.AWS_FRONTEND_ROLE }}
31+
role-session-name: GitHub_to_AWS_via_FederatedOIDC
32+
aws-region: ${{ env.AWS_REGION }}
33+
34+
- name: Build frontend distribution
35+
working-directory: frontend
36+
run: npm ci && npm run build
37+
38+
- name: Sync distribution to S3
39+
run: |
40+
aws s3 sync ./frontend/dist/frontend/browser/ s3://$S3_BUCKET_NAME --delete
41+
42+
- name: Invalidate Cloudfront Cache
43+
run: |
44+
aws cloudfront create-invalidation --distribution-id ${{ secrets.AWS_CLOUDFRONT_ID }} --paths "/*"

0 commit comments

Comments
 (0)