Skip to content

Commit 07884f1

Browse files
author
wlanboy
committed
Add .dockerignore and update Dockerfiles for improved build process and layer caching
1 parent 58045ca commit 07884f1

File tree

4 files changed

+52
-10
lines changed

4 files changed

+52
-10
lines changed

.dockerignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Maven build output
2+
target/
3+
4+
# IDE & OS
5+
.idea/
6+
.vscode/
7+
*.iml
8+
.DS_Store
9+
Thumbs.db
10+
11+
# Git
12+
.git/
13+
.gitignore
14+
15+
# Docker
16+
.dockerignore
17+
Dockerfile*
18+
19+
# Docs & screenshots
20+
README.md
21+
layers.md
22+
screenshots/
23+
24+
# Helm chart (not needed in image)
25+
javahttpclient-chart/
26+
27+
# Scripts (not needed in image)
28+
multiarch-build.sh
29+
30+
# Local config (wird via containerconfig/ eingebunden)
31+
application.properties

Dockerfile

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RUN --mount=type=cache,target=/root/.m2 mvn -q -DskipTests compile spring-boot:p
2828
# → package: Baut das finale JAR inkl. AOT-Klassen.
2929
# → Wieder mit Maven-Cache, um Build-Zeit zu sparen.
3030

31-
RUN cp target/javahttpclient-0.0.1-SNAPSHOT.jar app.jar && \
31+
RUN cp target/*.jar app.jar && \
3232
java -Djarmode=tools -jar app.jar extract --layers --launcher --destination extracted
3333
# → Spring Boot 4.x Layertools: --launcher ist erforderlich um den Loader zu extrahieren
3434
# → Extrahierte Layer:
@@ -38,6 +38,12 @@ RUN cp target/javahttpclient-0.0.1-SNAPSHOT.jar app.jar && \
3838
# - application (BOOT-INF/classes)
3939
# → Vorteil: Docker kann diese Layer getrennt cachen → schnellere Deployments.
4040

41+
RUN java -XX:ArchiveClassesAtExit=app.jsa \
42+
-Dspring.context.exit=onRefresh \
43+
-Dspring.aot.enabled=true \
44+
-cp "extracted/dependencies/*:extracted/observability-dependencies/*:extracted/snapshot-dependencies/*:extracted/application/" \
45+
org.springframework.boot.loader.launch.JarLauncher || [ -f app.jsa ]
46+
4147
# ============================
4248
# 2. Runtime Stage (Java 25)
4349
# ============================
@@ -80,6 +86,8 @@ COPY --from=build --chown=185:185 /app/extracted/application-resources/ ./
8086
COPY --from=build --chown=185:185 /app/extracted/application/ ./
8187
# → Der eigentliche Applikationscode (Kompilat). Ändert sich.
8288

89+
COPY --from=build --chown=185:185 /app/app.jsa /app/app.jsa
90+
8391
COPY --chown=185:185 containerconfig/application.properties /app/config/application.properties
8492
# → Externe Konfiguration ins Config-Verzeichnis für die Referenz für ENV Vars
8593

Dockerfile25

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ RUN --mount=type=cache,target=/root/.m2 mvn -q -DskipTests compile spring-boot:p
2828
# → package: Baut das finale JAR inkl. AOT-Klassen.
2929
# → Wieder mit Maven-Cache, um Build-Zeit zu sparen.
3030

31-
RUN cp target/javahttpclient-0.0.1-SNAPSHOT.jar app.jar && \
31+
RUN cp target/*.jar app.jar && \
3232
java -Djarmode=tools -jar app.jar extract --layers --launcher --destination extracted
3333
# → Spring Boot 4.x Layertools: --launcher ist erforderlich um den Loader zu extrahieren
3434
# → Extrahierte Layer:
@@ -38,6 +38,12 @@ RUN cp target/javahttpclient-0.0.1-SNAPSHOT.jar app.jar && \
3838
# - application (BOOT-INF/classes)
3939
# → Vorteil: Docker kann diese Layer getrennt cachen → schnellere Deployments.
4040

41+
RUN java -XX:ArchiveClassesAtExit=app.jsa \
42+
-Dspring.context.exit=onRefresh \
43+
-Dspring.aot.enabled=true \
44+
-cp "extracted/dependencies/*:extracted/observability-dependencies/*:extracted/snapshot-dependencies/*:extracted/application/" \
45+
org.springframework.boot.loader.launch.JarLauncher || [ -f app.jsa ]
46+
4147
# ============================
4248
# 2. Runtime Stage (Java 25)
4349
# ============================
@@ -80,6 +86,8 @@ COPY --from=build --chown=185:185 /app/extracted/application-resources/ ./
8086
COPY --from=build --chown=185:185 /app/extracted/application/ ./
8187
# → Der eigentliche Applikationscode (Kompilat). Ändert sich.
8288

89+
COPY --from=build --chown=185:185 /app/app.jsa /app/app.jsa
90+
8391
COPY --chown=185:185 containerconfig/application.properties /app/config/application.properties
8492
# → Externe Konfiguration ins Config-Verzeichnis für die Referenz für ENV Vars
8593

Dockerfile25Jlink

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,9 @@ RUN $JAVA_HOME/bin/jlink \
6262
--no-man-pages \
6363
--no-header-files \
6464
--compress zip-9 \
65-
--add-options "-XX:+UseZGC -XX:+ExitOnOutOfMemoryError -Dfile.encoding=UTF-8" \
65+
--add-options "-XX:+UseZGC -XX:+ExitOnOutOfMemoryError -Dfile.encoding=UTF-8" \
6666
--output /custom-jre
6767

68-
# Erzeuge die Klassenliste für AppCDS
69-
RUN /custom-jre/bin/java -Djarmode=tools -jar app.jar extract --layers --destination cds-extraction
70-
7168
# Erzeugt das Basis-Archiv für das Custom JRE
7269
RUN /custom-jre/bin/java -Xshare:dump
7370

@@ -82,8 +79,8 @@ RUN /custom-jre/bin/java -XX:ArchiveClassesAtExit=app.jsa \
8279
-Dspring.aot.enabled=true \
8380
-cp "extracted/dependencies/*:extracted/observability-dependencies/*:extracted/snapshot-dependencies/*:extracted/application/" \
8481
org.springframework.boot.loader.launch.JarLauncher || [ -f app.jsa ]
85-
# Hinweis: Das "|| true" ist wichtig, da die App beim Training mangels DB/Config evtl. abbricht,
86-
# aber das Archiv trotzdem schreibt.
82+
# Hinweis: "|| [ -f app.jsa ]" erlaubt einen Non-Zero Exit (z.B. fehlende DB/Config),
83+
# solange das Archiv trotzdem geschrieben wurde. Fehlt app.jsa, bricht der Build ab.
8784

8885
# ============================
8986
# 3. Runtime Stage (Minimales OS)
@@ -125,8 +122,6 @@ ENTRYPOINT [ \
125122
"-Djava.security.egd=file:/dev/./urandom", \
126123
"-XX:MaxRAMPercentage=80", \
127124
"-XX:InitialRAMPercentage=40", \
128-
"-XX:+UseZGC", \
129-
"-XX:+ExitOnOutOfMemoryError", \
130125
"org.springframework.boot.loader.launch.JarLauncher", \
131126
"--spring.config.location=file:/app/config/application.properties" \
132127
]

0 commit comments

Comments
 (0)