From 30a9ff3564428ed7954c8a0d79867ff463ddc482 Mon Sep 17 00:00:00 2001 From: Hongmin Lee Date: Tue, 7 Jan 2025 21:52:51 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20github=20actions=20=EC=84=A4=EC=A0=95?= =?UTF-8?q?=20=ED=8C=8C=EC=9D=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 49 ++++++++++++++++++++++++++++++++++++ 1 file changed, 49 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..f23c581 --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,49 @@ +name: Deploy to EC2 + +# 워크플로우 실행 조건 설정 +on: + push: + branches: + - dev # dev 브랜치에 push될 때 실행 + +jobs: + deploy: + runs-on: ubuntu-24.04 # 가상 환경 지정 (Ubuntu 24.04 버전) + + steps: + # 1. 코드 체크아웃 + - name: Checkout code + uses: actions/checkout@v4 + + # 2. Node.js 세팅 + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + + # 3. SSH 키 설정 + - name: Set up SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.SSH_PRIVATE_KEY }}" | base64 --decode > ~/.ssh/id_rsa + chmod 600 ~/.ssh/id_rsa + ssh-keyscan -H ${{ secrets.HOST }} >> ~/.ssh/known_hosts + + # 4. EC2 접속 및 코드 배포 + - name: Deploy to EC2 + run: | + ssh ${{ secrets.USER }}@${{ secrets.HOST }} << 'EOF' + cd /app + + # 코드 업데이트 및 빌드 + git pull origin dev + npm install + npm run init + npm run build + + # 환경 변수 적용 + echo "${{ secrets.ENV_FILE }}" | base64 --decode > .env + + # PM2 재시작 + pm2 restart ecosystem.config.js + EOF