Skip to content

Commit 65e3d62

Browse files
authored
Fix Microprofile image and add Eureka connection (#1082)
* Fix Microprofile image and add Eureka connection * Package as a thin jar zip file * Add Assembly configuration
1 parent facd9f7 commit 65e3d62

File tree

6 files changed

+257
-65
lines changed

6 files changed

+257
-65
lines changed
Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
1-
21
# 1st stage, build the app
32
FROM container-registry.oracle.com/java/jdk-no-fee-term:21 as build
43

54
# Install maven
65
WORKDIR /usr/share
76
RUN set -x && \
87
curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \
9-
tar -xvf apache-maven-*-bin.tar.gz && \
8+
tar -xvf apache-maven-*-bin.tar.gz && \
109
rm apache-maven-*-bin.tar.gz && \
1110
mv apache-maven-* maven && \
1211
ln -s /usr/share/maven/bin/mvn /bin/
1312

1413
WORKDIR /helidon
1514

1615
# Create a first layer to cache the "Maven World" in the local repository.
17-
# Incremental docker builds will always resume after that, unless you update
18-
# the pom
1916
ADD pom.xml .
20-
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip -Declipselink.weave.skip -DskipOpenApiGenerate
17+
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip -DskipOpenApiGenerate
2118

22-
# Do the Maven build!
23-
# Incremental docker builds will resume here when you change sources
19+
# Do the Maven build with fat JAR!
2420
ADD src src
2521
RUN mvn package -DskipTests
2622

27-
RUN echo "done!"
28-
2923
# 2nd stage, build the runtime image
3024
FROM container-registry.oracle.com/java/jdk-no-fee-term:21
25+
3126
WORKDIR /helidon
3227

33-
# Copy the binary built in the 1st stage
34-
COPY --from=build /helidon/target/customer-helidon.jar ./
35-
COPY --from=build /helidon/target/libs ./libs
28+
# Copy ONLY the fat JAR (not libs directory)
29+
COPY --from=build /helidon/target/*.jar app.jar
3630

37-
CMD ["java", "-jar", "customer-helidon.jar"]
31+
# Simple fat JAR execution
32+
CMD ["java", "-jar", "app.jar"]
3833

3934
EXPOSE 8080
35+
Lines changed: 163 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,80 @@
11
# customer-helidon
22

3-
Helidon MP version of the "customer" microservice.
3+
Helidon MP version of the "customer" microservice built using the **Helidon MP profile** for enterprise Java applications with CDI, JPA, and microservices capabilities.
44

55
## Build and run
66

7+
### Prerequisites
8+
- JDK 21
9+
- Maven 3.8+
10+
11+
### Building the Application
12+
13+
The build process creates a **thin JAR deployment package** as a ZIP file containing the application JAR and all dependencies:
714

8-
With JDK21
915
```bash
10-
mvn package
11-
java -jar target/customer-helidon.jar
16+
mvn clean package
1217
```
1318

14-
## Exercise the application
19+
This creates:
20+
- `target/customer-helidon.jar` - The thin application JAR
21+
- `target/customer-helidon-deployment.zip` - Complete deployment package with structure:
22+
```
23+
customer-helidon.jar (main application)
24+
app/
25+
libs/ (all dependency JARs)
26+
```
27+
28+
### Running the Application
1529

16-
Basic:
30+
**Option 1: Using the thin JAR (requires dependencies in classpath):**
31+
```bash
32+
# Extract the deployment ZIP first
33+
cd target
34+
unzip customer-helidon-deployment.zip
35+
java -jar customer-helidon.jar
1736
```
18-
curl -X GET http://localhost:8080/simple-greet
19-
Hello World!
37+
38+
**Option 2: Using Maven to run directly:**
39+
```bash
40+
mvn exec:java
2041
```
2142

43+
## Quick Start with Local Oracle Database
44+
45+
To run against a local Oracle Docker container, simply:
2246

23-
JSON:
47+
1. **Start Oracle Database container:**
48+
```bash
49+
docker run -d --name oracle-db -p 1521:1521 \
50+
-e ORACLE_PWD=Welcome12345 \
51+
container-registry.oracle.com/database/free:latest
52+
```
53+
54+
2. **Uncomment database configuration** in `src/main/resources/application.yaml`:
55+
```yaml
56+
javax.sql.DataSource.customer.URL = jdbc:oracle:thin:@//localhost:1521/freepdb1
57+
javax.sql.DataSource.customer.user = customer
58+
javax.sql.DataSource.customer.password = Welcome12345
59+
```
60+
61+
3. **Rebuild and run:**
62+
```bash
63+
mvn clean package
64+
cd target && unzip customer-helidon-deployment.zip
65+
java -jar customer-helidon.jar
66+
```
67+
68+
The application will automatically create the necessary database tables on startup using Hibernate's DDL auto-generation.
69+
70+
### Basic:
71+
```bash
72+
curl -X GET http://localhost:8080/simple-greet
73+
Hello World!
2474
```
75+
76+
### JSON:
77+
```bash
2578
curl -X GET http://localhost:8080/greet
2679
{"message":"Hello World!"}
2780

@@ -34,61 +87,130 @@ curl -X GET http://localhost:8080/greet/Jose
3487
{"message":"Hola Jose!"}
3588
```
3689

37-
38-
39-
## Try health
40-
41-
```
90+
### Try health
91+
```bash
4292
curl -s -X GET http://localhost:8080/health
4393
{"outcome":"UP",...
44-
4594
```
4695

96+
### Try metrics
97+
```bash
98+
# Prometheus Format
99+
curl -s -X GET http://localhost:8080/metrics
100+
# TYPE base:gc_g1_young_generation_count gauge
101+
. . .
102+
103+
# JSON Format
104+
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
105+
{"base":...
106+
. . .
107+
```
47108

48109
## Building a Native Image
49110

50111
The generation of native binaries requires an installation of GraalVM 22.1.0+.
51-
52112
You can build a native binary using Maven as follows:
53113

54-
```
114+
```bash
55115
mvn -Pnative-image install -DskipTests
56116
```
57117

58-
The generation of the executable binary may take a few minutes to complete depending on
59-
your hardware and operating system. When completed, the executable file will be available
60-
under the `target` directory and be named after the artifact ID you have chosen during the
61-
project generation phase.
62-
118+
The generation of the executable binary may take a few minutes to complete depending on your hardware and operating system. When completed, the executable file will be available under the `target` directory and be named after the artifact ID you have chosen during the project generation phase.
63119

120+
## Docker Support
64121

65-
## Try metrics
122+
### Building the Docker Image
123+
```bash
124+
docker build -t customer-helidon .
125+
```
66126

127+
### Running the Docker Image
128+
```bash
129+
docker run --rm -p 8080:8080 customer-helidon:latest
67130
```
68-
# Prometheus Format
69-
curl -s -X GET http://localhost:8080/metrics
70-
# TYPE base:gc_g1_young_generation_count gauge
71-
. . .
72131

73-
# JSON Format
74-
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
75-
{"base":...
76-
. . .
132+
Exercise the application as described above.
133+
134+
## Configuration
135+
136+
### Application Properties (`application.yaml`)
137+
```yaml
138+
# Microprofile server properties
139+
server.port=8080
140+
server.host=0.0.0.0
141+
# Change the following to true to enable the optional MicroProfile Metrics REST.request metrics
142+
metrics.rest-request.enabled=false
143+
144+
# Application properties. This is the default greeting
145+
app.greeting=Hello
146+
147+
# Database connection factory - specifies Oracle UCP driver for connection pooling
148+
javax.sql.DataSource.customer.connectionFactoryClassName = oracle.jdbc.pool.OracleDataSource
149+
150+
# Local Oracle Database Configuration
151+
# Uncomment the following lines to connect to a local Oracle Docker container out-of-the-box:
152+
# javax.sql.DataSource.customer.URL = jdbc:oracle:thin:@//localhost:1521/freepdb1
153+
# javax.sql.DataSource.customer.user = customer
154+
# javax.sql.DataSource.customer.password = Welcome12345
155+
156+
# Hibernate/JPA Configuration
157+
hibernate.hbm2ddl.auto=create
158+
hibernate.show_sql=true
159+
hibernate.format_sql=true
160+
# Fix JTA transaction coordinator issue
161+
hibernate.transaction.coordinator_class=jta
162+
163+
# Eureka service discovery configuration
164+
server.features.eureka.client.base-uri=http://eureka.eureka:8761/eureka
165+
server.features.eureka.instance.name=helidon-customer-service
166+
server.features.eureka.instance.hostName=helidon.helidon
77167
```
78168

169+
## Build Architecture
79170

171+
This project uses:
172+
- **Helidon MP (MicroProfile)** - Enterprise Java microservices profile
173+
- **Thin JAR deployment** - Application JAR + separate dependencies for optimal Docker layering
174+
- **Maven Assembly Plugin** - Creates deployment ZIP with proper structure for containerization
175+
- **Hibernate + JTA** - Database persistence with transaction management
176+
- **Oracle UCP** - Connection pooling for Oracle Database
177+
- **Eureka integration** - Service discovery support
80178

81-
## Building the Docker Image
179+
## Dockerfile Structure
82180

83-
```
84-
docker build -t customer-helidon .
85-
```
181+
The included Dockerfile uses a **multi-stage build**:
86182

87-
## Running the Docker Image
183+
```dockerfile
184+
# 1st stage, build the app
185+
FROM container-registry.oracle.com/java/jdk-no-fee-term:21 as build
88186

89-
```
90-
docker run --rm -p 8080:8080 customer-helidon:latest
91-
```
187+
# Install maven
188+
WORKDIR /usr/share
189+
RUN set -x && \
190+
curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \
191+
tar -xvf apache-maven-*-bin.tar.gz && \
192+
rm apache-maven-*-bin.tar.gz && \
193+
mv apache-maven-* maven && \
194+
ln -s /usr/share/maven/bin/mvn /bin/
92195

93-
Exercise the application as described above.
94-
196+
WORKDIR /helidon
197+
198+
# Create a first layer to cache the "Maven World" in the local repository.
199+
ADD pom.xml .
200+
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip -DskipOpenApiGenerate
201+
202+
# Do the Maven build with fat JAR!
203+
ADD src src
204+
RUN mvn package -DskipTests
205+
206+
# 2nd stage, build the runtime image
207+
FROM container-registry.oracle.com/java/jdk-no-fee-term:21
208+
WORKDIR /helidon
209+
210+
# Copy ONLY the fat JAR (not libs directory)
211+
COPY --from=build /helidon/target/*.jar app.jar
212+
213+
# Simple fat JAR execution
214+
CMD ["java", "-jar", "app.jar"]
215+
EXPOSE 8080
216+
```

cloudbank-v4/customer-helidon/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
<artifactId>jakarta.persistence-api</artifactId>
4444
<!-- <scope>provided</scope> -->
4545
</dependency>
46+
<dependency>
47+
<groupId>io.helidon.integrations.eureka</groupId>
48+
<artifactId>helidon-integrations-eureka</artifactId>
49+
<scope>runtime</scope>
50+
</dependency>
4651
<dependency>
4752
<groupId>io.helidon.integrations.cdi</groupId>
4853
<artifactId>helidon-integrations-cdi-jpa</artifactId>
@@ -58,6 +63,11 @@
5863
<artifactId>hibernate-core</artifactId>
5964
<version>${version.lib.hibernate}</version>
6065
</dependency>
66+
<!--dependency>
67+
<groupId>io.helidon.logging</groupId>
68+
<artifactId>helidon-logging-jul</artifactId>
69+
<scope>runtime</scope>
70+
</dependency-->
6171
<dependency>
6272
<groupId>io.helidon.microprofile.openapi</groupId>
6373
<artifactId>helidon-microprofile-openapi</artifactId>
@@ -153,6 +163,38 @@
153163
</execution>
154164
</executions>
155165
</plugin>
166+
<plugin>
167+
<groupId>org.apache.maven.plugins</groupId>
168+
<artifactId>maven-assembly-plugin</artifactId>
169+
<version>3.4.2</version>
170+
<configuration>
171+
<descriptors>
172+
<descriptor>src/assembly/jib-ready.xml</descriptor>
173+
</descriptors>
174+
</configuration>
175+
<executions>
176+
<execution>
177+
<phase>package</phase>
178+
<goals>
179+
<goal>single</goal>
180+
</goals>
181+
</execution>
182+
</executions>
183+
</plugin>
184+
<!-- Explicitly set the correct main class for Helidon MP -->
185+
<plugin>
186+
<groupId>org.apache.maven.plugins</groupId>
187+
<artifactId>maven-jar-plugin</artifactId>
188+
<configuration>
189+
<archive>
190+
<manifest>
191+
<addClasspath>true</addClasspath>
192+
<classpathPrefix>libs/</classpathPrefix>
193+
<mainClass>io.helidon.microprofile.cdi.Main</mainClass>
194+
</manifest>
195+
</archive>
196+
</configuration>
197+
</plugin>
156198
<plugin>
157199
<groupId>org.hibernate.orm.tooling</groupId>
158200
<artifactId>hibernate-enhance-maven-plugin</artifactId>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<assembly>
2+
<id>deployment</id>
3+
<formats>
4+
<format>zip</format>
5+
</formats>
6+
<includeBaseDirectory>false</includeBaseDirectory>
7+
<fileSets>
8+
<!-- Copy the main JAR to root of ZIP -->
9+
<fileSet>
10+
<directory>${project.build.directory}</directory>
11+
<includes>
12+
<include>${project.build.finalName}.jar</include>
13+
</includes>
14+
<outputDirectory>.</outputDirectory>
15+
<fileMode>755</fileMode>
16+
</fileSet>
17+
<!-- Copy dependencies to app/libs in ZIP -->
18+
<fileSet>
19+
<directory>${project.build.directory}/libs</directory>
20+
<outputDirectory>app/libs</outputDirectory>
21+
<fileMode>644</fileMode>
22+
</fileSet>
23+
</fileSets>
24+
</assembly>

0 commit comments

Comments
 (0)