๐ทci: GitHub Actions: EC2 ๋ฌด์ค๋จ ๋ฐฐํฌ workflow ์์ (๋ก๊ทธ์ธ ์ ํ๊ฒฝ ๋ก๋ฉ ๋ฐ์) #4
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy to EC2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Setup SSH | |
| run: | | |
| mkdir -p ~/.ssh | |
| echo "${{ secrets.EC2_SSH_KEY }}" > ~/.ssh/id_rsa | |
| chmod 600 ~/.ssh/id_rsa | |
| ssh-keyscan -H ${{ secrets.EC2_HOST }} >> ~/.ssh/known_hosts | |
| - name: Deploy to EC2 | |
| run: | | |
| ssh ${{ secrets.EC2_USER }}@${{ secrets.EC2_HOST }} << 'EOF' | |
| set -e | |
| bash -l << 'INNER' | |
| set -e | |
| cd ~/ssakssak-commit | |
| echo "๐ฆ Pull latest code" | |
| git pull origin main | |
| echo "๐ฆ Install dependencies" | |
| npm ci | |
| echo "๐ Build Next.js" | |
| npm run build | |
| echo "๐ Reload PM2 apps" | |
| pm2 reload next-app || pm2 start npm --name "next-app" -- run start -- --port 3000 | |
| pm2 reload ssakssak-worker || pm2 start npm --name "ssakssak-worker" -- run worker:start | |
| pm2 save | |
| INNER | |
| EOF |