Skip to content

Commit f625387

Browse files
committed
Tune start script for OpenJDK 25 and use it in Docker image
Signed-off-by: Fabio Di Fabio <[email protected]>
1 parent cecb7ce commit f625387

File tree

3 files changed

+63
-17
lines changed

3 files changed

+63
-17
lines changed

app/src/main/scripts/unixStartScript.txt

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,6 @@ cd "\$SAVED" >/dev/null
4343
APP_NAME="${applicationName}"
4444
APP_BASE_NAME=`basename "\$0"`
4545

46-
# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script.
47-
DEFAULT_JVM_OPTS=${defaultJvmOpts}
48-
4946
# Use the maximum available, or set MAX_FD != -1 to use that value.
5047
MAX_FD="maximum"
5148

@@ -105,6 +102,18 @@ Please set the JAVA_HOME variable in your environment to match the
105102
location of your Java installation."
106103
fi
107104

105+
JAVA_VERSION=`"\$JAVA_HOME/bin/java" -version 2>&1 | fgrep version | cut -d' ' -f3 | tr -d '"' | cut -d. -f1`
106+
107+
# Add default JVM options here. You can also use JAVA_OPTS and ${optsEnvironmentVar} to pass JVM options to this script.
108+
if [ "\$JAVA_VERSION" -ge 25 ]; then
109+
DEFAULT_JVM_OPTS=@DEFAULT_JVM_OPTS_25@
110+
elif [ "\$JAVA_VERSION" -ge 21 ]; then
111+
DEFAULT_JVM_OPTS=${defaultJvmOpts}
112+
else
113+
echo "Java version must be at least 21"
114+
exit 1
115+
fi
116+
108117
# Increase the maximum file descriptors if we can.
109118
if [ "\$cygwin" = "false" -a "\$darwin" = "false" -a "\$nonstop" = "false" ] ; then
110119
MAX_FD_LIMIT=`ulimit -H -n`

build.gradle

Lines changed: 29 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -714,11 +714,14 @@ run {
714714
}
715715
}
716716

