Skip to content

Commit 7b2761a

Browse files
committed
feat: create initial helidon project
Signed-off-by: Otavio Santana <[email protected]>
1 parent 49c5cfd commit 7b2761a

File tree

22 files changed

+837
-11
lines changed

22 files changed

+837
-11
lines changed

.dockerignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
target/*

.gitignore

+23-11
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
# Compiled class file
22
*.class
33

4-
# Log file
5-
*.log
6-
7-
# BlueJ files
8-
*.ctxt
9-
10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
4+
# Maven
5+
target/
6+
.m2/
127

138
# Package Files #
149
*.jar
@@ -19,6 +14,23 @@
1914
*.tar.gz
2015
*.rar
2116

22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
24-
replay_pid*
17+
# IntelliJ Idea
18+
.idea/*
19+
!.idea/runConfigurations
20+
*.iws
21+
*.ipr
22+
*.iml
23+
*.releaseBackup
24+
atlassian-ide-plugin.xml
25+
26+
# Netbeans
27+
nbactions.xml
28+
nb-configuration.xml
29+
30+
# Eclipse
31+
.settings
32+
.settings/
33+
.project
34+
.classpath
35+
.factorypath
36+

.helidon

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Helidon Project Configuration
2+
#Wed Dec 11 07:33:16 UTC 2024
3+
schema.version=1.1.0
4+
helidon.version=4.1.4
5+
project.flavor=mp
6+
project.archetype=quickstart

.idea/runConfigurations/configuration.xml

+9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Dockerfile

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# 1st stage, build the app
3+
FROM container-registry.oracle.com/java/jdk-no-fee-term:21 as build
4+
5+
# Install maven
6+
WORKDIR /usr/share
7+
RUN set -x && \
8+
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 && \
10+
rm apache-maven-*-bin.tar.gz && \
11+
mv apache-maven-* maven && \
12+
ln -s /usr/share/maven/bin/mvn /bin/
13+
14+
WORKDIR /helidon
15+
16+
# 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
19+
ADD pom.xml .
20+
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip -Declipselink.weave.skip -DskipOpenApiGenerate
21+
22+
# Do the Maven build!
23+
# Incremental docker builds will resume here when you change sources
24+
ADD src src
25+
RUN mvn package -DskipTests
26+
27+
RUN echo "done!"
28+
29+
# 2nd stage, build the runtime image
30+
FROM container-registry.oracle.com/java/jdk-no-fee-term:21
31+
WORKDIR /helidon
32+
33+
# Copy the binary built in the 1st stage
34+
COPY --from=build /helidon/target/embedded-mongodb.jar ./
35+
COPY --from=build /helidon/target/libs ./libs
36+
37+
CMD ["java", "-jar", "embedded-mongodb.jar"]
38+
39+
EXPOSE 8080

Dockerfile.jlink

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
# 1st stage, build the app
3+
FROM container-registry.oracle.com/java/jdk-no-fee-term:21 as build
4+
5+
WORKDIR /usr/share
6+
7+
# Install maven
8+
RUN set -x && \
9+
curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \
10+
tar -xvf apache-maven-*-bin.tar.gz && \
11+
rm apache-maven-*-bin.tar.gz && \
12+
mv apache-maven-* maven && \
13+
ln -s /usr/share/maven/bin/mvn /bin/
14+
15+
WORKDIR /helidon
16+
17+
# Create a first layer to cache the "Maven World" in the local repository.
18+
# Incremental docker builds will always resume after that, unless you update
19+
# the pom
20+
ADD pom.xml .
21+
RUN mvn package -Dmaven.test.skip -Declipselink.weave.skip
22+
23+
# Do the Maven build to create the custom Java Runtime Image
24+
# Incremental docker builds will resume here when you change sources
25+
ADD src src
26+
RUN mvn package -Pjlink-image -DskipTests
27+
RUN echo "done!"
28+
29+
# 2nd stage, build the final image with the JRI built in the 1st stage
30+
31+
FROM debian:stretch-slim
32+
WORKDIR /helidon
33+
COPY --from=build /helidon/target/embedded-mongodb-jri ./
34+
ENTRYPOINT ["/bin/bash", "/helidon/bin/start"]
35+
EXPOSE 8080

Dockerfile.native

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
2+
# 1st stage, build the app
3+
FROM ghcr.io/graalvm/graalvm-community:21.0.0-ol9 as build
4+
5+
WORKDIR /usr/share
6+
7+
# Install maven
8+
RUN set -x && \
9+
curl -O https://archive.apache.org/dist/maven/maven-3/3.8.4/binaries/apache-maven-3.8.4-bin.tar.gz && \
10+
tar -xvf apache-maven-*-bin.tar.gz && \
11+
rm apache-maven-*-bin.tar.gz && \
12+
mv apache-maven-* maven && \
13+
ln -s /usr/share/maven/bin/mvn /bin/
14+
15+
WORKDIR /helidon
16+
17+
# Create a first layer to cache the "Maven World" in the local repository.
18+
# Incremental docker builds will always resume after that, unless you update
19+
# the pom
20+
ADD pom.xml .
21+
RUN mvn package -Pnative-image -Dnative.image.skip -Dmaven.test.skip -Declipselink.weave.skip
22+
23+
# Do the Maven build!
24+
# Incremental docker builds will resume here when you change sources
25+
ADD src src
26+
RUN mvn package -Pnative-image -Dnative.image.buildStatic -DskipTests
27+
28+
RUN echo "done!"
29+
30+
# 2nd stage, build the runtime image
31+
FROM scratch
32+
WORKDIR /helidon
33+
34+
# Copy the binary built in the 1st stage
35+
COPY --from=build /helidon/target/embedded-mongodb .
36+
37+
ENTRYPOINT ["./embedded-mongodb"]
38+
39+
EXPOSE 8080

README.md

+158
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
# embedded-mongodb
2+
3+
Sample Helidon MP project that includes multiple REST operations.
4+
5+
## Build and run
6+
7+
8+
With JDK21
9+
```bash
10+
mvn package
11+
java -jar target/embedded-mongodb.jar
12+
```
13+
14+
## Exercise the application
15+
16+
Basic:
17+
```
18+
curl -X GET http://localhost:8080/simple-greet
19+
Hello World!
20+
```
21+
22+
23+
JSON:
24+
```
25+
curl -X GET http://localhost:8080/greet
26+
{"message":"Hello World!"}
27+
28+
curl -X GET http://localhost:8080/greet/Joe
29+
{"message":"Hello Joe!"}
30+
31+
curl -X PUT -H "Content-Type: application/json" -d '{"greeting" : "Hola"}' http://localhost:8080/greet/greeting
32+
33+
curl -X GET http://localhost:8080/greet/Jose
34+
{"message":"Hola Jose!"}
35+
```
36+
37+
38+
39+
## Try health
40+
41+
```
42+
curl -s -X GET http://localhost:8080/health
43+
{"outcome":"UP",...
44+
45+
```
46+
47+
48+
## Building a Native Image
49+
50+
The generation of native binaries requires an installation of GraalVM 22.1.0+.
51+
52+
You can build a native binary using Maven as follows:
53+
54+
```
55+
mvn -Pnative-image install -DskipTests
56+
```
57+
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+
63+
64+
65+
## Try metrics
66+
67+
```
68+
# Prometheus Format
69+
curl -s -X GET http://localhost:8080/metrics
70+
# TYPE base:gc_g1_young_generation_count gauge
71+
. . .
72+
73+
# JSON Format
74+
curl -H 'Accept: application/json' -X GET http://localhost:8080/metrics
75+
{"base":...
76+
. . .
77+
```
78+
79+
80+
81+
## Building the Docker Image
82+
83+
```
84+
docker build -t embedded-mongodb .
85+
```
86+
87+
## Running the Docker Image
88+
89+
```
90+
docker run --rm -p 8080:8080 embedded-mongodb:latest
91+
```
92+
93+
Exercise the application as described above.
94+
95+
96+
## Run the application in Kubernetes
97+
98+
If you don’t have access to a Kubernetes cluster, you can [install one](https://helidon.io/docs/latest/#/about/kubernetes) on your desktop.
99+
100+
### Verify connectivity to cluster
101+
102+
```
103+
kubectl cluster-info # Verify which cluster
104+
kubectl get pods # Verify connectivity to cluster
105+
```
106+
107+
### Deploy the application to Kubernetes
108+
109+
```
110+
kubectl create -f app.yaml # Deploy application
111+
kubectl get pods # Wait for quickstart pod to be RUNNING
112+
kubectl get service embedded-mongodb # Get service info
113+
kubectl port-forward service/embedded-mongodb 8081:8080 # Forward service port to 8081
114+
```
115+
116+
You can now exercise the application as you did before but use the port number 8081.
117+
118+
After you’re done, cleanup.
119+
120+
```
121+
kubectl delete -f app.yaml
122+
```
123+
124+
125+
## Building a Custom Runtime Image
126+
127+
Build the custom runtime image using the jlink image profile:
128+
129+
```
130+
mvn package -Pjlink-image
131+
```
132+
133+
This uses the helidon-maven-plugin to perform the custom image generation.
134+
After the build completes it will report some statistics about the build including the reduction in image size.
135+
136+
The target/embedded-mongodb-jri directory is a self contained custom image of your application. It contains your application,
137+
its runtime dependencies and the JDK modules it depends on. You can start your application using the provide start script:
138+
139+
```
140+
./target/embedded-mongodb-jri/bin/start
141+
```
142+
143+
Class Data Sharing (CDS) Archive
144+
Also included in the custom image is a Class Data Sharing (CDS) archive that improves your application’s startup
145+
performance and in-memory footprint. You can learn more about Class Data Sharing in the JDK documentation.
146+
147+
The CDS archive increases your image size to get these performance optimizations. It can be of significant size (tens of MB).
148+
The size of the CDS archive is reported at the end of the build output.
149+
150+
If you’d rather have a smaller image size (with a slightly increased startup time) you can skip the creation of the CDS
151+
archive by executing your build like this:
152+
153+
```
154+
mvn package -Pjlink-image -Djlink.image.addClassDataSharingArchive=false
155+
```
156+
157+
For more information on available configuration options see the helidon-maven-plugin documentation.
158+

app.yaml

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
kind: Service
2+
apiVersion: v1
3+
metadata:
4+
name: embedded-mongodb
5+
labels:
6+
app: embedded-mongodb
7+
spec:
8+
type: ClusterIP
9+
selector:
10+
app: embedded-mongodb
11+
ports:
12+
- name: tcp
13+
port: 8080
14+
protocol: TCP
15+
targetPort: 8080
16+
---
17+
kind: Deployment
18+
apiVersion: apps/v1
19+
metadata:
20+
name: embedded-mongodb
21+
spec:
22+
replicas: 1
23+
selector:
24+
matchLabels:
25+
app: embedded-mongodb
26+
template:
27+
metadata:
28+
labels:
29+
app: embedded-mongodb
30+
version: v1
31+
spec:
32+
containers:
33+
- name: embedded-mongodb
34+
image: embedded-mongodb
35+
imagePullPolicy: IfNotPresent
36+
ports:
37+
- containerPort: 8080

0 commit comments

Comments
 (0)