Skip to content

Commit 6d8bb45

Browse files
authored
Merge pull request #566 from Josh-Matsuoka/3646
[OPENJDK-3646] clean up jdeps *.txt files unless S2I_DELETE_SOURCE is set
2 parents 643a79c + ec538a0 commit 6d8bb45

File tree

7 files changed

+41
-11
lines changed

7 files changed

+41
-11
lines changed

modules/jlink/artifacts/opt/jboss/container/java/jlink/generatejdkdeps.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
function generatejdkdeps() {
44
echo "Generating JDK deps"
5-
$JAVA_HOME/bin/java --list-modules > java-modules.txt
6-
< java-modules.txt sed "s/\\@.*//" > modules.txt
7-
grep -Fx -f stripped-deps.txt modules.txt | tr '\n' ',' | tr -d "[:space:]" > module-deps.txt
8-
echo "jdk.zipfs" >> module-deps.txt
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
99
}

modules/jlink/artifacts/opt/jboss/container/java/jlink/mkdeps.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ function generate_deps() {
2121
--module-path dependencies \
2222
"$JAVA_APP_JAR" \
2323
"$JAVA_LIB_DIR"/**/*.jar \
24-
> deps.txt
24+
> $S2I_JLINK_TEMP_PATH/deps.txt
2525
else
2626
$JAVA_HOME/bin/jdeps --multi-release $JAVA_VERSION -R -s \
2727
--module-path dependencies \
2828
"$JAVA_APP_JAR" \
29-
> deps.txt
30-
cat deps.txt
29+
> $S2I_JLINK_TEMP_PATH/deps.txt
30+
cat $S2I_JLINK_TEMP_PATH/deps.txt
3131
fi
3232
}

modules/jlink/artifacts/opt/jboss/container/java/jlink/mkjreimage.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# TODO: Still Needed?
33
set -euo pipefail
44

5-
depsfile="module-deps.txt"
5+
depsfile="$S2I_JLINK_TEMP_PATH/module-deps.txt"
66

77
function generate_jre_image() {
88
test -f $depsfile

modules/jlink/artifacts/opt/jboss/container/java/jlink/mkstrippeddeps.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22
set -euo pipefail
33

44
function mkstrippeddeps() {
5-
if [ -f "deps.txt" ]; then
5+
if [ -f "$S2I_JLINK_TEMP_PATH/deps.txt" ]; then
66
echo "deps exists, filtering"
7-
<deps.txt \
7+
< $S2I_JLINK_TEMP_PATH/deps.txt \
88
grep 'java\|jdk\.' | # mostly removes target/, but also jdk8internals
99
sed -E "s/Warning: .*//" | #remove extraneous warnings
1010
sed -E "s/.*-> //" | # remove src of src -> dep
1111
sed -E "s/.*\.jar//" | # remove extraneous dependencies
1212
sed "s#/.*##" | # delete anything after a slash. in practice target/..
1313
sort | uniq |
14-
tee stripped-deps.txt
14+
tee $S2I_JLINK_TEMP_PATH/stripped-deps.txt
1515
echo "Stripping dependencies complete"
1616
else
1717
echo "deps does not exist"

modules/jlink/module.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ envs:
1414
value: /opt/jboss/container/java/jlink
1515
- name: S2I_JLINK_OUTPUT_PATH
1616
value: /tmp/jre
17+
- name: S2I_JLINK_TEMP_PATH
18+
value: /tmp/jlink
1719

1820
modules:
1921
install:

modules/jlink/tests/features/jlink.feature

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,19 @@ Scenario: Check that /tmp/jre/bin/java and /tmp/jre/lib/modules exist post s2i b
1818
| S2I_ENABLE_JLINK | true |
1919
Then file /tmp/jre/bin/java should exist and be a file
2020
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/s2i/bash/artifacts/usr/local/s2i/assemble

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ if [ "$S2I_ENABLE_JLINK" = "true" ]; then
2525
jlink_techpreview_warning
2626
jlink_preflight_check
2727

28+
if [ ! -d "${S2I_JLINK_TEMP_PATH}" ]; then
29+
log_info "S2I_JLINK_TEMP_PATH does not exist, creating ${S2I_JLINK_TEMP_PATH}"
30+
mkdir -pm 775 "${S2I_JLINK_TEMP_PATH}"
31+
fi
32+
2833
source "${JBOSS_CONTAINER_JAVA_JLINK_MODULE}/mkdeps.sh"
2934
echo "Invoking mkdeps"
3035
generate_deps || {
@@ -53,4 +58,11 @@ if [ "$S2I_ENABLE_JLINK" = "true" ]; then
5358
exit 1
5459
}
5560

61+
if [ "$S2I_DELETE_SOURCE" == "true" ]; then
62+
if [ -n "$(find $S2I_JLINK_TEMP_PATH -maxdepth 0 -type d ! -empty 2> /dev/null)" ]; then
63+
log_info "Cleaning up temporary file directory $S2I_JLINK_TEMP_PATH"
64+
rm -rf $S2I_JLINK_TEMP_PATH
65+
fi
66+
fi
5667
fi
68+

0 commit comments

Comments
 (0)