From 6b1fed0b6d5ccdcaff2318dc9ef6b4f6111f9b96 Mon Sep 17 00:00:00 2001 From: YeonHu Yim <71930280+lcqff@users.noreply.github.com> Date: Wed, 6 Nov 2024 22:17:55 +0900 Subject: [PATCH] Create deploy.yml --- .github/workflows/deploy.yml | 73 ++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 .github/workflows/deploy.yml diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..ae7a390 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,73 @@ +name: s3-develop-deploy + +on: + push: + branches: + - develop + workflow_dispatch: + +jobs: + deploy_development: + runs-on: ubuntu-22.04 + timeout-minutes: 10 + + permissions: + id-token: write + contents: read + + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Configure AWS Credentials + uses: aws-actions/configure-aws-credentials@v4 + with: + role-to-assume: ${{ secrets.AWS_ROLE_ARN }} + aws-region: ${{ secrets.AWS_REGION }} + + - name: Install Dependencies + run: npm ci + + - name: Create .env File + env: + PREFIX: 'NEXT_PUBLIC_' + SECRETS: ${{ toJson(secrets) }} + run: | + touch .env && \ + jq -r 'to_entries|map("\(.key)=\(.value|tostring)")|.[]' <<< "$SECRETS" | grep $PREFIX > .env + + - name: Build + run: npm run build + + - name: Collect Code + run: | + mkdir -p build/.next && \ + cp -r .next/standalone/. build/. && \ + cp -r public build && \ + cp -r .next/static build/.next + + - name: Compress + run: | + mkdir tars && \ + tar -cvzf - build | \ + split -b 100M - \ + tars/${GITHUB_SHA::8}.tar.gz. + + - name: Upload to S3 + run: | + aws s3 sync \ + --region ${{ secrets.AWS_REGION }} \ + tars ${{secrets.S3_DEV_FRONT_LOCATION}} + + - name: Deploy + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.EC2_HOST_DEV }} + username: ${{ secrets.EC2_USER_DEV }} + port: ${{ secrets.EC2_PORT_DEV }} + key: ${{ secrets.EC2_KEY_DEV }} + envs: GITHUB_SHA + script: | + cd ~/soundflyer-infra/deploy + chmod +x ./deploy_front.sh + sudo -E ./deploy_front.sh ${GITHUB_SHA::8} dev