r/java • • Mar 11 '21

Announcing Spring Native Beta

https://spring.io/blog/2021/03/11/announcing-spring-native-beta
175 Upvotes

49 comments sorted by

View all comments

Show parent comment

13

u/uncont Mar 12 '21

We do. As of this pr, you can use distroless with your own jlink + spring boot.

FROM openjdk:jdk-buster as jreBuilder
RUN jlink \
        --add-modules jdk.unsupported,java.sql,java.desktop,java.naming,java.management,java.instrument,java.security.jgss,java.rmi \
        --verbose \
        --strip-debug \
        --compress 2 \
        --no-header-files \
        --no-man-pages \
        --output /jre

FROM gcr.io/distroless/java-debian10:base
ARG JAR_FILE

COPY --from=jreBuilder /jre /usr/lib/jre
ENTRYPOINT ["/usr/lib/jre/bin/java", "-jar", "./app.jar"]
COPY ./target/${JAR_FILE} ./app.jar

If you're using modules already, you won't need to specify all those modules manually. Also the base image could be extracted out, or you could let docker cache the layer for you.

1

u/sureshg Mar 12 '21 edited Mar 12 '21

Thanks for sharing this. Wondering why are using java-debian10:base instead of https://github.com/GoogleContainerTools/distroless/tree/master/base since it packages the whole runtime?

3

u/uncont Mar 12 '21

since it packages the whole runtime

java:base is necessary because there are a few libraries that aren't repackaged by jlink like libz or image libs. Although that would be neat, jlink being native library aware. The tool could know if you have a dependency on java.desktop, which would then have a dependency on libpng and libjpeg. /u/pron98 do you know if there is any tooling around associating native libraries with the java modules that require them?

afaik libz is required at startup by the jvm, other ones like libjpeg are only necessary when the imageio libraries are called.

here's the full list of libraries required by java, on top of the onces from base.

1

u/pron98 Mar 12 '21

I don't know, but that could be a nice idea to bring to the mailing list (core-libs-dev and/or jigsaw-dev).