@@ -36,20 +36,29 @@ RUN jdeps \
3636 extracted/application/BOOT-INF/classes > modules.txt
3737
3838# Erzeuge das Custom JRE
39- # --compress zip-9 ist der moderne Ersatz für --compress=2
39+ # strip-debug -> keine Local Variable Tables, Line Number Tables, Native Debug Symbols
40+ # strip-native-commands -> kein keytool, rmiregistry, jdb, jhsdb, serialver - breaker!
41+ # compress zip-9 ist der moderne Ersatz für --compress=2
4042# NoClassDefFoundError: java.beans.PropertyEditorSupport -> java.desktop
4143# jmx, metrics -> java.management
44+ # GC notifications will not be available -> jdk.management
4245# load jar files (swagger) -> jdk.zipfs
4346# needs jlink -> java.instrument
4447# jpa needs java.sql.Date -> java.sql
4548# jetty jndi config -> java.naming
4649# jdk25 warnings -> sun.misc.Unsafe, das von Objenesis/CGLIB -> jdk.unsupported
50+ # org.ietf.jgss.GSSException -> java.security.jgss, java.security.sasl
51+ # Generational ZGC (Z Garbage Collector) setzen
52+ # ExitOnOutOfMemoryError OOM killt den Thread und die JVM beenden.
53+ # UTF-8 only String handling
4754RUN $JAVA_HOME/bin/jlink \
48- --add-modules $(cat modules.txt),jdk.crypto.ec,jdk.charsets,java.desktop,java.management,jdk.zipfs,java.instrument,java.sql,java.naming,jdk.unsupported \
55+ --module-path /usr/lib/jvm/java-25/jmods \
56+ --add-modules java.base,$(cat modules.txt),jdk.crypto.ec,jdk.charsets,java.desktop,java.management,jdk.management,jdk.zipfs,java.instrument,java.sql,java.naming,jdk.unsupported,java.security.jgss,java.security.sasl \
4957 --strip-debug \
5058 --no-man-pages \
5159 --no-header-files \
5260 --compress zip-9 \
61+ --add-options "-XX:+UseZGC -XX:+ExitOnOutOfMemoryError -Dfile.encoding=UTF-8" \
5362 --output /custom-jre
5463
5564# Erzeuge die Klassenliste für AppCDS
@@ -76,7 +85,8 @@ RUN /custom-jre/bin/java -XX:ArchiveClassesAtExit=app.jsa \
7685# 3. Runtime Stage (Minimales OS)
7786# ============================
7887# Wir nutzen hier ubi9-minimal statt der vollen Java-Runtime
79- FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
88+ #FROM registry.access.redhat.com/ubi9/ubi-minimal:latest
89+ FROM gcr.io/distroless/cc
8090
8191LABEL org.opencontainers.image.title="Java http client with Custom JRE" \
8292 org.opencontainers.image.version="0.0.1-SNAPSHOT"
@@ -87,28 +97,28 @@ WORKDIR /app
8797COPY --from=build /custom-jre /opt/jre
8898ENV PATH="/opt/jre/bin:$PATH"
8999
90- # User-Setup (UBI-Minimal braucht oft manuelles ID-Handling)
91- # curl-minial for healthcheck
92- RUN microdnf install -y shadow-utils curl-minimal && \
93- groupadd -r appgroup -g 185 && \
94- useradd -r -u 185 -g appgroup -d /app -s /sbin/nologin appuser && \
95- mkdir -p /app/config /app/data && \
96- chown -R 185:185 /app && \
97- microdnf clean all
98-
99- USER 185
100+ USER nonroot
100101
101102# Layer kopieren (wie gehabt)
102- COPY --from=build --chown=185:185 /app/extracted/dependencies/ ./
103- COPY --from=build --chown=185:185 /app/extracted/spring-boot-loader/ ./
104- COPY --from=build --chown=185:185 /app/extracted/snapshot-dependencies/ ./
105- COPY --from=build --chown=185:185 /app/extracted/application/ ./
106- COPY --from=build --chown=185:185 /app/app.jsa /app/app.jsa
107- COPY --chown=185:185 containerconfig/application.properties /app/config/application.properties
108- COPY --chown=185:185 entrypoint.sh /app/entrypoint.sh
103+ COPY --from=build --chown=65532:65532 /app/extracted/dependencies/ ./
104+ COPY --from=build --chown=65532:65532 /app/extracted/spring-boot-loader/ ./
105+ COPY --from=build --chown=65532:65532 /app/extracted/snapshot-dependencies/ ./
106+ COPY --from=build --chown=65532:65532 /app/extracted/application/ ./
107+ COPY --from=build --chown=65532:65532 /app/app.jsa /app/app.jsa
108+ COPY --chown=65532:65532 containerconfig/application.properties /app/config/application.properties
109109
110110EXPOSE 8080
111- HEALTHCHECK --interval=30s --timeout=3s \
112- CMD curl -f http://localhost:8080/actuator/health || exit 1
113111
114- ENTRYPOINT ["/app/entrypoint.sh"]
112+ #ENTRYPOINT ["/app/entrypoint.sh"]
113+ ENTRYPOINT [ \
114+ "/opt/jre/bin/java", \
115+ "-XX:SharedArchiveFile=/app/app.jsa", \
116+ "-Dspring.aot.enabled=true", \
117+ "-Djava.security.egd=file:/dev/./urandom", \
118+ "-XX:MaxRAMPercentage=80", \
119+ "-XX:InitialRAMPercentage=40", \
120+ "-XX:+UseZGC", \
121+ "-XX:+ExitOnOutOfMemoryError", \
122+ "org.springframework.boot.loader.launch.JarLauncher", \
123+ "--spring.config.location=file:/app/config/application.properties" \
124+ ]
0 commit comments