From 3e017334e23c6acb3ab8da1ce893770f577590a3 Mon Sep 17 00:00:00 2001 From: zzthian Date: Thu, 9 Nov 2023 00:25:40 +0800 Subject: [PATCH] Add workflow to deploy Question history --- .github/workflows/history-be-aws.yml | 79 ++++++++++++++++++++++++++++ frontend/Dockerfile.prod | 1 + 2 files changed, 80 insertions(+) create mode 100644 .github/workflows/history-be-aws.yml diff --git a/.github/workflows/history-be-aws.yml b/.github/workflows/history-be-aws.yml new file mode 100644 index 00000000..ead8a913 --- /dev/null +++ b/.github/workflows/history-be-aws.yml @@ -0,0 +1,79 @@ + +name: Deploy History 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_HISTORY_REPOSITORY: peerprep-history-backend + + + ECS_HISTORY_SERVICE: Peerprep-History-BE + + + ECS_CLUSTER: PeerPrepDev # set this to your Amazon ECS cluster name + + + ECS_HISTORY_TASK_DEFINITION: ./backend/question-history-backend/task-definition.json + + + HISTORY_CONTAINER_NAME: Peerprep-History-Backend + +permissions: + contents: read + +jobs: + deploy: + name: Deploy History 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: History service - Build, tag, and push image to Amazon ECR + id: build-history-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_HISTORY_REPOSITORY:$IMAGE_TAG -f ./backend/question-history-backend/Dockerfile.prod ./backend/question-history-backend + docker push $ECR_REGISTRY/$ECR_HISTORY_REPOSITORY:$IMAGE_TAG + echo "image=$ECR_REGISTRY/$ECR_HISTORY_REPOSITORY:$IMAGE_TAG" >> $GITHUB_OUTPUT + + - name: Fill in the new image ID in the Amazon ECS task definition + id: history-service-task-def + uses: aws-actions/amazon-ecs-render-task-definition@v1 + with: + task-definition: ${{ env.ECS_HISTORY_TASK_DEFINITION }} + container-name: ${{ env.HISTORY_CONTAINER_NAME }} + image: ${{ steps.build-history-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.history-service-task-def.outputs.task-definition }} + service: ${{ env.ECS_HISTORY_SERVICE }} + cluster: ${{ env.ECS_CLUSTER }} + wait-for-service-stability: true diff --git a/frontend/Dockerfile.prod b/frontend/Dockerfile.prod index 78f31e42..de404ffd 100644 --- a/frontend/Dockerfile.prod +++ b/frontend/Dockerfile.prod @@ -10,6 +10,7 @@ ENV REACT_APP_MATCHING_HOST=https://peerprep.jonoans.com:8443 ENV REACT_APP_COLLAB_HOST=https://peerprep.jonoans.com ENV REACT_APP_COMMUNICATION_HOST=https://peerprep.jonoans.com:2096 ENV REACT_APP_CATEGORIES_HOST=https://peerprep.jonoans.com/api/categories +ENV REACT_APP_HISTORY_HOST=https://peerprep.jonoans/api/history RUN npm run build RUN npm i -g serve