Skip to content

Commit 4563d8e

Browse files
committed
Create temporary jlink files under /tmp/jlink, clean up based on S2I_DELETE_SOURCE
1 parent 7e16de1 commit 4563d8e

File tree

6 files changed

+24
-10
lines changed

6 files changed

+24
-10
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
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"
77
<deps.txt \
88
grep 'java\|jdk\.' | # mostly removes target/, but also jdk8internals
@@ -11,7 +11,7 @@ function mkstrippeddeps() {
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/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 || {
@@ -54,3 +59,10 @@ if [ "$S2I_ENABLE_JLINK" = "true" ]; then
5459
}
5560

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

0 commit comments

Comments
 (0)