Merge pull request #180 from pirogramming/main #92
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 Frontend & Backend | |
| on: | |
| push: | |
| branches: [deploy] | |
| jobs: | |
| backend: | |
| name: Deploy Backend to EC2 | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Java | |
| uses: actions/setup-java@v3 | |
| with: | |
| distribution: 'temurin' | |
| java-version: '17' | |
| - name: Create .env file& Build backend | |
| run: | | |
| cd backend/pirocheck | |
| echo DB_HOST=${{ secrets.DB_HOST }} >> .env | |
| echo DB_PORT=${{ secrets.DB_PORT }} >> .env | |
| echo DB_NAME=${{ secrets.DB_NAME }} >> .env | |
| echo DB_USER=${{ secrets.DB_USER }} >> .env | |
| echo DB_PASSWORD=${{ secrets.DB_PASSWORD }} >> .env | |
| chmod +x gradlew | |
| ./gradlew build -x test --no-daemon | |
| - name: Restore PEM file | |
| run: | | |
| echo "${{ secrets.EC2_SSH_KEY }}" | base64 -d > pirocheck.pem | |
| chmod 400 pirocheck.pem | |
| - name: Copy JAR to EC2 | |
| run: | | |
| scp -o StrictHostKeyChecking=no -i pirocheck.pem backend/pirocheck/build/libs/*.jar ubuntu@${{ secrets.EC2_HOST }}:/home/ubuntu/ | |
| - name: Restart Spring Boot on EC2 | |
| run: | | |
| ssh -o StrictHostKeyChecking=no -i pirocheck.pem ubuntu@${{ secrets.EC2_HOST }} 'bash ~/restart.sh' | |
| - name: Send Discord notification (Success) | |
| if: success() | |
| run: | | |
| curl -H "Content-Type: application/json" \ | |
| -X POST \ | |
| -d '{ | |
| "embeds": [{ | |
| "title": "🚀 Deploy 성공!", | |
| "description": "**Branch**: `${{ github.ref }}`\n**Commit**: `${{ github.sha }}`\n🟢 서비스가 정상적으로 배포되었습니다!", | |
| "color": 65353 | |
| }] | |
| }' ${{ secrets.DISCORD_WEBHOOK }} | |
| - name: Send Discord notification (Failure) | |
| if: failure() | |
| run: | | |
| curl -H "Content-Type: application/json" \ | |
| -X POST \ | |
| -d '{ | |
| "embeds": [{ | |
| "title": "❌ Deploy 실패!", | |
| "description": "**Branch**: `${{ github.ref }}`\n**Commit**: `${{ github.sha }}`\n🔴 배포 중 오류가 발생했습니다. 로그를 확인하세요.", | |
| "color": 16711680 | |
| }] | |
| }' ${{ secrets.DISCORD_WEBHOOK }} | |
| frontend: | |
| name: Deploy Frontend to S3 | |
| needs: backend | |
| runs-on: ubuntu-22.04 | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: '22' | |
| - name: Install dependencies | |
| run: | | |
| cd frontend | |
| rm -rf node_modules package-lock.json | |
| npm install | |
| npm install --save-dev vite rollup | |
| - name: Build frontend | |
| run: | | |
| cd frontend | |
| npm run build | |
| - name: Deploy to S3 | |
| uses: jakejarvis/s3-sync-action@master | |
| with: | |
| args: --delete | |
| env: | |
| AWS_S3_BUCKET: www.pirocheck.org | |
| AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
| SOURCE_DIR: frontend/dist |