Skip to content

Commit 032cc83

Browse files
authored
address SME review (#201)
* address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> * address SME review Signed-off-by: Gilbert Kwan <[email protected]> --------- Signed-off-by: Gilbert Kwan <[email protected]>
1 parent 1b3c129 commit 032cc83

File tree

7 files changed

+129
-13
lines changed

7 files changed

+129
-13
lines changed

README.adoc

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Learn how to containerize, package, and run a Spring Boot application on Open Li
2929

3030
== What you'll learn
3131

32-
The starting point of this guide is the finished application from the https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot^] guide. If you are not familiar with Spring Boot, complete that guide first. Java 17 is required to run this project.
32+
The starting point of this guide is the finished application from the https://spring.io/guides/gs/spring-boot/[Building an Application with Spring Boot^] guide. If you are not familiar with Spring Boot, complete that guide first. Java 21 is required to run this project.
3333

3434
You will learn how to use the `springBootUtility` command to deploy a Spring Boot application in Docker on Open Liberty without modification. This command stores the dependent library JAR files of the application to the target library cache, and packages the remaining application artifacts into a thin application JAR file.
3535

@@ -124,7 +124,7 @@ Navigate to the `start` directory.
124124
----
125125

126126
Dockerfile
127-
[source, Text, linenums, role='code_column']
127+
[source, Text, linenums, role='code_column']
128128
----
129129
include::finish/Dockerfile[]
130130
----
@@ -155,7 +155,7 @@ Your `springboot` image appears in the list of Docker images:
155155
[role='no_copy']
156156
```
157157
REPOSITORY TAG IMAGE ID CREATED SIZE
158-
springboot latest 3a5492c0cbeb 27 seconds ago 789MB
158+
springboot latest 3a5492c0cbeb 27 seconds ago 485MB
159159
```
160160

161161
Now, you can run the Spring Boot application in a Docker container:
@@ -175,7 +175,7 @@ You see an entry similar to the following example:
175175
[role='no_copy']
176176
----
177177
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
178-
e33532aa07d6 springboot "/opt/ibm/docker/doc…" 7 seconds ago Up 2 seconds 0.0.0.0:9080->9080/tcp, 0.0.0.0:9443->9443/tcp springBootContainer
178+
e33532aa07d6 springboot "/opt/ol/helpers/run…" 7 seconds ago Up 2 seconds 0.0.0.0:9080->9080/tcp, 0.0.0.0:9443->9443/tcp springBootContainer
179179
----
180180

181181
You can watch the application start by monitoring the logs:
@@ -187,6 +187,9 @@ docker logs springBootContainer
187187
Wait for the following message, which indicates that Liberty’s startup is complete in several seconds:
188188
[role='no_copy']
189189
----
190+
...
191+
CWWKZ0001I: Application thin-guide-spring-boot-0.1.0 started in 5.542 seconds.
192+
...
190193
CWWKF0011I: The defaultServer server is ready to run a smarter planet.
191194
The defaultServer server started in 7.121 seconds.
192195
----
@@ -224,7 +227,35 @@ If you are working on a Linux system with kernel version 5.9 or greater, you can
224227
uname -r
225228
```
226229

227-
You have built the `springboot` container image in the previous section. To take a checkpoint of the application process with the `afterAppStart` option, run the following command:
230+
The https://openliberty.io/docs/latest/reference/feature/crac.html[Coordinated Restore at Checkpoint^] feature enables Liberty to use the Liberty’s implementation of https://javadoc.io/doc/org.crac/crac/1.4.0/index.html[org.crac^] APIs and more logs from Spring when the application is restoring.
231+
232+
[role="code_command hotspot file=0", subs="quotes"]
233+
----
234+
#Replace the `Dockerfile` in the `start` directory.#
235+
`Dockerfile`
236+
----
237+
238+
Dockerfile
239+
[source, Text, linenums, role='code_column']
240+
----
241+
include::instantOn/Dockerfile[]
242+
----
243+
244+
crac.xml
245+
[source, xml, linenums, role='code_column']
246+
----
247+
include::finish/src/main/liberty/instantOn/crac.xml[]
248+
----
249+
250+
Copy the provided [hotspot=cracXml file=0]`crac.xml` configuration file to the Liberty `configDropins` configuration directory. The crac.xml file enables the [hotspot=crac file=1]`crac` feature to the Liberty instance.
251+
252+
Run the following command to rebuild the Docker image:
253+
[role='command']
254+
```
255+
docker build -t springboot .
256+
```
257+
258+
To take a checkpoint of the application process with the `afterAppStart` option, run the following command:
228259

229260
[role='command']
230261
```
@@ -256,9 +287,9 @@ Your `springboot-instanton` image appears in the list of Docker images. It shows
256287

257288
[role='no_copy']
258289
```
259-
REPOSITORY TAG IMAGE ID CREATED SIZE
260-
springboot-instanton latest c4aabcdd64bf 20 seconds ago 879MB
261-
springboot latest 3a5492c0cbeb 14 minutes ago 789MB
290+
REPOSITORY TAG IMAGE ID CREATED SIZE
291+
springboot-instanton latest c4aabcdd64bf 20 seconds ago 577MB
292+
springboot latest 3a5492c0cbeb 14 minutes ago 485MB
262293
```
263294