717-
def tweakStartScript(createScriptTask) {
717+
def tweakStartScript(createScriptTask, defaultJvmOpts25) {
718718
def shortenWindowsClasspath = { line ->
719719
line.replaceAll(/^set CLASSPATH=.*$/, "set CLASSPATH=%APP_HOME%/lib/*")
720720
}
721721

722+
// this must be before the BESU_HOME replacement
723+
createScriptTask.unixScript.text = createScriptTask.unixScript.text.replace('@DEFAULT_JVM_OPTS_25@', defaultJvmOpts25)
724+
722725
createScriptTask.unixScript.text = createScriptTask.unixScript.text.replace('BESU_HOME', '\$APP_HOME')
723726
createScriptTask.windowsScript.text = createScriptTask.windowsScript.text.replace('BESU_HOME', '%~dp0..')
724727

@@ -730,17 +733,32 @@ def tweakStartScript(createScriptTask) {
730733
.join('\r\n')
731734
}
732735

736+
def defaultJvmOpts21 = application.applicationDefaultJvmArgs + [
737+
"-XX:G1ConcRefinementThreads=2",
738+
"-XX:G1HeapWastePercent=15",
739+
"-XX:MaxGCPauseMillis=100",
740+
"-XX:StartFlightRecording,settings=default.jfc",
741+
"-Xlog:jfr*=off"
742+
]
743+
744+
def defaultJvmOpts25 = defaultJvmOpts21 + [
745+
"-XX:+UseCompactObjectHeaders",
746+
"-XX:MaxHeapFreeRatio=30",
747+
"-XX:MinHeapFreeRatio=10",
748+
"-XX:GCTimeRatio=50",
749+
"-XX:-ShrinkHeapInSteps"
750+
]
751+
752+
def serializeDefaultJvmOpts(opts) {
753+
return "'" + opts.collect{ /"$it"/}.join(' ') + "'"
754+
}
755+
733756
startScripts {
734-
defaultJvmOpts = application.applicationDefaultJvmArgs + [
735-
"-XX:G1ConcRefinementThreads=2",
736-
"-XX:G1HeapWastePercent=15",
737-
"-XX:MaxGCPauseMillis=100",
738-
"-XX:StartFlightRecording,settings=default.jfc",
739-
"-Xlog:jfr*=off"
740-
]
757+
defaultJvmOpts = defaultJvmOpts21
741758
unixStartScriptGenerator.template = resources.text.fromFile("${projectDir}/app/src/main/scripts/unixStartScript.txt")
742759
windowsStartScriptGenerator.template = resources.text.fromFile("${projectDir}/app/src/main/scripts/windowsStartScript.txt")
743-
doLast { tweakStartScript(startScripts) }
760+
761+
doLast { tweakStartScript(startScripts, serializeDefaultJvmOpts(defaultJvmOpts25)) }
744762
}
745763

746764
task untunedStartScripts(type: CreateStartScripts) {
@@ -751,7 +769,7 @@ task untunedStartScripts(type: CreateStartScripts) {
751769
defaultJvmOpts = application.applicationDefaultJvmArgs
752770
unixStartScriptGenerator.template = resources.text.fromFile("${projectDir}/app/src/main/scripts/unixStartScript.txt")
753771
windowsStartScriptGenerator.template = resources.text.fromFile("${projectDir}/app/src/main/scripts/windowsStartScript.txt")
754-
doLast { tweakStartScript(untunedStartScripts) }
772+
doLast { tweakStartScript(untunedStartScripts, serializeDefaultJvmOpts(application.applicationDefaultJvmArgs)) }
755773
}
756774

757775
task evmToolStartScripts(type: CreateStartScripts) {
@@ -764,7 +782,7 @@ task evmToolStartScripts(type: CreateStartScripts) {
764782
]
765783
unixStartScriptGenerator.template = resources.text.fromFile("${projectDir}/app/src/main/scripts/unixStartScript.txt")
766784
windowsStartScriptGenerator.template = resources.text.fromFile("${projectDir}/app/src/main/scripts/windowsStartScript.txt")
767-
doLast { tweakStartScript(evmToolStartScripts) }
785+
doLast { tweakStartScript(evmToolStartScripts, serializeDefaultJvmOpts(defaultJvmOpts)) }
768786
}
769787

770788
task autocomplete(type: JavaExec) {

docker/Dockerfile

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
FROM ubuntu:24.04
2+
ARG TARGETARCH
23
ARG VERSION="dev"
34
ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0"
45

56
# Update and install dependencies without using any cache
67
RUN apt-get update $NO_PROXY_CACHE && \
78
# $NO_PROXY_CACHE must not be used here or otherwise will trigger a hadolint error
89
apt-get -o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0 \
9-
--no-install-recommends -q --assume-yes install openjdk-21-jre-headless=21* libjemalloc-dev=5.* adduser=3* && \
10+
--no-install-recommends -q --assume-yes install libjemalloc-dev=5.* adduser=3* wget=1* ca-certificates=2* && \
1011
# Clean apt cache
1112
apt-get clean && \
1213
rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* && \
@@ -16,7 +17,24 @@ RUN apt-get update $NO_PROXY_CACHE && \
1617
# Ensure we use a stable UID for besu, as file permissions are tied to UIDs.
1718
adduser --uid 1000 --disabled-password --gecos "" --home /opt/besu besu && \
1819
chown besu:besu /opt/besu && \
19-
chmod 0755 /opt/besu
20+
chmod 0755 /opt/besu && \
21+
case "${TARGETARCH}" in \
22+
amd64) JDK_ARCH=x64 \
23+
CHECKSUM=59cdcaf255add4721de38eb411d4ecfe779356b61fb671aee63c7dec78054c2b \
24+
;; \
25+
arm64) JDK_ARCH=aarch64 \
26+
CHECKSUM=f4a8d27429458a529148f90ebafcd1ae9b1968fa323f9e5e40d579a5c8c0288f \
27+
;; \
28+
*) echo "Unsupported architecture: ${TARGETARCH}" && exit 1 ;; \
29+
esac && \
30+
wget -q "https://download.java.net/java/GA/jdk25/bd75d5f9689641da8e1daabeccb5528b/36/GPL/openjdk-25_linux-${JDK_ARCH}_bin.tar.gz" && \
31+
if [ "$(sha256sum "openjdk-25_linux-${JDK_ARCH}_bin.tar.gz")" != "${CHECKSUM} openjdk-25_linux-${JDK_ARCH}_bin.tar.gz" ]; \
32+
then \
33+
echo "Checksum failed" && exit 1; \
34+
else \
35+
tar -xzf "openjdk-25_linux-${JDK_ARCH}_bin.tar.gz" -C /opt ; \
36+
rm "openjdk-25_linux-${JDK_ARCH}_bin.tar.gz"; \
37+
fi
2038

2139
ARG BESU_USER=besu
2240
USER ${BESU_USER}
@@ -49,8 +67,9 @@ ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0
4967
ENV BESU_PID_PATH "/tmp/pid"
5068
ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu,service.version=$VERSION"
5169

70+
ENV JAVA_HOME="/opt/jdk-25"
5271
ENV OLDPATH="${PATH}"
53-
ENV PATH="/opt/besu/bin:${OLDPATH}"
72+
ENV PATH="/opt/besu/bin:${JAVA_HOME}/bin:${OLDPATH}"
5473

5574
# The entry script just sets permissions as needed based on besu config
5675
# and is replaced by the besu process running as besu user.

0 commit comments

Comments
 (0)