Feat : CI/CD #5
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: | |
| test: | |
| name: Test and Build Backend | |
| 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: Add execute permissions to Gradlew | |
| run: chmod +x ./gradlew | |
| working-directory: HalfFifty_BE | |
| - name: Build and Test | |
| working-directory: HalfFifty_BE | |
| run: ./gradlew build | |
| 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: Build Docker Image | |
| working-directory: HalfFifty_BE | |
| run: docker build -t half-fifty:latest . | |
| - 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:latest | |
| - name: Verify Container Status | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.AWS_IP }} | |
| username: ${{ secrets.AWS_USER }} | |
| key: ${{ secrets.AWS_KEY }} | |
| script: docker ps | grep half-fifty |