From 7aa72562363906af305e0da4b74fcbfa85863969 Mon Sep 17 00:00:00 2001 From: Rajesh1b <118235010+Rajesh1b@users.noreply.github.com> Date: Mon, 23 Sep 2024 17:40:51 +0530 Subject: [PATCH 1/5] Create Dockerfile --- Dockerfile | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..20a007f7e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,26 @@ +# Use an official OpenJDK image as a base +FROM openjdk:17-slim + +# Set the working directory +WORKDIR /app + +# Copy the pom.xml and other necessary files first +COPY . . + +# Install Maven +RUN apt-get update && \ + apt-get install -y maven && \ + apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +# Expose the port +EXPOSE 8080 + +# Run Maven to build the application +RUN ./mvnw package + + + + +# Set the command to run the application +CMD ["java", "-jar", "target/spring-petclinic-3.3.0-SNAPSHOT.jar"] From 58d6105e774fa5e04a1ee90918fe2c116711655d Mon Sep 17 00:00:00 2001 From: Rajesh1b <118235010+Rajesh1b@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:42:05 +0530 Subject: [PATCH 2/5] Create deployment.yaml --- k8s/deployment.yaml | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 k8s/deployment.yaml diff --git a/k8s/deployment.yaml b/k8s/deployment.yaml new file mode 100644 index 000000000..4dc2304b1 --- /dev/null +++ b/k8s/deployment.yaml @@ -0,0 +1,21 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: petclinic + labels: + app: petclinic +spec: + replicas: 3 + selector: + matchLabels: + app: petclinic + template: + metadata: + labels: + app: petclinic + spec: + containers: + - name: petclinic-container + image: nginx:1.14.2 + ports: + - containerPort: 80 From b7b5ca185b27c66784799104311a7d2093d54013 Mon Sep 17 00:00:00 2001 From: Rajesh1b <118235010+Rajesh1b@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:45:50 +0530 Subject: [PATCH 3/5] Create service.yaml --- k8s/service.yaml | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 k8s/service.yaml diff --git a/k8s/service.yaml b/k8s/service.yaml new file mode 100644 index 000000000..00e5e077e --- /dev/null +++ b/k8s/service.yaml @@ -0,0 +1,17 @@ +apiVersion: v1 +kind: Service +metadata: + name: petclinic-service +spec: + type: NodePort + selector: + app: petclinic + ports: + - port: 80 + # 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 a113b6f5e0b3c42c23808f26daccc6378d661abb Mon Sep 17 00:00:00 2001 From: Rajesh1b <118235010+Rajesh1b@users.noreply.github.com> Date: Thu, 26 Sep 2024 15:51:23 +0530 Subject: [PATCH 4/5] Update Dockerfile --- Dockerfile | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index 20a007f7e..4258f2e0a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,25 +1,37 @@ -# Use an official OpenJDK image as a base -FROM openjdk:17-slim +#stage 1 +# Use a base image with OpenJDK +FROM openjdk:17-jdk-slim as build # Set the working directory WORKDIR /app -# Copy the pom.xml and other necessary files first -COPY . . - # Install Maven RUN apt-get update && \ apt-get install -y maven && \ apt-get clean && \ rm -rf /var/lib/apt/lists/* -# Expose the port -EXPOSE 8080 +# Copy the project files into the container +COPY . . -# Run Maven to build the application +# Package the application using Maven RUN ./mvnw package +#stage 2 +# Stage 2: Create a Distroless image +FROM gcr.io/distroless/java17 +# Set the working directory +WORKDIR /app + +# Copy the packaged JAR from the build stage +COPY --from=build /app/target/spring-petclinic-3.3.0-SNAPSHOT.jar app.jar + +#Expose port +EXPOSE 8080 + +#cmd command +CMD ["app.jar"] # Set the command to run the application From 9c55ed36c119a279b4d2f619be9add18be04a680 Mon Sep 17 00:00:00 2001 From: Rajesh1b <118235010+Rajesh1b@users.noreply.github.com> Date: Thu, 26 Sep 2024 16:10:16 +0530 Subject: [PATCH 5/5] Update Dockerfile --- Dockerfile | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index 4258f2e0a..fa9075747 100644 --- a/Dockerfile +++ b/Dockerfile @@ -32,7 +32,3 @@ EXPOSE 8080 #cmd command CMD ["app.jar"] - - -# Set the command to run the application -CMD ["java", "-jar", "target/spring-petclinic-3.3.0-SNAPSHOT.jar"]