Test : CI/CD Deploy 테스트 #22
Workflow file for this run
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: Backend CI/CD Pipeline | |
| on: | |
| push: | |
| paths: | |
| - 'HalfFifty_BE/**' | |
| pull_request: | |
| paths: | |
| - 'HalfFifty_BE/**' | |
| jobs: | |
| # 1. 테스트 및 빌드 | |
| test: | |
| name: Test and Build Backend | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 1.1 코드 체크아웃 | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # 1.2 JDK 17 설치 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Add execute permissions to Gradlew | |
| run: chmod +x ./gradlew | |
| working-directory: HalfFifty_BE | |
| # Gradle 빌드 및 테스트 | |
| - name: Build and Test | |
| working-directory: HalfFifty_BE | |
| env: | |
| DB_DRIVER_CLASS_NAME: ${{ secrets.DB_DRIVER_CLASS_NAME }} | |
| DB_URL: ${{ secrets.DB_URL }} | |
| DB_USERNAME: ${{ secrets.DB_USERNAME }} | |
| DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
| run: | | |
| ./gradlew clean build | |
| - name: Verify JAR File | |
| working-directory: HalfFifty_BE | |
| run: ls -la build/libs/ | |
| # 빌드 결과물을 아티팩트로 업로드 | |
| - name: Upload Build Artifacts | |
| uses: actions/upload-artifact@v3 | |
| with: | |
| name: build-artifact | |
| path: HalfFifty_BE/build/libs/*.jar | |
| deploy: | |
| name: Deploy Backend | |
| needs: test | |
| if: github.ref == 'refs/heads/main' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| - name: Download Build Artifacts | |
| uses: actions/download-artifact@v3 | |
| with: | |
| name: build-artifact | |
| - name: Verify JAR File | |
| working-directory: HalfFifty_BE | |
| run: | | |
| ls -la build/libs/ | |
| - name: Set Permissions for JAR File | |
| working-directory: HalfFifty_BE | |
| run: chmod 644 build/libs/HalfFifty_BE-0.0.1-SNAPSHOT.jar | |
| - name: Upload JAR to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.AWS_IP }} | |
| username: ${{ secrets.AWS_USER }} | |
| key: ${{ secrets.AWS_KEY }} | |
| source: ./HalfFifty_BE/build/libs/HalfFifty_BE-0.0.1-SNAPSHOT.jar | |
| target: ~/HalfFifty_BE-0.0.1-SNAPSHOT.jar | |
| - name: Deploy to EC2 using Docker Compose | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.AWS_IP }} | |
| username: ${{ secrets.AWS_USER }} | |
| key: ${{ secrets.AWS_KEY }} | |
| script: | | |
| cd ~ | |
| docker-compose down || true | |
| docker-compose up -d --build | |