mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 04:55:50 +00:00
CI/CD Pipeline
This commit is contained in:
parent
147a8b4893
commit
f75ad7eb37
8 changed files with 94 additions and 232 deletions
26
.github/workflows/build-matrix.yaml
vendored
26
.github/workflows/build-matrix.yaml
vendored
|
@ -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
|
|
94
.github/workflows/ci-cd.yaml
vendored
Normal file
94
.github/workflows/ci-cd.yaml
vendored
Normal file
|
@ -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
|
||||||
|
|
31
.github/workflows/deploy-and-test-cluster.yml
vendored
31
.github/workflows/deploy-and-test-cluster.yml
vendored
|
@ -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
|
|
||||||
|
|
35
.github/workflows/docker-build.yml
vendored
35
.github/workflows/docker-build.yml
vendored
|
@ -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
|
|
||||||
|
|
31
.github/workflows/gradle-build.yml
vendored
31
.github/workflows/gradle-build.yml
vendored
|
@ -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
|
|
21
.github/workflows/java.yml
vendored
21
.github/workflows/java.yml
vendored
|
@ -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
|
|
||||||
|
|
29
.github/workflows/maven-build.yml
vendored
29
.github/workflows/maven-build.yml
vendored
|
@ -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
|
|
59
.github/workflows/multi-job.yaml
vendored
59
.github/workflows/multi-job.yaml
vendored
|
@ -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
|
|
Loading…
Reference in a new issue