From 08f187e410e9d8227fd06497ccca80dd2d57cded Mon Sep 17 00:00:00 2001 From: JaninduMunasinghe Date: Sat, 12 Jul 2025 11:32:56 +0530 Subject: [PATCH 1/4] Dockerize publisher app --- publisher/Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 publisher/Dockerfile diff --git a/publisher/Dockerfile b/publisher/Dockerfile new file mode 100644 index 0000000..a0cc7ca --- /dev/null +++ b/publisher/Dockerfile @@ -0,0 +1,14 @@ +# Use an official OpenJDK image as a base +FROM eclipse-temurin:21-jre + +# Set the working directory +WORKDIR /app + +# Copy the built jar file into the container +COPY target/publisher-0.0.1-SNAPSHOT.jar app.jar + +# Expose the application port +EXPOSE 9219 + +# Run the application +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file From 235e04bde0a3ac83f241bfb50212890420d39075 Mon Sep 17 00:00:00 2001 From: JaninduMunasinghe Date: Sat, 12 Jul 2025 11:44:45 +0530 Subject: [PATCH 2/4] Dockerize consumer app --- consumer/Dockerfile | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 consumer/Dockerfile diff --git a/consumer/Dockerfile b/consumer/Dockerfile new file mode 100644 index 0000000..5570f26 --- /dev/null +++ b/consumer/Dockerfile @@ -0,0 +1,14 @@ +# Use an official OpenJDK image as a base +FROM eclipse-temurin:21-jre + +# Set the working directory +WORKDIR /app + +# Copy the built jar file into the container +COPY target/consumer-0.0.1-SNAPSHOT.jar app.jar + +# Expose the application port +EXPOSE 9229 + +# Run the application +ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file From 06915eb1e67d02295428309ba29d202c64960f29 Mon Sep 17 00:00:00 2001 From: JaninduMunasinghe Date: Sun, 13 Jul 2025 12:00:47 +0530 Subject: [PATCH 3/4] refactored Dockerfile for multi-stage build --- docker-compose.yml | 43 ++++++++++++++++++ publisher/Dockerfile | 25 ++++++---- .../compile/default-compile/inputFiles.lst | 2 +- shared-dto/target/shared-dto-1.0.0.jar | Bin 2340 -> 2341 bytes 4 files changed, 59 insertions(+), 11 deletions(-) create mode 100644 docker-compose.yml diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..735670a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,43 @@ +version: "3.8" + +services: + zookeeper: + image: confluentinc/cp-zookeeper:7.5.0 + environment: + ZOOKEEPER_CLIENT_PORT: 2181 + ZOOKEEPER_TICK_TIME: 2000 + ports: + - "2181:2181" + + kafka: + image: confluentinc/cp-kafka:7.5.0 + depends_on: + - zookeeper + ports: + - "9092:9092" + environment: + KAFKA_BROKER_ID: 1 + KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 + KAFKA_ADVERTISED_LISTENERS: PLAINTEXT://kafka:9092,PLAINTEXT_HOST://localhost:9092 + KAFKA_LISTENERS: PLAINTEXT://0.0.0.0:9092,PLAINTEXT_HOST://0.0.0.0:9093 + KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: PLAINTEXT:PLAINTEXT,PLAINTEXT_HOST:PLAINTEXT + KAFKA_INTER_BROKER_LISTENER_NAME: PLAINTEXT + KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: 1 + + publisher: + image: janindu1999/publisher-app:latest + depends_on: + - kafka + ports: + - "9219:9219" + environment: + SPRING_KAFKA_BOOTSTRAP_SERVERS: kafka:9092 + + consumer: + image: janindu1999/consumer-app:latest + depends_on: + - kafka + ports: + - "9229:9229" + environment: + SPRING_KAFKA_BOOTSTRAP_SERVERS: kafka:9092 diff --git a/publisher/Dockerfile b/publisher/Dockerfile index a0cc7ca..df33fe4 100644 --- a/publisher/Dockerfile +++ b/publisher/Dockerfile @@ -1,14 +1,19 @@ -# Use an official OpenJDK image as a base -FROM eclipse-temurin:21-jre - -# Set the working directory +# Stage 1: Build shared-dto +FROM maven:3.9.6-eclipse-temurin-21 AS build WORKDIR /app -# Copy the built jar file into the container -COPY target/publisher-0.0.1-SNAPSHOT.jar app.jar +# Copy and build shared-dto first +COPY shared-dto ./shared-dto +RUN mvn install -f shared-dto/pom.xml -DskipTests -# Expose the application port -EXPOSE 9219 +# Copy the rest and build publisher (including its dependencies) +COPY publisher ./publisher +COPY consumer ./consumer +RUN mvn clean package -f publisher/pom.xml -DskipTests -# Run the application -ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file +# Stage 2: Run the application +FROM eclipse-temurin:21-jre +WORKDIR /app +COPY --from=build /app/publisher/target/publisher-0.0.1-SNAPSHOT.jar app.jar +EXPOSE 9219 +ENTRYPOINT ["java", "-jar", "app.jar"] diff --git a/shared-dto/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/shared-dto/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst index 7386fa2..0b37f0b 100644 --- a/shared-dto/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +++ b/shared-dto/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -1 +1 @@ -E:\I_Learn_Cloud\Projects\Springboot Kafka\shared-dto\src\main\java\com\shared\dto\Customer.java +C:\Projects\Java\Spring Boot\Kafka\springboot-kafka-pubsub\shared-dto\src\main\java\com\shared\dto\Customer.java diff --git a/shared-dto/target/shared-dto-1.0.0.jar b/shared-dto/target/shared-dto-1.0.0.jar index df49cbcb99ec8096a76dd2427e7ad65b22589cad..e1355b00b1191dc3d8c8912fd272b68a3686dda5 100644 GIT binary patch delta 447 zcmZ1?v{Z;Uz?+$ci-CcIfq^Uf%|u=mP9PPvi&N=S@I z45DtSfvCyMj9SbBaSf1{oS&;7;LXS+!VGaU$N?wWq~*>*<%%;Bi&9fCl-RRN zGk%{e$SA^#&#RUG_ar|sd8X6j^xh{~}E0IgtP003l;X;c6J delta 433 zcmZ1~v_yzEz?+$ci-CcIf#KGadlPw8IDu5ut*A#GK@+XAg_*iO7BMm))Z757*(uKq zqHe2!sL3phTFgK#lMSJC9HS|iKaJ4=B)|D4BQG=aOrV07EUO?AtZiUgp3MYd*W?&B zOH-ioC_ymed+IZl;GKnxloD6cnDK=@jvrxI>jKreU6bvN}?9zeQ-7{DA1z)*;CRf=X$1}dBn#5yP%Zcnb~um(GDFNZW! Z2kYbp4(-VoSh*(ia|*EW1I=e(004^HdsYAd From 586cac395a0fd1e06bc389bf6882ec9eebb7bc40 Mon Sep 17 00:00:00 2001 From: JaninduMunasinghe Date: Sun, 13 Jul 2025 12:20:15 +0530 Subject: [PATCH 4/4] Refactored consumer dockerfile for multi-stage build --- consumer/Dockerfile | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/consumer/Dockerfile b/consumer/Dockerfile index 5570f26..e696046 100644 --- a/consumer/Dockerfile +++ b/consumer/Dockerfile @@ -1,14 +1,18 @@ -# Use an official OpenJDK image as a base -FROM eclipse-temurin:21-jre - -# Set the working directory +# Stage 1: Build shared-dto +FROM maven:3.9.6-eclipse-temurin-21 AS build WORKDIR /app -# Copy the built jar file into the container -COPY target/consumer-0.0.1-SNAPSHOT.jar app.jar +# Copy and build shared-dto +COPY shared-dto ./shared-dto +RUN mvn install -f shared-dto/pom.xml -DskipTests -# Expose the application port -EXPOSE 9229 +# Copy and build consumer (flat, to avoid nesting) +COPY consumer ./consumer +RUN mvn clean package -f consumer/pom.xml -DskipTests -# Run the application -ENTRYPOINT ["java", "-jar", "app.jar"] \ No newline at end of file +# Stage 2: Run the application +FROM eclipse-temurin:21-jre +WORKDIR /app +COPY --from=build /app/consumer/target/consumer-0.0.1-SNAPSHOT.jar app.jar +EXPOSE 9220 +ENTRYPOINT ["java", "-jar", "app.jar"]