diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..32bcfa297 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,15 @@ +FROM maven:3.9-eclipse-temurin-17 AS build +WORKDIR /app +COPY pom.xml . +COPY src ./src +RUN mvn clean package -DskipTests + +# web.xml declares Servlet 2.5 (javax.servlet), but pom.xml actually pulls in +# Spring 6 / Boot 3.1, which is Jakarta-only (jakarta.servlet.*) — the real +# classes on the classpath, not the stale web.xml schema attribute, determine +# the runtime requirement. Tomcat 9 has no jakarta.servlet.* at all, which +# throws NoClassDefFoundError on Spring's ContextLoaderListener. Tomcat 10+ +# ships jakarta.servlet.* and deploys an old-schema web.xml fine regardless. +FROM tomcat:10.1-jdk17-temurin +COPY --from=build /app/target/*.war /usr/local/tomcat/webapps/ROOT.war +EXPOSE 8080 diff --git a/Jenkinsfile b/Jenkinsfile index e99abca44..74505b396 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,122 +1,42 @@ pipeline { - - agent any - - tools { - jdk "JDK17" - maven "MAVEN3.9" - } - + agent any + environment { - NEXUS_VERSION = "nexus3" - NEXUS_PROTOCOL = "http" - NEXUS_URL = "172.31.40.209:8081" - NEXUS_REPOSITORY = "vprofile-release" - NEXUS_REPO_ID = "vprofile-release" - NEXUS_CREDENTIAL_ID = "nexuslogin" - ARTVERSION = "${env.BUILD_ID}" + HARBOR_HOST = '192.168.56.20' + IMAGE = "${HARBOR_HOST}/vprofile/vproapp" + TAG = "${env.BUILD_NUMBER}" + KUBECONFIG = '/var/lib/jenkins/.kube/config' } - - stages{ - - stage('BUILD'){ - steps { - sh 'mvn clean install -DskipTests' - } - post { - success { - echo 'Now Archiving...' - archiveArtifacts artifacts: '**/target/*.war' - } - } - } - stage('UNIT TEST'){ + stages { + stage('Build image') { steps { - sh 'mvn test' + sh "docker build -t ${IMAGE}:${TAG} -t ${IMAGE}:latest ." } } - stage('INTEGRATION TEST'){ + stage('Push to Harbor') { steps { - sh 'mvn verify -DskipUnitTests' + sh ''' + set -a; . /etc/harbor-creds.env; set +a + echo "$HARBOR_PASS" | docker login "$HARBOR_HOST" -u "$HARBOR_USER" --password-stdin + ''' + sh "docker push ${IMAGE}:${TAG}" + sh "docker push ${IMAGE}:latest" } } - - stage ('CODE ANALYSIS WITH CHECKSTYLE'){ - steps { - sh 'mvn checkstyle:checkstyle' - } - post { - success { - echo 'Generated Analysis Result' - } - } - } - - stage('CODE ANALYSIS with SONARQUBE') { - - environment { - scannerHome = tool 'sonarscanner4' - } - steps { - withSonarQubeEnv('sonar-pro') { - sh '''${scannerHome}/bin/sonar-scanner -Dsonar.projectKey=vprofile \ - -Dsonar.projectName=vprofile-repo \ - -Dsonar.projectVersion=1.0 \ - -Dsonar.sources=src/ \ - -Dsonar.java.binaries=target/test-classes/com/visualpathit/account/controllerTest/ \ - -Dsonar.junit.reportsPath=target/surefire-reports/ \ - -Dsonar.jacoco.reportsPath=target/jacoco.exec \ - -Dsonar.java.checkstyle.reportPaths=target/checkstyle-result.xml''' - } - - timeout(time: 10, unit: 'MINUTES') { - waitForQualityGate abortPipeline: true - } - } - } - - stage("Publish to Nexus Repository Manager") { + stage('Deploy to Kubernetes') { steps { - script { - pom = readMavenPom file: "pom.xml"; - filesByGlob = findFiles(glob: "target/*.${pom.packaging}"); - echo "${filesByGlob[0].name} ${filesByGlob[0].path} ${filesByGlob[0].directory} ${filesByGlob[0].length} ${filesByGlob[0].lastModified}" - artifactPath = filesByGlob[0].path; - artifactExists = fileExists artifactPath; - if(artifactExists) { - echo "*** File: ${artifactPath}, group: ${pom.groupId}, packaging: ${pom.packaging}, version ${pom.version} ARTVERSION"; - nexusArtifactUploader( - nexusVersion: NEXUS_VERSION, - protocol: NEXUS_PROTOCOL, - nexusUrl: NEXUS_URL, - groupId: pom.groupId, - version: ARTVERSION, - repository: NEXUS_REPOSITORY, - credentialsId: NEXUS_CREDENTIAL_ID, - artifacts: [ - [artifactId: pom.artifactId, - classifier: '', - file: artifactPath, - type: pom.packaging], - [artifactId: pom.artifactId, - classifier: '', - file: "pom.xml", - type: "pom"] - ] - ); - } - else { - error "*** File: ${artifactPath}, could not be found"; - } - } + sh "kubectl -n vprofile set image deployment/vproapp vproapp=${IMAGE}:${TAG}" + sh "kubectl -n vprofile rollout status deployment/vproapp --timeout=180s" } } - - } - + post { + always { + sh 'docker image prune -f || true' + } + } } diff --git a/README.md b/README.md index 786f8549c..e1adec762 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ # Prerequisites -# + - JDK 17 or 21 - Maven 3.9 - MySQL 8 # Technologies - Spring MVC -- Spring Security +- Spring Security - Spring Data JPA - Maven - JSP @@ -20,6 +20,6 @@ Here,we used Mysql DB sql dump file: - /src/main/resources/db_backup.sql - db_backup.sql file is a mysql dump file.we have to import this dump to mysql db server -- > mysql -u -p accounts < db_backup.sql - - +- > mysql -u -p accounts < db_backup.sql. + + diff --git a/ansible/install.yml b/ansible/install.yml new file mode 100644 index 000000000..45b983be3 --- /dev/null +++ b/ansible/install.yml @@ -0,0 +1 @@ +hi