diff --git a/.github/workflows/build-matrix.yaml b/.github/workflows/build-matrix.yaml deleted file mode 100644 index e0aad3c21..000000000 --- a/.github/workflows/build-matrix.yaml +++ /dev/null @@ -1,26 +0,0 @@ -name: Java CI Matrix Build - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - - strategy: - matrix: - java: [17, 21] - - name: Build with Java ${{ matrix.java }} - - steps: - - name: Checkout Code - uses: actions/checkout@v4 - - - name: Set up Java ${{ matrix.java }} - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: ${{ matrix.java }} - - - name: Build with Gradle - run: ./gradlew build diff --git a/.github/workflows/ci-cd.yaml b/.github/workflows/ci-cd.yaml new file mode 100644 index 000000000..7f114ebdf --- /dev/null +++ b/.github/workflows/ci-cd.yaml @@ -0,0 +1,94 @@ +name: Spring PetClinic CI/CD + +on: + pull_request: + branches: [main] + push: + branches: [main] + +env: + IMAGE_NAME: spring-petclinic + +jobs: + checkstyle: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + name: Checkstyle + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + - name: Checkstyle + run: ./gradlew checkstyleMain checkstyleTest + - name: Upload Checkstyle Report + uses: actions/upload-artifact@v4 + with: + name: checkstyle-report + path: build/reports/checkstyle/ + + test: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + needs: checkstyle + name: Run Tests + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + - run: ./gradlew test + + build: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + needs: test + name: Build App + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-java@v3 + with: + distribution: temurin + java-version: 17 + - run: ./gradlew build -x test + + docker-pr: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + needs: build + name: Build & Push Docker Image (MR) + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build & Push + run: | + SHORT_SHA=$(echo $GITHUB_SHA | cut -c1-7) + docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/mr:${SHORT_SHA} . + docker push ${{ secrets.DOCKERHUB_USERNAME }}/mr:${SHORT_SHA} + + docker-main: + if: github.ref == 'refs/heads/main' && github.event_name == 'push' + runs-on: ubuntu-latest + name: Build & Push Docker Image (Main) + steps: + - uses: actions/checkout@v3 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKERHUB_USERNAME }} + password: ${{ secrets.DOCKERHUB_TOKEN }} + - name: Build & Push + run: | + docker build -t ${{ secrets.DOCKERHUB_USERNAME }}/main:latest . + docker push ${{ secrets.DOCKERHUB_USERNAME }}/main:latest + diff --git a/.github/workflows/deploy-and-test-cluster.yml b/.github/workflows/deploy-and-test-cluster.yml deleted file mode 100644 index 7353a604b..000000000 --- a/.github/workflows/deploy-and-test-cluster.yml +++ /dev/null @@ -1,31 +0,0 @@ -name: Deploy and Test Cluster - -on: - push: - branches: [main] - paths: - - 'k8s/**' - pull_request: - branches: [main] - paths: - - 'k8s/**' - -jobs: - deploy-and-test-cluster: - runs-on: ubuntu-latest - steps: - - name: Check out the repository - uses: actions/checkout@v2 - - - name: Create k8s Kind Cluster - uses: helm/kind-action@v1 - - - name: Deploy application - run: | - kubectl apply -f k8s/ - - - name: Wait for Pods to be ready - run: | - kubectl wait --for=condition=ready pod -l app=demo-db --timeout=180s - kubectl wait --for=condition=ready pod -l app=petclinic --timeout=180s - diff --git a/.github/workflows/docker-build.yml b/.github/workflows/docker-build.yml deleted file mode 100644 index 879ef648c..000000000 --- a/.github/workflows/docker-build.yml +++ /dev/null @@ -1,35 +0,0 @@ -name: Build and Push Docker Image - -on: - push: - branches: [ main ] - -jobs: - build-and-push: - runs-on: ubuntu-latest - - steps: - - name: ๐Ÿงพ Checkout Code - uses: actions/checkout@v4 - - - name: โ˜• Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - - - name: ๐Ÿงฑ Build with Gradle - run: ./gradlew build - - - name: ๐Ÿ” Log in to Docker Hub - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: ๐Ÿณ Build and Tag Docker Image - run: docker build -t ${{ secrets.DOCKER_USERNAME }}/spring-petclinic:latest . - - - name: ๐Ÿš€ Push Docker Image - run: docker push ${{ secrets.DOCKER_USERNAME }}/spring-petclinic:latest - diff --git a/.github/workflows/gradle-build.yml b/.github/workflows/gradle-build.yml deleted file mode 100644 index c24c121b1..000000000 --- a/.github/workflows/gradle-build.yml +++ /dev/null @@ -1,31 +0,0 @@ -# This workflow will build a Java project with Gradle, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-gradle - -name: Java CI with Gradle - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - matrix: - java: [ '17' ] - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK ${{matrix.java}} - uses: actions/setup-java@v4 - with: - java-version: ${{matrix.java}} - distribution: 'adopt' - cache: maven - - name: Setup Gradle - uses: gradle/actions/setup-gradle@v4 - - name: Build with Gradle - run: ./gradlew build diff --git a/.github/workflows/java.yml b/.github/workflows/java.yml deleted file mode 100644 index b344d975f..000000000 --- a/.github/workflows/java.yml +++ /dev/null @@ -1,21 +0,0 @@ -name: Java CI with Gradle - -on: [push, pull_request] - -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: ๐Ÿ“ฅ Checkout code - uses: actions/checkout@v4 - - - name: โ˜• Set up JDK 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: '17' - - - name: ๐Ÿ“ฆ Build with Gradle - run: ./gradlew build - diff --git a/.github/workflows/maven-build.yml b/.github/workflows/maven-build.yml deleted file mode 100644 index a1ec4dab7..000000000 --- a/.github/workflows/maven-build.yml +++ /dev/null @@ -1,29 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/use-cases-and-examples/building-and-testing/building-and-testing-java-with-maven - -name: Java CI with Maven - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -jobs: - build: - - runs-on: ubuntu-latest - strategy: - matrix: - java: [ '17' ] - - steps: - - uses: actions/checkout@v4 - - name: Set up JDK ${{matrix.java}} - uses: actions/setup-java@v4 - with: - java-version: ${{matrix.java}} - distribution: 'adopt' - cache: maven - - name: Build with Maven Wrapper - run: ./mvnw -B verify diff --git a/.github/workflows/multi-job.yaml b/.github/workflows/multi-job.yaml deleted file mode 100644 index 01e291fff..000000000 --- a/.github/workflows/multi-job.yaml +++ /dev/null @@ -1,59 +0,0 @@ -name: Multi-Job CI/CD Pipeline - -on: [push, pull_request] - -jobs: - test: - name: Run Tests - runs-on: ubuntu-latest - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Java 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 17 - - - name: Make Gradle executable - run: chmod +x ./gradlew - - - name: Run Tests - run: ./gradlew test - - build: - name: Build App - runs-on: ubuntu-latest - needs: test - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Setup Java 17 - uses: actions/setup-java@v4 - with: - distribution: 'temurin' - java-version: 17 - - - name: Make Gradle executable - run: chmod +x ./gradlew - - docker_push: - name: Push to Docker Hub - runs-on: ubuntu-latest - needs: build - steps: - - name: Checkout code - uses: actions/checkout@v4 - - - name: Docker Hub Login - uses: docker/login-action@v3 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Build and Push Docker Image - run: | - docker build -t ${{ secrets.DOCKER_USERNAME }}/spring-petclinic:latest . - docker push ${{ secrets.DOCKER_USERNAME }}/spring-petclinic:latest