Skip to content

Commit 3328f51

Browse files
committed
removed -alpine from Dockerfile because its not compatible with M series chips, also added <goal>repackage</goal> so that maven binds up every springboot library into one rumble, changed localhost to http://discovery-server:8761/eureka/. Created Docker image with these changes containing --> mysqldb, discovery-server , api-gateway , event-service , booking-service
1 parent 6403cbe commit 3328f51

12 files changed

Lines changed: 186 additions & 58 deletions

File tree

‎api-gateway/Dockerfile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 1. Use an official Java runtime as a parent image
2-
FROM eclipse-temurin:17-jdk-alpine
3-
2+
FROM eclipse-temurin:17-jdk
43
# 2. Set the working directory inside the container
54
WORKDIR /app
65

‎api-gateway/pom.xml‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,20 @@
2222
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
2323
</dependency>
2424
</dependencies>
25+
26+
<build>
27+
<plugins>
28+
<plugin>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-maven-plugin</artifactId>
31+
<executions>
32+
<execution>
33+
<goals>
34+
<goal>repackage</goal>
35+
</goals>
36+
</execution>
37+
</executions>
38+
</plugin>
39+
</plugins>
40+
</build>
2541
</project>
Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
spring.application.name=api-gateway
22
server.port=8080
33

4-
# Connect to Eureka
5-
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
4+
# 1. FIX: Use the service name defined in docker-compose
5+
eureka.client.service-url.defaultZone=${EUREKA_URL:http://discovery-server:8761/eureka/}
66

7-
# --- ROUTING RULES ---
8-
9-
# Route 1: Events
10-
# "lb://" means Load Balance using Eureka!
7+
# 2. PRO TIP: Use UPPERCASE for service names in lb://
8+
# Eureka usually registers names in uppercase by default.
119
spring.cloud.gateway.routes[0].id=event-service
12-
spring.cloud.gateway.routes[0].uri=lb://event-service
10+
spring.cloud.gateway.routes[0].uri=lb://EVENT-SERVICE
1311
spring.cloud.gateway.routes[0].predicates[0]=Path=/api/events/**
1412

15-
# Route 2: Bookings
1613
spring.cloud.gateway.routes[1].id=booking-service
17-
spring.cloud.gateway.routes[1].uri=lb://booking-service
18-
spring.cloud.gateway.routes[1].predicates[0]=Path=/api/bookings/**
14+
spring.cloud.gateway.routes[1].uri=lb://BOOKING-SERVICE
15+
spring.cloud.gateway.routes[1].predicates[0]=Path=/api/bookings/**
16+
17+
eureka.instance.prefer-ip-address=true

‎booking-service/Dockerfile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 1. Use an official Java runtime as a parent image
2-
FROM eclipse-temurin:17-jdk-alpine
3-
2+
FROM eclipse-temurin:17-jdk
43
# 2. Set the working directory inside the container
54
WORKDIR /app
65

‎booking-service/pom.xml‎

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
<artifactId>booking-service</artifactId>
1313

14+
<properties>
15+
<java.version>17</java.version>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
</properties>
19+
1420
<dependencies>
1521
<dependency>
1622
<groupId>org.springframework.boot</groupId>
@@ -31,15 +37,57 @@
3137
<groupId>org.springframework.boot</groupId>
3238
<artifactId>spring-boot-starter-data-jpa</artifactId>
3339
</dependency>
40+
3441
<dependency>
3542
<groupId>com.mysql</groupId>
3643
<artifactId>mysql-connector-j</artifactId>
3744
<scope>runtime</scope>
3845
</dependency>
46+
3947
<dependency>
4048
<groupId>org.projectlombok</groupId>
4149
<artifactId>lombok</artifactId>
4250
<optional>true</optional>
4351
</dependency>
4452
</dependencies>
53+
54+
<build>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.apache.maven.plugins</groupId>
58+
<artifactId>maven-compiler-plugin</artifactId>
59+
<version>3.13.0</version>
60+
<configuration>
61+
<release>17</release>
62+
<annotationProcessorPaths>
63+
<path>
64+
<groupId>org.projectlombok</groupId>
65+
<artifactId>lombok</artifactId>
66+
<version>1.18.30</version>
67+
</path>
68+
</annotationProcessorPaths>
69+
</configuration>
70+
</plugin>
71+
<plugin>
72+
<groupId>org.springframework.boot</groupId>
73+
<artifactId>spring-boot-maven-plugin</artifactId>
74+
<configuration>
75+
<excludes>
76+
<exclude>
77+
<groupId>org.projectlombok</groupId>
78+
<artifactId>lombok</artifactId>
79+
</exclude>
80+
</excludes>
81+
</configuration>
82+
<executions>
83+
<execution>
84+
<goals>
85+
<goal>repackage</goal>
86+
</goals>
87+
</execution>
88+
</executions>
89+
</plugin>
90+
91+
</plugins>
92+
</build>
4593
</project>
Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
spring.application.name=booking-service
2-
# IMPORTANT: Different port!
3-
server.port=8082
2+
# Inside the container, we usually stick to 8080.
3+
# Docker Compose will handle the 8082 mapping for your Mac.
4+
server.port=8080
45

5-
# Eureka
6-
eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
6+
# 1. Eureka Fix: Use the service name 'discovery-server'
7+
eureka.client.service-url.defaultZone=${EUREKA_URL:http://discovery-server:8761/eureka/}
78

8-
# Database (We use the SAME MySQL server, but a DIFFERENT database name usually)
9-
# For simplicity, let's use the SAME 'event_db' for now, or create 'booking_db'
10-
spring.datasource.url=jdbc:mysql://localhost:3306/event_db?createDatabaseIfNotExist=true
11-
# Use placeholders (or your local file trick)
12-
spring.datasource.username=${DB_USERNAME}
13-
spring.datasource.password=${DB_PASSWORD}
9+
# 2. Database Fix: Use the service name 'mysqldb'
10+
spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:mysql://mysqldb:3306/stream_seat_db?createDatabaseIfNotExist=true}
11+
spring.datasource.username=${SPRING_DATASOURCE_USERNAME:root}
12+
spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:root}
1413
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
1514

15+
# 3. Networking Fix: Crucial for Docker
16+
eureka.instance.prefer-ip-address=true
17+
1618
spring.jpa.hibernate.ddl-auto=update
1719
spring.jpa.show-sql=true
18-
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
19-
20-
eureka.instance.hostname=localhost
21-
eureka.instance.prefer-ip-address=false
20+
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect

‎discovery-server/Dockerfile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 1. Use an official Java runtime as a parent image
2-
FROM eclipse-temurin:17-jdk-alpine
3-
2+
FROM eclipse-temurin:17-jdk
43
# 2. Set the working directory inside the container
54
WORKDIR /app
65

‎discovery-server/pom.xml‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@
1111

1212
<artifactId>discovery-server</artifactId>
1313

14+
<properties>
15+
<java.version>17</java.version>
16+
<maven.compiler.source>17</maven.compiler.source>
17+
<maven.compiler.target>17</maven.compiler.target>
18+
</properties>
19+
1420
<dependencies>
1521
<dependency>
1622
<groupId>org.springframework.cloud</groupId>
@@ -22,4 +28,20 @@
2228
<scope>test</scope>
2329
</dependency>
2430
</dependencies>
31+
32+
<build>
33+
<plugins>
34+
<plugin>
35+
<groupId>org.springframework.boot</groupId>
36+
<artifactId>spring-boot-maven-plugin</artifactId>
37+
<executions>
38+
<execution>
39+
<goals>
40+
<goal>repackage</goal>
41+
</goals>
42+
</execution>
43+
</executions>
44+
</plugin>
45+
</plugins>
46+
</build>
2547
</project>

‎docker-compose.yml‎

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,16 @@
11
version: '3.8'
22

33
services:
4+
mysqldb:
5+
image: mysql:8.0
6+
container_name: mysqldb
7+
environment:
8+
- MYSQL_DATABASE=stream_seat_db
9+
- MYSQL_ROOT_PASSWORD=root
10+
ports:
11+
- "3306:3306"
12+
networks:
13+
- microservices-net
414
# ----------------------------
515
# 1. THE BRAIN (Eureka Server)
616
# ----------------------------
@@ -32,7 +42,6 @@ services:
3242
- discovery-server
3343
networks:
3444
- microservices-net
35-
3645
# ----------------------------
3746
# 3. BOOKING SERVICE
3847
# ----------------------------
@@ -41,13 +50,17 @@ services:
4150
container_name: booking-service
4251
build: ./booking-service
4352
ports:
44-
- "8081:8080" # Optional: access directly via localhost:8081 if needed
53+
- "8081:8080"
4554
environment:
4655
- SPRING_APPLICATION_NAME=booking-service
4756
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-server:8761/eureka/
57+
# Link to the container named 'mysqldb'
58+
- SPRING_DATASOURCE_URL=jdbc:mysql://mysqldb:3306/stream_seat_db?createDatabaseIfNotExist=true
59+
- SPRING_DATASOURCE_USERNAME=root
60+
- SPRING_DATASOURCE_PASSWORD=root
4861
depends_on:
4962
- discovery-server
50-
- api-gateway
63+
- mysqldb # Added dependency
5164
networks:
5265
- microservices-net
5366

@@ -59,13 +72,17 @@ services:
5972
container_name: event-service
6073
build: ./event-service
6174
ports:
62-
- "8082:8080" # Optional: access directly via localhost:8082 if needed
75+
- "8082:8080"
6376
environment:
6477
- SPRING_APPLICATION_NAME=event-service
6578
- EUREKA_CLIENT_SERVICEURL_DEFAULTZONE=http://discovery-server:8761/eureka/
79+
# Link to the container named 'mysqldb'
80+
- SPRING_DATASOURCE_URL=jdbc:mysql://mysqldb:3306/stream_seat_db?createDatabaseIfNotExist=true
81+
- SPRING_DATASOURCE_USERNAME=root
82+
- SPRING_DATASOURCE_PASSWORD=root
6683
depends_on:
6784
- discovery-server
68-
- api-gateway
85+
- mysqldb # Added dependency
6986
networks:
7087
- microservices-net
7188

‎event-service/Dockerfile‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# 1. Use an official Java runtime as a parent image
2-
FROM eclipse-temurin:17-jdk-alpine
3-
2+
FROM eclipse-temurin:17-jdk
43
# 2. Set the working directory inside the container
54
WORKDIR /app
65

0 commit comments

Comments
 (0)