diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..dbf03a32b --- /dev/null +++ b/Dockerfile @@ -0,0 +1,3 @@ +FROM eclipse-temurin:17-jdk-alpine +COPY build/libs/*.jar app.jar +ENTRYPOINT ["java", "-jar", "/app.jar"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 000000000..d10264786 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,65 @@ +pipeline{ + agent any + + environment{ + REGISTRY_URL = "https://hub.docker.com/repositories/prankumar313" + IMAGE_NAME = "spring-petclinic" + GIT_COMMIT_SHORT = "${env.GIT_COMMIT[0..6]}" + } + + stages{ + stage('Checkstyle'){ + when{ + not{ + branch 'main' + } + } + steps{ + sh './gradlew checkstyleMain' + archiveArtifacts artifacts: '**/build/reports/checkstyle/*.xml', allowEmptyArchive: true + } + } + + stage('Test'){ + when{ + not{ + branch 'main' + } + } + steps{ + sh './gradlew test' + junit '**/build/test-results/test/*.xml' + } + } + + stage('Build'){ + steps{ + sh './gradlew clean build -x test' + } + } + + stage('Build Docker Image'){ + steps{ + script{ + def ImageTag = env.BRANCH_NAME == 'main' ? 'latest' : GIT_COMMIT_SHORT + sh "docker build -t $REGISTRY_URL/${IMAGE_NAME}:${imageTag} ." + } + } + } + + stage('Push Docker Image'){ + steps{ + script{ + def targetRepo = env.BRANCH_NAME == 'main' ? 'main' : 'mr' + def imageTag = env.BRANCH_NAME == 'main' ? 'latest' : GIT_COMMIT_SHORT + sh """ + echo $DOCKER_PASSWORD | docker login -u $DOCKER_USERNAME --password-stdin $REGISTRY_URL + docker tag $REGISTRY_URL/$(IMAGE_NAME):${imageTag} $REGISTRY_URL/${targetRepo}/${IMAGE_NAME}:${imageTag} + docker push $REGISTRY_URL/${targetRepo}/${IMAGE_NAME}:${imageTag} + """ + } + } + } + } +} + diff --git a/build.gradle b/build.gradle index bef78d3f3..a83b254e9 100644 --- a/build.gradle +++ b/build.gradle @@ -1,5 +1,6 @@ plugins { id 'java' + id 'checkstyle' id 'org.springframework.boot' version '3.4.2' id 'io.spring.dependency-management' version '1.1.6' id 'org.graalvm.buildtools.native' version '0.10.3' @@ -24,6 +25,14 @@ java { sourceCompatibility = JavaVersion.VERSION_17 } +checkstyle{ + toolVersion = '10.12.3' + configFile = file("${rootDir}/config/checkstyle/checkstyle.xml") + configProperties = [ + 'checkstyle.cache.file': "${buildDir}/checkstyle/cachefile" + ] +} + repositories { mavenCentral() } diff --git a/config/checkstyle/checkstyle.xml b/config/checkstyle/checkstyle.xml new file mode 100644 index 000000000..5906505ca --- /dev/null +++ b/config/checkstyle/checkstyle.xml @@ -0,0 +1,448 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +