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/main.yml b/.github/workflows/main.yml new file mode 100644 index 000000000..27c7e4a57 --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,86 @@ +name: CI Pipeline + +on: + push: + branches: + - main + pull_request: + +jobs: + checkstyle: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + container: + image: maven:3.8.5-openjdk-17 + steps: + - uses: actions/checkout@v4 + - name: Run Checkstyle + run: mvn checkstyle:checkstyle + - name: Upload Checkstyle Report + uses: actions/upload-artifact@v4 + with: + name: checkstyle-result + path: target/checkstyle-result.xml + + test: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + container: + image: maven:3.8.5-openjdk-17 + needs: checkstyle + steps: + - uses: actions/checkout@v4 + - name: Run Tests + run: mvn test -Dmaven.test.failure.ignore=true + + build: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + container: + image: maven:3.8.5-openjdk-17 + needs: test + steps: + - uses: actions/checkout@v4 + - name: Build Package + run: mvn clean package -DskipTests + - name: Upload JAR Artifacts + uses: actions/upload-artifact@v4 + with: + name: jar-files + path: target/*.jar + + build_image: + if: github.event_name == 'pull_request' + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Registry (mr) + run: echo ${{ secrets.REGISTRY_PASS }} | docker login mr:8084 -u ${{ secrets.REGISTRY_USER }} --password-stdin + - name: Extract Short SHA + id: vars + run: echo "::set-output name=short_sha::$(echo $GITHUB_SHA | cut -c1-7)" + - name: Build Docker Image (mr) + run: docker build -t mr:8084/spring-petclinic:${{ steps.vars.outputs.short_sha }} . + - name: Push Docker Image (mr) + run: docker push mr:8084/spring-petclinic:${{ steps.vars.outputs.short_sha }} + + build_image_main: + if: github.ref == 'refs/heads/main' + runs-on: ubuntu-latest + needs: build + steps: + - uses: actions/checkout@v4 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + - name: Login to Registry (main) + run: echo ${{ secrets.REGISTRY_PASS }} | docker login main:8083 -u ${{ secrets.REGISTRY_USER }} --password-stdin + - name: Extract Short SHA + id: vars + run: echo "::set-output name=short_sha::$(echo $GITHUB_SHA | cut -c1-7)" + - name: Build Docker Image (main) + run: docker build -t main:8083/spring-petclinic:${{ steps.vars.outputs.short_sha }} . + - name: Push Docker Image (main) + run: docker push main:8083/spring-petclinic:${{ steps.vars.outputs.short_sha }} 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/Dockerfile b/Dockerfile new file mode 100644 index 000000000..21d1b5e84 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM maven AS build +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn clean package -DskipTests + +RUN jar xf /app/target/spring-petclinic-3.4.0-SNAPSHOT.jar +RUN jdeps \ + --ignore-missing-deps \ + --print-module-deps \ + --multi-release 17 \ + --recursive \ + --class-path 'BOOT-INF/lib/*' \ + /app/target/spring-petclinic-3.4.0-SNAPSHOT.jar > modules.txt + +RUN $JAVA_HOME/bin/jlink \ + --add-modules $(cat modules.txt) \ + --strip-debug \ + --no-man-pages \ + --no-header-files \ + --compress=2 \ + --output /javaruntime + +FROM debian:buster-slim +ENV JAVA_HOME=/opt/java/openjdk +ENV PATH="${JAVA_HOME}/bin:${PATH}" +COPY --from=build /javaruntime $JAVA_HOME + +WORKDIR /app +COPY --from=build /app/target/spring-petclinic-3.4.0-SNAPSHOT.jar . +CMD ["java", "-Dspring.profiles.active=postgres", "-jar", "spring-petclinic-3.4.0-SNAPSHOT.jar"] + diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..d22c2f937 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,94 @@ +pipeline { + agent none + + stages { + stage('Checkstyle') { + when { + changeRequest() + } + agent { + docker { image 'maven:3.8.5-openjdk-17' } + } + steps { + checkout scm + sh 'mvn checkstyle:checkstyle' + } + post { + always { + archiveArtifacts artifacts: 'target/checkstyle-result.xml', allowEmptyArchive: true + } + } + } + stage('Test') { + when { + changeRequest() + } + + agent { + docker { image 'maven:3.8.5-openjdk-17' } + } + steps { + sh 'mvn test -Dcheckstyle.skip=true' + } + } + stage('Build') { + when { + changeRequest() + } + + agent { + docker { image 'maven:3.8.5-openjdk-17' } + } + steps { + sh 'mvn clean package -DskipTests -Dcheckstyle.skip=true' + } + post { + always { + archiveArtifacts artifacts: 'target/*.jar', allowEmptyArchive: true + } + } + } + stage('Build Image') { + when { + changeRequest() + } + + agent { + docker { + image 'docker:20.10.16' + args '--privileged -u root -v /var/run/docker.sock:/var/run/docker.sock' + } + } + steps { + script { + def docker_image=docker.build("mr:8084/spring-petclinic:$GIT_COMMIT") + sh 'docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS" mr:8084' + docker.withRegistry('http://mr:8084') { + docker_image.push() + } + } + } + } + stage('Build Image Main') { + when { + not { changeRequest() } + } + + agent { + docker { + image 'docker:20.10.16' + args '--privileged -u root -v /var/run/docker.sock:/var/run/docker.sock' + } + } + steps { + script { + def docker_image=docker.build("main:8083/spring-petclinic:$GIT_COMMIT") + sh 'docker login -u "$REGISTRY_USER" -p "$REGISTRY_PASS" main:8083' + docker.withRegistry('http://main:8083') { + docker_image.push() + } + } + } + } + } +} diff --git a/README.md b/README.md index e34511b86..3a98b0b2e 100644 --- a/README.md +++ b/README.md @@ -1,9 +1,12 @@ # Spring PetClinic Sample Application [![Build Status](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml/badge.svg)](https://github.com/spring-projects/spring-petclinic/actions/workflows/maven-build.yml)[![Build Status](https://github.com/spring-projects/spring-petclinic/actions/workflows/gradle-build.yml/badge.svg)](https://github.com/spring-projects/spring-petclinic/actions/workflows/gradle-build.yml) + [![Open in Gitpod](https://gitpod.io/button/open-in-gitpod.svg)](https://gitpod.io/#https://github.com/spring-projects/spring-petclinic) [![Open in GitHub Codespaces](https://github.com/codespaces/badge.svg)](https://github.com/codespaces/new?hide_repo_select=true&ref=main&repo=7517918) ## Understanding the Spring Petclinic application with a few diagrams +## TESTMESSAGE + [See the presentation here](https://speakerdeck.com/michaelisvy/spring-petclinic-sample-application) ## Run Petclinic locally diff --git a/pom.xml b/pom.xml index 27fb9a6bd..bd4f400f0 100644 --- a/pom.xml +++ b/pom.xml @@ -169,8 +169,8 @@ This build requires at least Java ${java.version}, - update your JVM, and - run the build again + update your JVM, and + run the build again ${java.version} @@ -222,6 +222,18 @@ config_loc=${basedir}/src/checkstyle/ + + generate-checkstyle-report + verify + + checkstyle + + + src/checkstyle/nohttp-checkstyle.xml + target/site/checkstyle.html + plain + +