fabric8io-images / s2i

OpenShift S2I images for Java and Karaf applications
Apache License 2.0
70 stars 84 forks source link

Smaller JDK base image using Java 11 modularity (jlink) #181

Open vorburger opened 5 years ago

vorburger commented 5 years ago

once and after we'll have #160, then I think the idea also in raised #180 by @gunnarmorling re. a modular small JDK base image (jlink) is worth a dedicated issue ... let's discuss this further and some day implement under this issue? -- One of the points to IMHO clarify is:

  1. Could we just settle on a suitable list of JDK modules to hard code into the Java S2I base image (e.g. like what @gunnarmorling has done over here) ? Like obviously no UI stuff, and ditch really old and in practice un-used modules in modern server side containerized Java apps.

  2. Or is this an illusion and there would have to have some (complicated...) mechanism to chose modules, and have a multi-stage build, for JDK and application? (Urgh, with S2I.)

  3. May be a middle way and a (hopefully small) set of pre-baked S2I Java 11 image types with different JDK modules?

gunnarmorling commented 5 years ago

I think it'll be hard to define meaningful ready-made subsets, likely it will always be too little or too much for chosen applications. The modules to include should be determined by the specific build itself. In the example I built I used a hard-coded list I head determined upfront, but this can easily be automated by running the jdeps tool against all the JARs to be included:

jdeps --print-module-deps --class-path ...

The reason why I didn't do it is that jdeps works with JARs as input, i.e. it can only be run after the application JAR has been created. So this won't benefit from caching, if the application changes, also if the change doesn't lead to the inclusion of more modules.

vorburger commented 5 years ago

From @gunnarmorling comment over in #160 (which I want to keep focused on Java 11 itself):

Btw. the current OpenJDK 11 package on Fedora gives very bad results with jlink modular runtime images (huge size due to debug symbols), so I'd advise against using it).

This could be looked more into here and discussed with our OpenJDK friends when this gets picked up.

vorburger commented 5 years ago

@gunnarmorling following up on a possible first step in the direction of this issue, and based on your comments on the original Java 11 PR over here re. java-11-openjdk-jmods ("I realized that for using jlink another package must be installed: java-11-openjdk-jmods. This brings in the jmod files with the JDK modules that are used by jlink to produce the modular runtime images."), do you think the base image should include this java-11-openjdk-jmods package? I'm proposing this in #198 for review & discussion...

vorburger commented 5 years ago

https://bugzilla.redhat.com/show_bug.cgi?id=1652177

vorburger commented 5 years ago

198 just merged, but that's just the basic pre-req, there is more work here how to actually use this...

198 has a very nice simple standalone example how to use jlink (thanks @gunnarmorling)

Perhaps https://maven.apache.org/plugins/maven-jlink-plugin/ could be of use for this as well?

vorburger commented 5 years ago

Actually to prepare #203, I just reverted the #198 again; with this, latest-java11 is down from 489 MB to 166 MB.