264295
Run the `springboot-instanton` InstantOn application image by the following command:
@@ -282,10 +313,17 @@ Run the following command to see the container logs:
282313
docker logs springBootContainer
283314
```
284315

285-
Liberty’s startup is complete in less than a second:
316+
You see more logs from Spring for restoring. Liberty’s startup is complete in less than a second:
286317

287318
[role='no_copy']
288319
----
320+
2024-11-22T16:33:43.349Z INFO 1027 --- [ecutor-thread-1] o.s.c.support.DefaultLifecycleProcessor : Restarting Spring-managed lifecycle beans after JVM restore
321+
...
322+
2024-11-22T16:33:43.562Z INFO 1027 --- [ecutor-thread-1] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 135784 ms
323+
2024-11-22T16:33:43.568Z INFO 1027 --- [ecutor-thread-1] o.s.c.support.DefaultLifecycleProcessor : Spring-managed lifecycle restart completed (restored JVM running for 525 ms)
324+
...
325+
CWWKZ0001I: Application thin-guide-spring-boot-0.1.0 started in 0.585 seconds.
326+
...
289327
CWWKF0011I: The defaultServer server is ready to run a smarter planet.
290328
The defaultServer server started in 0.323 seconds.
291329
----
@@ -299,6 +337,8 @@ After you are finished checking out the application, stop your container by runn
299337
docker stop springBootContainer
300338
```
301339

340+
If you use Podman instead of Docker, you can build your InstantOn image in a simply way. Read the https://openliberty.io/docs/latest/instanton.html#checkpoint_script[Building the InstantOn image with Podman and the checkpoint.sh script^] documentation.
341+
302342
To learn more about the Liberty InstantOn feature, see the https://openliberty.io/docs/latest/instanton.html[Faster startup for containerized applications with Open Liberty InstantOn^] documentation.
303343

304344
endif::[]

finish/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Stage and thin the application
22
# tag::OLimage1[]
3-
FROM icr.io/appcafe/open-liberty:full-java17-openj9-ubi as staging
3+
FROM icr.io/appcafe/open-liberty:full-java21-openj9-ubi-minimal as staging
44
# end::OLimage1[]
55

66
# tag::copyJar[]
@@ -17,7 +17,7 @@ RUN springBootUtility thin \
1717

1818
# Build the image
1919
# tag::OLimage2[]
20-
FROM icr.io/appcafe/open-liberty:kernel-slim-java17-openj9-ubi
20+
FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal
2121
# end::OLimage2[]
2222

2323
ARG VERSION=1.0

finish/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description>Demo project for Spring Boot</description>
1616

1717
<properties>
18-
<java.version>17</java.version>
18+
<java.version>21</java.version>
1919
</properties>
2020

2121
<dependencies>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<server description="Enable the org.crac API">
3+
4+
<featureManager>
5+
<!-- tag::crac[] -->
6+
<feature>crac-1.4</feature>
7+
<!-- end::crac[] -->
8+
</featureManager>
9+
10+
</server>

instantOn/Dockerfile

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# Stage and thin the application
2+
# tag::OLimage1[]
3+
FROM icr.io/appcafe/open-liberty:full-java21-openj9-ubi-minimal as staging
4+
# end::OLimage1[]
5+
6+
# tag::copyJar[]
7+
COPY --chown=1001:0 target/guide-spring-boot-0.1.0.jar \
8+
/staging/fat-guide-spring-boot-0.1.0.jar
9+
# end::copyJar[]
10+
11+
# tag::springBootUtility[]
12+
RUN springBootUtility thin \
13+
--sourceAppPath=/staging/fat-guide-spring-boot-0.1.0.jar \
14+
--targetThinAppPath=/staging/thin-guide-spring-boot-0.1.0.jar \
15+
--targetLibCachePath=/staging/lib.index.cache
16+
# end::springBootUtility[]
17+
18+
# Build the image
19+
# tag::OLimage2[]
20+
FROM icr.io/appcafe/open-liberty:kernel-slim-java21-openj9-ubi-minimal
21+
# end::OLimage2[]
22+
23+
ARG VERSION=1.0
24+
ARG REVISION=SNAPSHOT
25+
26+
LABEL \
27+
org.opencontainers.image.authors="Your Name" \
28+
org.opencontainers.image.vendor="Open Liberty" \
29+
org.opencontainers.image.url="local" \
30+
org.opencontainers.image.source="https://github.com/OpenLiberty/guide-spring-boot" \
31+
org.opencontainers.image.version="$VERSION" \
32+
org.opencontainers.image.revision="$REVISION" \
33+
vendor="Open Liberty" \
34+
name="hello app" \
35+
version="$VERSION-$REVISION" \
36+
summary="The hello application from the Spring Boot guide" \
37+
description="This image contains the hello application running with the Open Liberty runtime."
38+
39+
# tag::serverXml[]
40+
RUN cp /opt/ol/wlp/templates/servers/springBoot3/server.xml /config/server.xml
41+
# end::serverXml[]
42+
43+
# tag::cracXml[]
44+
COPY --chown=1001:0 src/main/liberty/instantOn/crac.xml \
45+
/config/configDropins/defaults/crac.xml
46+
# end::cracXml[]
47+
48+
RUN features.sh
49+
50+
# tag::libcache[]
51+
COPY --chown=1001:0 --from=staging /staging/lib.index.cache /lib.index.cache
52+
# end::libcache[]
53+
# tag::thinjar[]
54+
COPY --chown=1001:0 --from=staging /staging/thin-guide-spring-boot-0.1.0.jar \
55+
/config/dropins/spring/thin-guide-spring-boot-0.1.0.jar
56+
# end::thinjar[]
57+
58+
RUN configure.sh

start/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<description>Demo project for Spring Boot</description>
1616

1717
<properties>
18-
<java.version>17</java.version>
18+
<java.version>21</java.version>
1919
</properties>
2020

2121
<dependencies>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<server description="Enable the org.crac API">
3+
4+
<featureManager>
5+
<feature>crac-1.4</feature>
6+
</featureManager>
7+
8+
</server>

0 commit comments

Comments
 (0)