diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..b910c9ac --- /dev/null +++ b/Dockerfile @@ -0,0 +1,13 @@ +FROM openjdk:17-jdk-slim + + +WORKDIR /app + + +COPY target/spring-boot-2-hello-world-1.0.2-SNAPSHOT.jar app.jar + + +EXPOSE 8080 + + +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..58a981ea --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,50 @@ +pipeline { + agent any + + environment { + SONARQUBE_ENV = 'MySonarQube' + } + + stages { + stage('Checkout') { + steps { + checkout scm + } + } + + stage('Build with Maven') { + steps { + sh 'mvn clean package -DskipTests' + } + } + + stage('SonarQube Analysis') { + steps { + withSonarQubeEnv("${SONARQUBE_ENV}") { + sh 'mvn sonar:sonar' + } + } + } + + stage('Quality Gate') { + steps { + waitForQualityGate abortPipeline: true + } + } + + stage('Archive JAR') { + steps { + archiveArtifacts artifacts: 'target/*.jar', fingerprint: true + } + } + } + + post { + success { + echo "JAR built, analyzed by SonarQube, and archived successfully." + } + failure { + echo "Build failed due to errors or Quality Gate failure." + } + } +} diff --git a/deployment.yaml b/deployment.yaml new file mode 100644 index 00000000..92776678 --- /dev/null +++ b/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: helloworld-deployment + namespace: default + labels: + app: helloworld-deployment +spec: + replicas: 1 + selector: + matchLabels: + app: helloworld-deployment + template: + metadata: + labels: + app: helloworld-deployment + spec: + containers: + - name: springapp + image: yogeshpri/devopsexam + imagePullPolicy: Always diff --git a/services.yaml b/services.yaml new file mode 100644 index 00000000..ddb6a696 --- /dev/null +++ b/services.yaml @@ -0,0 +1,13 @@ +apiVersion: v1 +kind: Service +metadata: + name: hello-world-service +spec: + selector: + app: helloworld-deployment + ports: + - protocol: TCP + port: 80 + targetPort: 8080 + nodePort: 30015 + type: NodePort