Skip to content

Commit 350e5b0

Browse files
authored
Containerising App and verify Mongo and Kafka connections (#16)
* Prometheus setup * minor fix and app dashboard * Containerising App Verified mongo and Kafka and internally accessible from App
1 parent 172a0e4 commit 350e5b0

File tree

4 files changed

+58
-8
lines changed

4 files changed

+58
-8
lines changed

Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ RUN apt-get update && apt-get install -y telnet
1010
WORKDIR /app
1111

1212
# Copy the jar file
13-
COPY target/kafkaStudy-0.0.1-SNAPSHOT.jar .
13+
COPY target/kafkaStudy-0.0.1-SNAPSHOT.jar app.jar
1414

1515
# Command to run the application
16-
CMD ["java", "-jar", "kafkaStudy-0.0.1-SNAPSHOT.jar"]
16+
CMD ["java", "-jar", "app.jar"]

docker-compose.yml

+42-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,33 @@
1-
version: '2'
1+
version: '3.8' # Specify the version of the Compose file
2+
3+
networks:
4+
app-network: # Define the network here
5+
driver: bridge
26

37
services:
8+
app:
9+
build:
10+
context: . # Build from the current directory, where Dockerfile is located
11+
dockerfile: Dockerfile # Specify the Dockerfile
12+
container_name: kafka-study-app
13+
14+
ports:
15+
- "8080:8080" # Expose the app on localhost:8080
16+
depends_on:
17+
- kafka
18+
- mongodb
19+
command: ["java", "-jar", "/app/app.jar"] # Command to run the app
20+
networks:
21+
- app-network
22+
423
zookeeper:
524
image: wurstmeister/zookeeper:latest
625
ports:
726
- "2181:2181"
827
container_name: zookeeper
28+
networks:
29+
- app-network
30+
931
kafka:
1032
image: wurstmeister/kafka:latest
1133
ports:
@@ -24,17 +46,23 @@ services:
2446
- zookeeper
2547
volumes:
2648
- /var/run/docker.sock:/var/run/docker.sock
49+
networks:
50+
- app-network
51+
2752
mongodb:
2853
image: mongo:latest
29-
container_name: mongodb-container
54+
container_name: mongodb
3055
ports:
3156
- "27017:27017"
3257
environment:
3358
MONGO_INITDB_ROOT_USERNAME: root
3459
MONGO_INITDB_ROOT_PASSWORD: example
3560
volumes:
3661
- mongo-data:/data/db
37-
#sonar - code quality
62+
networks:
63+
- app-network
64+
65+
# SonarQube for code quality
3866
sonarqube:
3967
image: sonarqube
4068
ports:
@@ -47,7 +75,10 @@ services:
4775
- sonarqube_data:/opt/sonarqube/data
4876
- sonarqube_logs:/opt/sonarqube/logs
4977
- sonarqube_extensions:/opt/sonarqube/extensions
50-
#Sonar-related postgres
78+
networks:
79+
- app-network
80+
81+
# SonarQube-related PostgreSQL database
5182
postgres:
5283
image: postgres
5384
environment:
@@ -56,6 +87,8 @@ services:
5687
POSTGRES_PASSWORD: sonar
5788
volumes:
5889
- postgres_data:/var/lib/postgresql/data
90+
networks:
91+
- app-network
5992

6093
prometheus:
6194
image: prom/prometheus:latest
@@ -65,6 +98,8 @@ services:
6598
- prometheus_data:/prometheus
6699
ports:
67100
- "9090:9090"
101+
networks:
102+
- app-network
68103

69104
grafana:
70105
image: grafana/grafana:latest
@@ -75,6 +110,9 @@ services:
75110
- GF_SECURITY_ADMIN_PASSWORD=admin
76111
volumes:
77112
- grafana-storage:/var/lib/grafana
113+
networks:
114+
- app-network
115+
78116
volumes:
79117
mongo-data:
80118
sonarqube_data:

pom.xml

+12
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@
8888
<artifactId>sonar-maven-plugin</artifactId>
8989
<version>4.0.0.4121</version>
9090
</plugin>
91+
<plugin>
92+
<groupId>org.springframework.boot</groupId>
93+
<artifactId>spring-boot-maven-plugin</artifactId>
94+
<executions>
95+
<execution>
96+
<goals>
97+
<goal>repackage</goal>
98+
</goals>
99+
</execution>
100+
</executions>
101+
</plugin>
91102
</plugins>
92103
</build>
104+
93105
</project>

src/main/resources/application.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ spring.application.name=KafkaStudy
22
kafka.regular.topic=my-topic
33
regular.kafka.autostart=false
44
reactive.kafka.autostart=true
5-
spring.kafka.consumer.bootstrap-servers=127.0.0.1:9092
5+
spring.kafka.consumer.bootstrap-servers=kafka:9092
66
spring.kafka.consumer.group-id=demo-3
77
spring.kafka.consumer.auto-offset-reset=earliest
88
spring.kafka.consumer.key-deserializer=org.apache.kafka.common.serialization.StringDeserializer
99
spring.kafka.consumer.value-deserializer=org.apache.kafka.common.serialization.StringDeserializer
1010
spring.kafka.consumer.properties.session.timeout.ms=30000
1111
spring.kafka.consumer.properties.heartbeat.interval.ms=10000
12-
spring.data.mongodb.uri=mongodb://root:example@localhost:27017/testMongoDb?authSource=admin
12+
spring.data.mongodb.uri=mongodb://root:example@mongodb:27017/testMongoDb?authSource=admin
1313
mask.headers.list=pwd,pass
1414
management.endpoints.web.exposure.include = *

0 commit comments

Comments
 (0)