From a50efd206b74769261c8ca77c01de21ca763a92c Mon Sep 17 00:00:00 2001 From: Abhiramikannan Date: Thu, 3 Apr 2025 09:24:05 +0000 Subject: [PATCH 1/4] added dockerfile,deployment,service files --- Dockerfile | 34 ++++++++++++++++++++++++++++++++++ deployment.yaml | 21 +++++++++++++++++++++ service.yaml | 17 +++++++++++++++++ 3 files changed, 72 insertions(+) create mode 100644 Dockerfile create mode 100644 deployment.yaml create mode 100644 service.yaml diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..e98b32df --- /dev/null +++ b/Dockerfile @@ -0,0 +1,34 @@ +# setting the base image, will be creating the build image +FROM maven:3.8.8-eclipse-temurin-17 AS builder + +# setting up the work directory +WORKDIR /app + +# Copy the project files +COPY pom.xml . + +# run the mvn dependencies +RUN mvn dependency:go-offline + +# copy all the data to work directory +COPY . . + +# running mvn clean at build time +RUN mvn clean package -DskipTests + +# Use a lightweight JDK runtime for the final image +# using multiple from to build multi-stage image +FROM openjdk:17-jdk-slim + +# setting the new work directory +WORKDIR /app + +# Copy the built JAR from the builder stage +COPY --from=builder /app/target/*.jar app.jar + +# exposing port 8080 where java app will run +EXPOSE 8080 + +# setting the entry point, to run the application when it comes live +ENTRYPOINT ["java", "-jar", "app.jar"] + diff --git a/deployment.yaml b/deployment.yaml new file mode 100644 index 00000000..7f701105 --- /dev/null +++ b/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: hello-world-deployment + labels: + app: java-application +spec: + replicas: 3 + selector: + matchLabels: + app: java-application + template: + metadata: + labels: + app: java-application + spec: + containers: + - name: java-application + image: abhiramikannan/javaimage:latest + ports: + - containerPort: 8080 diff --git a/service.yaml b/service.yaml new file mode 100644 index 00000000..7b1ce6ee --- /dev/null +++ b/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: my-service +spec: + type: NodePort + selector: + app: java-application + ports: + - port: 8080 + # By default and for convenience, the `targetPort` is set to + # the same value as the `port` field. + targetPort: 8080 + # Optional field + # By default and for convenience, the Kubernetes control plane + # will allocate a port from a range (default: 30000-32767) + nodePort: 30007 From a5b317a5ec1708ceccff11e14771ab1c28900986 Mon Sep 17 00:00:00 2001 From: Abhiramikannan Date: Thu, 10 Apr 2025 09:07:28 +0000 Subject: [PATCH 2/4] Added Jenkinsfile for CI/CD --- Jenkinsfile | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile new file mode 100644 index 00000000..d9802f28 --- /dev/null +++ b/Jenkinsfile @@ -0,0 +1,44 @@ +pipeline { + agent any + + tools { + maven 'Maven3' + } + + environment { + REGISTRY = 'abhiramikannan' + IMAGE = 'spring-boot-hello-world' + } + + stages { + stage('Build and Test') { + steps { + sh 'mvn clean install' + } + } + + stage('Docker Build and Push') { + when { + branch 'develop' + } + steps { + script { + dockerImage = docker.build("${REGISTRY}/${IMAGE}:${env.BUILD_NUMBER}") + docker.withRegistry('', 'dockerhub-credentials-id') { + dockerImage.push() + } + } + } + } + + stage('Deploy to Kubernetes') { + when { + branch 'develop' + } + steps { + sh 'kubectl apply -f deployment.yaml' + sh 'kubectl apply -f service.yaml' + } + } + } +} From d27b3764c4e815cde34a3dd62a8e17c984c6e038 Mon Sep 17 00:00:00 2001 From: Abhirami kannan <85607268+Abhiramikannan@users.noreply.github.com> Date: Fri, 23 May 2025 17:07:17 +0530 Subject: [PATCH 3/4] Update Jenkinsfile --- Jenkinsfile | 43 ------------------------------------------- 1 file changed, 43 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d9802f28..8b137891 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,44 +1 @@ -pipeline { - agent any - tools { - maven 'Maven3' - } - - environment { - REGISTRY = 'abhiramikannan' - IMAGE = 'spring-boot-hello-world' - } - - stages { - stage('Build and Test') { - steps { - sh 'mvn clean install' - } - } - - stage('Docker Build and Push') { - when { - branch 'develop' - } - steps { - script { - dockerImage = docker.build("${REGISTRY}/${IMAGE}:${env.BUILD_NUMBER}") - docker.withRegistry('', 'dockerhub-credentials-id') { - dockerImage.push() - } - } - } - } - - stage('Deploy to Kubernetes') { - when { - branch 'develop' - } - steps { - sh 'kubectl apply -f deployment.yaml' - sh 'kubectl apply -f service.yaml' - } - } - } -} From f97ccba33cccf59d56ceb750f9430191f1f87b51 Mon Sep 17 00:00:00 2001 From: Abhirami kannan <85607268+Abhiramikannan@users.noreply.github.com> Date: Fri, 23 May 2025 17:08:37 +0530 Subject: [PATCH 4/4] Delete Jenkinsfile --- Jenkinsfile | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Jenkinsfile diff --git a/Jenkinsfile b/Jenkinsfile deleted file mode 100644 index 8b137891..00000000 --- a/Jenkinsfile +++ /dev/null @@ -1 +0,0 @@ -