Skip to content

Commit

Permalink
Merge pull request #62 from zzthian/master
Browse files Browse the repository at this point in the history
Finalize CD and small bug fixes
  • Loading branch information
ChangGittyHub authored Nov 4, 2023
2 parents 0016269 + 3bf1f22 commit 8c323e0
Show file tree
Hide file tree
Showing 40 changed files with 1,072 additions and 47 deletions.
76 changes: 76 additions & 0 deletions .github/workflows/collab-be-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

name: Deploy Collab BE to Amazon ECS

on:
push:
branches: [ "master" ]

env:
AWS_REGION: ap-southeast-1 # set this to your preferred AWS region, e.g. us-west-1

ECR_COLLABORATION_REPOSITORY: peerprep-collab-backend

ECS_COLLABORATION_SERVICE: Peerprep-Collab-Backend

ECS_CLUSTER: PeerPrepDev # set this to your Amazon ECS cluster name

ECS_COLLABORATION_TASK_DEFINITION: ./backend/collab-backend/task-definition.json


COLLABORATION_CONTAINER_NAME: Peerprep-Collab-Backend


permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
#repeat everything below this for each service

- name: Collaboration service - Build, tag, and push image to Amazon ECR
id: build-collaboration-service-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_COLLABORATION_REPOSITORY:$IMAGE_TAG -f ./backend/collab-backend/Dockerfile.prod ./backend/collab-backend
docker push $ECR_REGISTRY/$ECR_COLLABORATION_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_COLLABORATION_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: collaboration-service-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_COLLABORATION_TASK_DEFINITION }}
container-name: ${{ env.COLLABORATION_CONTAINER_NAME }}
image: ${{ steps.build-collaboration-service-image.outputs.image }}

- name: Collaboration service - Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.collaboration-service-task-def.outputs.task-definition }}
service: ${{ env.ECS_COLLABORATION_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
76 changes: 76 additions & 0 deletions .github/workflows/comm-be-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@

name: Deploy Comm BE to Amazon ECS

on:
push:
branches: [ "master" ]

env:
AWS_REGION: ap-southeast-1 # set this to your preferred AWS region, e.g. us-west-1


ECR_COMMUNICATION_REPOSITORY: peerprep-communication-backend

ECS_COMMUNICATION_SERVICE: Peerprep-Comm-Backend


ECS_CLUSTER: PeerPrepDev # set this to your Amazon ECS cluster name

ECS_COMMUNICATION_TASK_DEFINITION: ./backend/communication-backend/task-definition.json

COMMUNICATION_CONTAINER_NAME: Peerprep-Comm-Backend


permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Communication service - Build, tag, and push image to Amazon ECR
id: build-communication-service-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_COMMUNICATION_REPOSITORY:$IMAGE_TAG -f ./backend/communication-backend/Dockerfile.prod ./backend/communication-backend
docker push $ECR_REGISTRY/$ECR_COMMUNICATION_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_COMMUNICATION_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT

- name: Fill in the new image ID in the Amazon ECS task definition
id: communication-service-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_COMMUNICATION_TASK_DEFINITION }}
container-name: ${{ env.COMMUNICATION_CONTAINER_NAME }}
image: ${{ steps.build-communication-service-image.outputs.image }}

- name: Communication service - Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.communication-service-task-def.outputs.task-definition }}
service: ${{ env.ECS_COMMUNICATION_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true
49 changes: 29 additions & 20 deletions .github/workflows/aws.yml → .github/workflows/fe-aws.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,22 @@ name: Deploy to Amazon ECS

on:
push:
branches: [ "CICD" ]
branches: [ "master" ]

env:
AWS_REGION: ap-southeast-1 # set this to your preferred AWS region, e.g. us-west-1
ECR_REPOSITORY: peerprep-g53 # set this to your Amazon ECR repository name
ECS_SERVICE: Peerprep-User-Backend # set this to your Amazon ECS service name
ECS_CLUSTER: PeerPrepDev # set this to your Amazon ECS cluster name
ECS_TASK_DEFINITION: peerprep-user-backend # set this to the path to your Amazon ECS task definition
# file, e.g. .aws/task-definition.json
CONTAINER_NAME: peerprep-user-backend # set this to the name of the container in the
# containerDefinitions section of your task definition


ECR_FRONTEND_REPOSITORY: peerprep-frontend

ECS_FRONTEND_SERVICE: PeerPrep-FE


ECS_CLUSTER: PeerPrepDev # set this to your Amazon ECS cluster name

ECS_FRONTEND_TASK_DEFINITION: ./frontend/task-definition.json

FRONTEND_CONTAINER_NAME: peerprep-frontend

permissions:
contents: read
Expand All @@ -64,31 +69,35 @@ jobs:
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
#repeat everything below this for each service
- name: Build, tag, and push image to Amazon ECR
id: build-image

- name: Frontend service - Build, tag, and push image to Amazon ECR
id: build-frontend-service-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
docker build -t $ECR_REGISTRY/$ECR_FRONTEND_REPOSITORY:$IMAGE_TAG -f ./frontend/Dockerfile.prod ./frontend
docker push $ECR_REGISTRY/$ECR_FRONTEND_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_FRONTEND_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: task-def
id: frontend-service-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_TASK_DEFINITION }}
container-name: ${{ env.CONTAINER_NAME }}
image: ${{ steps.build-image.outputs.image }}
task-definition: ${{ env.ECS_FRONTEND_TASK_DEFINITION }}
container-name: ${{ env.FRONTEND_CONTAINER_NAME }}
image: ${{ steps.build-frontend-service-image.outputs.image }}

