Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Helidon SE: use jlink to create minimal Java 11 runtime #130

Closed
barchetta opened this issue Oct 26, 2018 · 6 comments
Closed

Helidon SE: use jlink to create minimal Java 11 runtime #130

barchetta opened this issue Oct 26, 2018 · 6 comments
Assignees
Labels
task To do

Comments

@barchetta
Copy link
Member

barchetta commented Oct 26, 2018

Environment Details

  • Helidon Version: 0.10.4
  • Helidon SE
  • JDK version: 11

Problem Description

We should determine the minimum set of modules needed to run a Helidon SE application and document it. Also, we should consider updating our quickstart Dockerfile to generate the JRE as part of a two stage docker build.

I did a quick experimentation and this seems to work, but I did not exercise very many code paths:

$JAVA_HOME/bin/jlink --compress=2 --output jre --add-modules java.base,java.logging,java.sql,java.desktop,java.management
@barchetta barchetta added the task To do label Oct 26, 2018
@barchetta barchetta self-assigned this Nov 1, 2018
@barchetta
Copy link
Member Author

barchetta commented Nov 1, 2018

Here are some examples of dependencies on modules of interest:

java.desktop: java/beans/IntrospectionException (org.yaml.snakeyaml)
java.sql: java/sql/Date (org.yaml.snakeyaml)
java.management: java/lang/management/ManagementFactory (io.helidon.metrics.BaseRegistry)

@barchetta
Copy link
Member Author

barchetta commented Nov 1, 2018

Example Dockerfile to generate image with custom JRE:

# Multistage docker build.
# Stage 1: Build custom Java 11 JRE and put it in /var/tmp/myjre
FROM openjdk:11-slim AS build
RUN ["jlink", "--compress=2", \
     "--add-modules", "java.base,java.logging,java.sql,java.desktop,java.management", \
     "--output", "/var/tmp/myjre"]

# Stage 2: Build application image using JRE from Stage 1
FROM debian:sid-slim
COPY --from=build /var/tmp/myjre /opt/jre
ENV PATH=$PATH:/opt/jre/bin

RUN mkdir /app
COPY libs /app/libs
COPY ${project.artifactId}.jar /app

CMD ["java", "-jar", "/app/${project.artifactId}.jar"]

@ljnelson
Copy link
Member

ljnelson commented Nov 2, 2018

Yep; more stuff than you think pulls in java.desktop for the Java beans features.

Haven’t thought deeply about this but if we put together some kind of configuration in the sample app that does not use YAML etc. we might be able to use requires static or something similar to sever a branch off the dependency tree.

@barchetta
Copy link
Member Author

Ack! Because of bug docker-library/openjdk#217 the above approach results in a docker image size >500MB. Need to look for a work-around.

@barchetta
Copy link
Member Author

The work-around for the bloated libjvm.so is to strip it. Ick:

RUN [ "apt", "update"]
RUN [ "apt-get", "install", "-y", "binutils"]
RUN ["strip", "-p", "--strip-unneeded", "/var/tmp/myjre/lib/server/libjvm.so"]

@barchetta
Copy link
Member Author

This is being documented in PR #182

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task To do
Projects
None yet
Development

No branches or pull requests

2 participants