From 97e7de1f5ab7a53a1752c29fd631e15dd3801f7e Mon Sep 17 00:00:00 2001 From: NayeonKeum Date: Sun, 6 Aug 2023 11:34:29 +0000 Subject: [PATCH] [feat/#53] Add: AWS CI with Codedeploy --- .github/workflows/CI.yml | 46 ++++++++++++++++++++++++++++++++++++++++ appspec.yml | 20 +++++++++++++++++ scripts/deploy.sh | 5 +++++ 3 files changed, 71 insertions(+) create mode 100644 .github/workflows/CI.yml create mode 100644 appspec.yml create mode 100644 scripts/deploy.sh diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..16debe2 --- /dev/null +++ b/.github/workflows/CI.yml @@ -0,0 +1,46 @@ +name: Deploy to Amazon EC2 +on: + push: + branches: + - develop +env: + S3_BUCKET_NAME: moaroom-frontend-codedeploy + CODE_DEPLOY_APPLICATION_NAME: moaroom-frontend + CODE_DEPLOY_DEPLOYMENT_GROUP_NAME: moaroom-frontend-dg +permissions: + contents: read + +jobs: + deploy: + name: Deploy + runs-on: ubuntu-latest + enviornment: production + + steps: + - name: Checkout source code. # Repo checkout + uses: actions/checkout@v2 + - name: Check Node v # Node v 확인 + run: node -v + - name: Install Dependencies # 의존 파일 설치 + run: npm install + - name: Build # React Build + run: npm run build + - name: zip create + run: zip -qq -r ./build-fe.zip . + shell: bash + - 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: ${{ secrets.AWS_REGION }} + + - name: Upload to AWS S3 + run: | + aws s3 cp --region ${{ secrets.AWS_REGION }} ./build-fe.zip s3://$S3_BUCKET_NAME/build-fe.zip + - name: Deploy to AWS EC2 from S3 + run: aws deploy create-deployment \ + --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ + --deployment-config-name CodeDeployDefault.AllAtOnce \ + --deployment-group-name ${{ env.CODE_DEPLOY_DEPLOYMENT_GROUP_NAME }} \ + --s3-location bucket=$S3_BUCKET_NAME,key=build-fe.zip,bundleType=zip \ No newline at end of file diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 0000000..368852e --- /dev/null +++ b/appspec.yml @@ -0,0 +1,20 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/MoaRoom-Front + overwrite: yes + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + mode: 755 + +hooks: + ApplicationStart: + - location: scripts/deploy.sh + timeout: 60 + runas: ubuntu \ No newline at end of file diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100644 index 0000000..ca916e0 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,5 @@ +#!/usr/bin/env bash + +PROJECT_ROOT="/home/ubuntu/MoaRoom-Front" +echo "> FE 배포" +sudo cp -rf /home/ubuntu/deploy-fe/dist/* /var/www/html \ No newline at end of file