Skip to content

Commit 3b9787e

Browse files
committed
Initial implementation of hooking the JLink scripts into the S2I
process. Resolves OPENJDK-2179, OPENJDK-2180
1 parent e28d02d commit 3b9787e

File tree

4 files changed

+57
-0
lines changed

4 files changed

+57
-0
lines changed

modules/s2i/bash/artifacts/usr/local/s2i/assemble

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,52 @@ source "${JBOSS_CONTAINER_JAVA_S2I_MODULE}/maven-s2i-overrides"
1414
# invoke the build
1515
maven_s2i_build
1616

17+
#TODO: Clean this up to call the scripts instead
18+
19+
shopt -s globstar
20+
echo "Setting environment variables"
21+
jarfile="/deployments/*.jar"
22+
libdir="/deployments/lib"
23+
$JAVA_HOME/
24+
25+
echo "Checking that jarfile and libdir exist"
26+
test -f "$jarfile"
27+
test -d "$libdir"
28+
29+
# Create a temporary directory for a module path
30+
mkdir dependencies
31+
cp /deployments/lib/**/*.jar dependencies
32+
# Calculate dependencies
33+
$JAVA_HOME/bin/jdeps --module-path dependencies --ignore-missing-deps --multi-release 11 -R -s \
34+
"$jarfile" \
35+
"$libdir"/**/*.jar \
36+
> deps.txt
37+
# Clean up temporary directory
38+
rm -rf dependencies
39+
40+
# Strip down the dependencies to the ones we're looking for
41+
<deps.txt \
42+
grep 'java\|jdk\.' | # mostly removes target/, but also jdk8internals
43+
sed -E "s/Warning: .*//" | #remove extraneous warnings
44+
sed -E "s/.*-> //" | # remove src of src -> dep
45+
sed -E "s/.*\.jar//" | # remove extraneous dependencies
46+
sed "s#/.*##" | # delete anything after a slash. in practice target/..
47+
sort | uniq |
48+
tee stripped-deps.txt
49+
50+
echo "Checking against jdk modules"
51+
$JAVA_HOME/bin/java --list-modules > java-modules.txt
52+
cat java-modules.txt | sed "s/\\@.*//" > modules.txt
53+
grep -Fx -f stripped-deps.txt modules.txt | tr '\n' ',' | tr -d "[:space:]" > module-deps.txt
54+
echo "jdk.zipfs" >> module-deps.txt
55+
56+
echo "Linking jre"
57+
$JAVA_HOME/bin/jlink --output runtime-jre \
58+
--add-modules $(cat module-deps.txt) \
59+
-G --no-header-files --no-man-pages
60+
61+
rm *.txt
62+
echo "Repacking jre"
63+
INSTALL_BASE="/lib/jvm/java-11-openjdk"
64+
JDK_IMAGE="runtime-jre"
65+
echo -n "Replacing shared libraries from JDK image '$JDK_IMAGE' with shared libraries from '$INSTALL_BASE'... "

modules/s2i/bash/module.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ modules:
1515
- name: jboss.container.maven.s2i
1616
- name: jboss.container.java.run
1717
- name: jboss.container.util.logging
18+
- name: jboss.container.java.jlink
1819

1920
packages:
2021
install:

modules/s2i/core/artifacts/opt/jboss/container/s2i/core/s2i-core

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ function s2i_core_env_init() {
3333
S2I_IMAGE_SOURCE_MOUNTS="${S2I_IMAGE_SOURCE_MOUNTS:-${CUSTOM_INSTALL_DIRECTORIES}}"
3434
S2I_ENABLE_INCREMENTAL_BUILDS="${S2I_ENABLE_INCREMENTAL_BUILDS:-true}"
3535
S2I_DELETE_SOURCE="${S2I_DELETE_SOURCE:-true}"
36+
S2I_ENABLE_JLINK="${S2I_ENABLE_JLINK:-true}"
3637
}
3738

3839
# extensions may override this method to initialize environment variables

modules/s2i/core/module.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ envs:
112112
Delete source files at the end of build. Defaults to true.
113113
example: "false"
114114

115+
- name: S2I_ENABLE_JLINK_WORKFLOW
116+
description: ^
117+
Enables the Jdeps/JLink workflow to minimize JRE size
118+
example: "false"
119+
value: false
120+
115121
run:
116122
cmd:
117123
- "/usr/local/s2i/run"

0 commit comments

Comments
 (0)