Skip to content

Commit eeb5629

Browse files
committed
Merge branch 'jlink-dev' into 4002-ubi10-merge-jlink
2 parents 397d0f4 + e4d595c commit eeb5629

File tree

32 files changed

+1379
-95
lines changed

32 files changed

+1379
-95
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/bin/bash
2+
3+
function generatejdkdeps() {
4+
echo "Generating JDK deps"
5+
$JAVA_HOME/bin/java --list-modules > $S2I_JLINK_TEMP_PATH/java-modules.txt
6+
< $S2I_JLINK_TEMP_PATH/java-modules.txt sed "s/\\@.*//" > $S2I_JLINK_TEMP_PATH/modules.txt
7+
grep -Fx -f $S2I_JLINK_TEMP_PATH/stripped-deps.txt $S2I_JLINK_TEMP_PATH/modules.txt | tr '\n' ',' | tr -d "[:space:]" > $S2I_JLINK_TEMP_PATH/module-deps.txt
8+
echo "jdk.zipfs" >> $S2I_JLINK_TEMP_PATH/module-deps.txt
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
shopt -s globstar
4+
5+
function generate_deps() {
6+
# Create a temporary directory for a module path
7+
# This works around "Module java.xml.bind not found, required by java.ws.rs"
8+
mkdir dependencies
9+
10+
if [[ -v JAVA_LIB_DIR ]]; then
11+
# Serially copy all library JARsinto a flat directory. Serially as we may
12+
# have multiple libs with the same name; in which case, we clobber all but
13+
# one rather than fail the script
14+
find $JAVA_LIB_DIR -type f -name '*.jar' -exec cp -vt dependencies {} \;
15+
16+
echo "Working with: "
17+
echo $JAVA_APP_JAR
18+
echo $JAVA_LIB_DIR
19+
# generate the dependency list
20+
$JAVA_HOME/bin/jdeps --multi-release $JAVA_VERSION -R -s \
21+
--module-path dependencies \
22+
"$JAVA_APP_JAR" \
23+
"$JAVA_LIB_DIR"/**/*.jar \
24+
> $S2I_JLINK_TEMP_PATH/deps.txt
25+
else
26+
$JAVA_HOME/bin/jdeps --multi-release $JAVA_VERSION -R -s \
27+
--module-path dependencies \
28+
"$JAVA_APP_JAR" \
29+
> $S2I_JLINK_TEMP_PATH/deps.txt
30+
cat $S2I_JLINK_TEMP_PATH/deps.txt
31+
fi
32+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
# TODO: Still Needed?
3+
set -euo pipefail
4+
5+
depsfile="$S2I_JLINK_TEMP_PATH/module-deps.txt"
6+
7+
function generate_jre_image() {
8+
test -f $depsfile
9+
modules="$(cat $depsfile)"
10+
11+
$JAVA_HOME/bin/jlink --output "$S2I_JLINK_OUTPUT_PATH" \
12+
--add-modules "$modules" \
13+
--strip-debug --no-header-files --no-man-pages \
14+
--compress=2
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -euo pipefail
3+
4+
function mkstrippeddeps() {
5+
if [ -f "$S2I_JLINK_TEMP_PATH/deps.txt" ]; then
6+
echo "deps exists, filtering"
7+
< $S2I_JLINK_TEMP_PATH/deps.txt \
8+
grep 'java\|jdk\.' | # mostly removes target/, but also jdk8internals
9+
sed -E "s/Warning: .*//" | #remove extraneous warnings
10+
sed -E "s/.*-> //" | # remove src of src -> dep
11+
sed -E "s/.*\.jar//" | # remove extraneous dependencies
12+
sed "s#/.*##" | # delete anything after a slash. in practice target/..
13+
sort | uniq |
14+
tee $S2I_JLINK_TEMP_PATH/stripped-deps.txt
15+
echo "Stripping dependencies complete"
16+
else
17+
echo "deps does not exist"
18+
fi
19+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
jlink_techpreview_warning()
2+
{
3+
{
4+
echo "WARNING WARNING WARNING"
5+
echo " Jlink integration is a Tech Preview feature!"
6+
echo " See <https://access.redhat.com/support/offerings/techpreview/>"
7+
echo " for more information."
8+
echo "WARNING WARNING WARNING"
9+
} >&2
10+
}
11+
12+
jlink_preflight_check()
13+
{
14+
# preflight check: do we have what we need?
15+
if [ "$JAVA_VERSION" -lt 11 ]; then
16+
echo "Jlink integration not available for JDK${JAVA_VERSION}!"
17+
echo "Jlink integration is only supported for JDK versions 11 and newer."
18+
exit 1
19+
fi
20+
if [ ! -d /usr/lib/jvm/java/jmods ]; then
21+
echo "Jlink integration requires the jmods RPM to be installed in the builder image, e.g."
22+
echo " microdnf install -y java-${JAVA_VERSION}-openjdk-jmods"
23+
exit 1
24+
fi
25+
}

modules/jlink/configure.sh

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/sh
2+
# Configure module
3+
set -e
4+
5+
SCRIPT_DIR=$(dirname $0)
6+
ARTIFACTS_DIR=${SCRIPT_DIR}/artifacts
7+
8+
chown -R default:root $SCRIPT_DIR
9+
chmod -R ug+rwX $SCRIPT_DIR
10+
chmod ug+x ${ARTIFACTS_DIR}/opt/jboss/container/java/jlink/*
11+
12+
pushd ${ARTIFACTS_DIR}
13+
cp -pr * /
14+
popd

modules/jlink/module.yaml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
schema_version: 1
2+
3+
name: "jboss.container.java.jlink"
4+
version: "2.0"
5+
description: ^
6+
"Provides support for building custom JREs with a slimmed
7+
down set of modules by making use of Jdeps and Jlink"
8+
9+
execute:
10+
- script: configure.sh
11+
12+
envs:
13+
- name: JBOSS_CONTAINER_JAVA_JLINK_MODULE
14+
value: /opt/jboss/container/java/jlink
15+
- name: S2I_JLINK_OUTPUT_PATH
16+
value: /tmp/jre
17+
- name: S2I_JLINK_TEMP_PATH
18+
value: /tmp/jlink
19+
- name: S2I_ENABLE_JLINK
20+
description: ^
21+
Enables the Jdeps/JLink workflow to minimize JRE size
22+
example: "false"
23+
24+
modules:
25+
install:
26+
- name: jboss.container.java.run
27+
- name: jboss.container.util.pathfinder
28+
29+
packages:
30+
install:
31+
- binutils # for objcopy
32+
- java-21-openjdk-jmods
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
@openjdk-tech-preview/openjdk-21-jlink-rhel9
2+
Feature: Openshift OpenJDK S2I tests (jlink specific)
3+
4+
Scenario: tech preview warning is printed (OPENJDK-3038)
5+
Given s2i build https://github.com/rh-openjdk/openjdk-container-test-applications from spring-boot-sample-simple/target using master
6+
| variable | value |
7+
| S2I_ENABLE_JLINK | true |
8+
Then s2i build log should contain Jlink integration is a Tech Preview feature
9+
10+
Scenario: Ensure S2I_ENABLE_JLINK is not set to true
11+
Given s2i build https://github.com/rh-openjdk/openjdk-container-test-applications from spring-boot-sample-simple/target using master
12+
Then s2i build log should not contain Jlink integration is a Tech Preview feature
13+
And file /tmp/jre should not exist
14+
15+
Scenario: Check that /tmp/jre/bin/java and /tmp/jre/lib/modules exist post s2i build if jlink is enabled.
16+
Given s2i build https://github.com/rh-openjdk/openjdk-container-test-applications from quarkus-quickstarts/getting-started-3.9.2-uberjar
17+
| variable | value |
18+
| S2I_ENABLE_JLINK | true |
19+
Then file /tmp/jre/bin/java should exist and be a file
20+
And file /tmp/jre/lib/modules should exist and be a file
21+
22+
Scenario: Check that /tmp/jlink is deleted when S2I_DELETE_SOURCE is set
23+
Given s2i build https://github.com/rh-openjdk/openjdk-container-test-applications from quarkus-quickstarts/getting-started-3.9.2-uberjar
24+
| variable | value |
25+
| S2I_ENABLE_JLINK | true |
26+
| S2I_DELETE_SOURCE | true |
27+
Then s2i build log should contain Cleaning up temporary file directory /tmp/jlink
28+
And file /tmp/jlink should not exist
29+
30+
Scenario: Check that /tmp/jlink is not deleted when S2I_DELETE_SOURCE is set to false
31+
Given s2i build https://github.com/rh-openjdk/openjdk-container-test-applications from quarkus-quickstarts/getting-started-3.9.2-uberjar
32+
| variable | value |
33+
| S2I_ENABLE_JLINK | true |
34+
| S2I_DELETE_SOURCE | false |
35+
Then s2i build log should not contain Cleaning up temporary file directory /tmp/jlink
36+
And file /tmp/jlink should exist

modules/jvm/tests/features/memory.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Feature: OPENJDK-559 JVM Memory tests
3434

3535
# Not the runtime images
3636
@ubi10/openjdk-21
37+
@openjdk-tech-preview/openjdk-21-jlink-rhel9
3738
Scenario: Ensure Maven doesn't use MaxRAMPercentage=80
3839
Given s2i build https://github.com/rh-openjdk/openjdk-container-test-applications.git from spring-boot-sample-simple
3940
Then s2i build log should match regex INFO Using MAVEN_OPTS.*-XX:MaxRAMPercentage=25.0$

modules/jvm/tests/features/runtime.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@ubi10/openjdk-21
2+
@openjdk-tech-preview/openjdk-21-jlink-rhel9
23
Feature: Openshift OpenJDK Runtime tests
34

45
@ubi10

0 commit comments

Comments
 (0)