diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml index 79ad28a5..6d88887c 100644 --- a/.github/workflows/deploy-main.yml +++ b/.github/workflows/deploy-main.yml @@ -49,9 +49,24 @@ jobs: - name: Build run: pnpm build - - name: Deploy - env: - AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} - AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} + - 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: ap-northeast-2 + + - name: Upload to AWS S3 + run: | + aws deploy push \ + --application-name ${{ env.CODE_DEPLOY_APPLICATION_NAME }} \ + --s3-location s3://$S3_BUCKET_NAME/$GITHUB_SHA.zip \ + --source . + + - name: Deploy to AWS EC2 from S3 run: | - aws s3 sync ./build s3://42library.kr --region ap-northeast-2 --delete + 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=$GITHUB_SHA.zip,bundleType=zip i \ No newline at end of file diff --git a/appspec.yml b/appspec.yml new file mode 100644 index 00000000..017894a3 --- /dev/null +++ b/appspec.yml @@ -0,0 +1,24 @@ +version: 0.0 +os: linux + +files: + - source: / + destination: /home/ubuntu/frontend + overwrite: true +file_exists_behavior: OVERWRITE + +permissions: + - object: / + pattern: "**" + owner: ubuntu + group: ubuntu + +hooks: + AfterInstall: + - location: scripts/stop.sh + timeout: 60 + runas: ubuntu + ApplicationStart: + - location: scripts/start.sh + timeout: 120 + runas: ubuntu \ No newline at end of file diff --git a/scripts/start.sh b/scripts/start.sh new file mode 100644 index 00000000..e4ad76fe --- /dev/null +++ b/scripts/start.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +# TODO: add front file + + +docker-compose -f ~/backend/docker-compose.yaml up -d --build \ No newline at end of file diff --git a/scripts/stop.sh b/scripts/stop.sh new file mode 100644 index 00000000..61dc58fd --- /dev/null +++ b/scripts/stop.sh @@ -0,0 +1,4 @@ +#!/bin/sh + +docker-compose -f ~/backend/docker-compose.yaml down +docker system prune \ No newline at end of file