Feat : CI/CD #1
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: | |
| # HalfFifty_BE 디렉토리에 변경사항이 있을 때 실행 | |
| push: | |
| paths: | |
| - 'HalfFifty_BE/**' | |
| # PR 생성 시 테스트 실행 | |
| 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 설치 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| # 1.3 Gradle 빌드 및 테스트 | |
| - name: Build and Test | |
| working-directory: HalfFifty_BE | |
| run: | | |
| ./gradlew clean build | |
| # 2. Docker 빌드 및 EC2 배포 | |
| deploy: | |
| name: Deploy Backend | |
| needs: test # 테스트가 성공해야 실행 | |
| if: github.ref == 'refs/heads/main' # main 브랜치로 push 시 실행 | |
| runs-on: ubuntu-latest | |
| steps: | |
| # 2.1 코드 체크아웃 | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| # 2.2 JDK 설치 | |
| - name: Set up JDK 17 | |
| uses: actions/setup-java@v3 | |
| with: | |
| java-version: '17' | |
| distribution: 'temurin' | |
| # 2.3 Docker 빌드 | |
| - name: Build Docker Image | |
| working-directory: HalfFifty_BE | |
| run: | | |
| docker build -t half-fifty . | |
| # 2.4 EC2 배포 | |
| - name: Deploy to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.AWS_IP }} | |
| username: ${{ secrets.AWS_USER }} | |
| key: ${{ secrets.AWS_KEY }} | |
| script: | | |
| docker stop half-fifty || true | |
| docker rm half-fifty || true | |
| docker run -d -p 80:8080 --name half-fifty half-fifty |