From 4ce9a2403affbcedba9fb1c5297709dc560bd100 Mon Sep 17 00:00:00 2001 From: chan9yu Date: Wed, 15 Jan 2025 13:11:59 +0900 Subject: [PATCH] chore: addded github action: deploy-main.yml --- .github/workflows/deploy-main.yml | 25 +++++++++++++++++++++++++ scripts/deploy.sh | 23 +++++++++++++++++++++++ 2 files changed, 48 insertions(+) create mode 100644 .github/workflows/deploy-main.yml create mode 100755 scripts/deploy.sh diff --git a/.github/workflows/deploy-main.yml b/.github/workflows/deploy-main.yml new file mode 100644 index 0000000..11de0a6 --- /dev/null +++ b/.github/workflows/deploy-main.yml @@ -0,0 +1,25 @@ +name: remote ssh command for deploy + +on: + push: + branches: [main] + +jobs: + build: + name: Build + runs-on: ubuntu-latest + steps: + # 레포지토리 체크아웃 + - name: Checkout repository + uses: actions/checkout@v2 + + # SSH를 사용하여 스크립트 실행 + - name: executing remote ssh commands using key + uses: appleboy/ssh-action@master + with: + host: ${{ secrets.HOST }} + username: ${{ secrets.USERNAME }} + key: ${{ secrets.KEY }} + port: ${{ secrets.PORT }} + script: | + ./git/react-api-cicd/scripts/deploy.sh diff --git a/scripts/deploy.sh b/scripts/deploy.sh new file mode 100755 index 0000000..3c627c0 --- /dev/null +++ b/scripts/deploy.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +npm -g install yarn + +source ~/.bash_profile +cd ~/git/react-api-cicd/ +git pull origin main + +# front-end +cd frontend/ +yarn install +yarn build +cp -rf dist/* ../backend/public + +# back-end +cd ../backend/ +yarn install + +# pm2 +pm2 stop react-api-cicd +pm2 start bin/www --name react-api-cicd --update-env +sleep 2 +pm2 list \ No newline at end of file