salesforce / rules_spring

Bazel rule for building Spring Boot apps as a deployable jar
BSD 3-Clause "New" or "Revised" License
224 stars 48 forks source link

Create a minified application JRE using jlink #96

Open plaird opened 3 years ago

plaird commented 3 years ago

This could be a good middle ground between our current standard deployment artifact, and the GraalVM/SpringNative optimized executable (see #93). This would be an optional add-on, perhaps as a distinct rule, something like:


springboot(name = 'glory_svc', ...)

springboot_jre(name = 'glory_svc_jre', springboot_app = ':glory_svc',...)

java_docker_image(name 'glory_docker', app = ':glory_svc', jdk = ':glory_svc_jre', ...)

With the JDK jlink tool, we should be able to produce a small JDK+app executable. In one published example, this reduced the size of the runnable jre from 286MB to 39MB. This works because the jre distro will only contain the Java platform modules that are needed to run the app, and not all the extra cruft (corba, rmi, etc) that are not.

https://medium.com/azulsystems/using-jlink-to-build-java-runtimes-for-non-modular-applications-9568c5e70ef4

There are a few examples of Spring Boot users getting this to work online, but all of them seemed to use manual methods. Because we have the full list of deps for the Spring Boot jar, we could invoke jdeps with high fidelity, and use that when invoking jlink.