- name: Deploy Amazon ECS task definition
- name: Frontend service - Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.task-def.outputs.task-definition }}
service: ${{ env.ECS_SERVICE }}
task-definition: ${{ steps.frontend-service-task-def.outputs.task-definition }}
service: ${{ env.ECS_FRONTEND_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true


81 changes: 81 additions & 0 deletions .github/workflows/matching-be-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@

name: Deploy Matching BE to Amazon ECS

on:
push:
branches: [ "master" ]

env:
AWS_REGION: ap-southeast-1 # set this to your preferred AWS region, e.g. us-west-1


ECR_MATCHING_REPOSITORY: peerprep-matching-backend


ECS_MATCHING_SERVICE: Peerprep-Matching-BE


ECS_CLUSTER: PeerPrepDev # set this to your Amazon ECS cluster name


ECS_MATCHING_TASK_DEFINITION: ./backend/matching_backend/task-definition.json


MATCHING_CONTAINER_NAME: Peerprep-Matching-Backend

permissions:
contents: read

jobs:
deploy:
name: Deploy Matching BE
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1


- name: Matching service - Build, tag, and push image to Amazon ECR
id: build-matching-service-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_MATCHING_REPOSITORY:$IMAGE_TAG -f ./backend/matching_backend/Dockerfile.prod ./backend/matching_backend
docker push $ECR_REGISTRY/$ECR_MATCHING_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_MATCHING_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Fill in the new image ID in the Amazon ECS task definition
id: matching-service-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_MATCHING_TASK_DEFINITION }}
container-name: ${{ env.MATCHING_CONTAINER_NAME }}
image: ${{ steps.build-matching-service-image.outputs.image }}

- name: Matching service - Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.matching-service-task-def.outputs.task-definition }}
service: ${{ env.ECS_MATCHING_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true


80 changes: 80 additions & 0 deletions .github/workflows/question-be-aws.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@


name: Deploy Qn BE to Amazon ECS

on:
push:
branches: [ "master" ]

env:
AWS_REGION: ap-southeast-1 # set this to your preferred AWS region, e.g. us-west-1

ECR_QUESTION_REPOSITORY: peerprep-question-backend # set this to your Amazon ECR repository name


ECS_QUESTION_SERVICE: Peerprep-Question-Backend


ECS_CLUSTER: PeerPrepDev # set this to your Amazon ECS cluster name

ECS_QUESTION_TASK_DEFINITION: ./backend/question-backend/task-definition.json # file, e.g. .aws/task-definition.json

QUESTION_CONTAINER_NAME: peerprep-question-backend


permissions:
contents: read

jobs:
deploy:
name: Deploy
runs-on: ubuntu-latest
environment: production

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ env.AWS_REGION }}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
#repeat everything below this for each service

- name: Question service - Build, tag, and push image to Amazon ECR
id: build-question-service-image
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
# Build a docker container and
# push it to ECR so that it can
# be deployed to ECS.
docker build -t $ECR_REGISTRY/$ECR_QUESTION_REPOSITORY:$IMAGE_TAG -f ./backend/question-backend/Dockerfile.prod ./backend/question-backend
docker push $ECR_REGISTRY/$ECR_QUESTION_REPOSITORY:$IMAGE_TAG
echo "image=$ECR_REGISTRY/$ECR_QUESTION_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT
- name: Question service - Fill in the new image ID in the Amazon ECS task definition
id: question-service-task-def
uses: aws-actions/amazon-ecs-render-task-definition@v1
with:
task-definition: ${{ env.ECS_QUESTION_TASK_DEFINITION }}
container-name: ${{ env.QUESTION_CONTAINER_NAME }}
image: ${{ steps.build-question-service-image.outputs.image }}

- name: Question service - Deploy Amazon ECS task definition
uses: aws-actions/amazon-ecs-deploy-task-definition@v1
with:
task-definition: ${{ steps.question-service-task-def.outputs.task-definition }}
service: ${{ env.ECS_QUESTION_SERVICE }}
cluster: ${{ env.ECS_CLUSTER }}
wait-for-service-stability: true


Loading

0 comments on commit 8c323e0

Please sign in to comment.