Skip to content

Commit 2674851

Browse files
usmansaleemjflo
authored andcommitted
feat: Use multistage Docker build for selecting JRE (besu-eth#9392)
-- Use multistage docker build to select JRE for Besu -- Fix minor issues in Docker build file Signed-off-by: Usman Saleem <usman@usmans.info>
1 parent e0b5bfe commit 2674851

File tree

4 files changed

+36
-16
lines changed

4 files changed

+36
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
- Update to vertx 4.5.22 [#9375](https://github.com/hyperledger/besu/pull/9375)
2020
- Add `opcodes` optional parameter to RPC methods: `debug_standardTraceBlockToFile`, `debug_standardTraceBadBlockToFile`, `debug_traceBlockByNumber`, `debug_traceBlockByHash`, `debug_traceTransaction`, `debug_traceBlock`, `debug_traceCall` for tracing specified opcodes [#9335](https://github.com/hyperledger/besu/pull/9335)
2121
- eth_createAccessList now returns success result if execution reverted [#9358](https://github.com/hyperledger/besu/pull/9358)
22+
- Use Eclipse Temurin OpenJDK JRE in Besu docker image [#9392](https://github.com/hyperledger/besu/pull/9392)
2223

2324
### Bug fixes
2425

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,8 @@ application {
702702
"--add-exports",
703703
"java.base/jdk.internal.misc=ALL-UNNAMED",
704704
"--add-opens",
705-
"java.base/java.nio=ALL-UNNAMED"
705+
"java.base/java.nio=ALL-UNNAMED",
706+
"--enable-native-access=ALL-UNNAMED"
706707
]
707708
}
708709

docker/Dockerfile

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# syntax=docker/dockerfile:1
2+
3+
# Stage: Use Eclipse Temurin JRE
4+
FROM eclipse-temurin:21-jre AS java-base
5+
6+
# Stage: Final Besu image
17
FROM ubuntu:24.04
28
ARG VERSION="dev"
39
ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0"
@@ -6,18 +12,20 @@ ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true
612
RUN apt-get update $NO_PROXY_CACHE && \
713
# $NO_PROXY_CACHE must not be used here or otherwise will trigger a hadolint error
814
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* && \
15+
--no-install-recommends -q --assume-yes install libjemalloc-dev=5.* && \
1016
# Clean apt cache
1117
apt-get clean && \
1218
rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* && \
1319
rm -rf /var/lib/apt/lists/* && \
1420
# Starting from version 23.10, Ubuntu comes with an "ubuntu" user with uid 1000. We need 1000 for besu.
1521
userdel ubuntu 2>/dev/null || true && rm -rf /home/ubuntu && \
1622
# Ensure we use a stable UID for besu, as file permissions are tied to UIDs.
17-
adduser --uid 1000 --disabled-password --gecos "" --home /opt/besu besu && \
18-
chown besu:besu /opt/besu && \
23+
useradd --uid 1000 --create-home --home-dir /opt/besu --shell /bin/bash --user-group --skel /etc/skel besu && \
1924
chmod 0755 /opt/besu
2025

26+
# Copy JRE from the java-base stage
27+
COPY --from=java-base /opt/java/openjdk /opt/java/openjdk
28+
2129
ARG BESU_USER=besu
2230
USER ${BESU_USER}
2331
WORKDIR /opt/besu
@@ -43,14 +51,13 @@ ENV PYROSCOPE_CONFIGURATION_FILE=/etc/besu/pyroscope.properties
4351
EXPOSE 8545 8546 8547 8550 8551 30303
4452

4553
# defaults for host interfaces
46-
ENV BESU_RPC_HTTP_HOST 0.0.0.0
47-
ENV BESU_RPC_WS_HOST 0.0.0.0
48-
ENV BESU_GRAPHQL_HTTP_HOST 0.0.0.0
49-
ENV BESU_PID_PATH "/tmp/pid"
54+
ENV BESU_RPC_HTTP_HOST=0.0.0.0
55+
ENV BESU_RPC_WS_HOST=0.0.0.0
56+
ENV BESU_GRAPHQL_HTTP_HOST=0.0.0.0
57+
ENV BESU_PID_PATH="/tmp/pid"
5058
ENV OTEL_RESOURCE_ATTRIBUTES="service.name=besu,service.version=$VERSION"
51-
52-
ENV OLDPATH="${PATH}"
53-
ENV PATH="/opt/besu/bin:${OLDPATH}"
59+
ENV JAVA_HOME="/opt/java/openjdk"
60+
ENV PATH="/opt/besu/bin:${JAVA_HOME}/bin:${PATH}"
5461

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

ethereum/evmtool/src/main/docker/Dockerfile

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1+
# syntax=docker/dockerfile:1
12

3+
# Stage: Use Eclipse Temurin JRE
4+
FROM eclipse-temurin:21-jre AS java-base
5+
6+
# Stage: Final Besu EVMTool image
27
FROM ubuntu:24.04
38
ARG VERSION="dev"
49
ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0"
@@ -7,21 +12,27 @@ ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true
712
RUN apt-get update $NO_PROXY_CACHE && \
813
# $NO_PROXY_CACHE must not be used here or otherwise will trigger a hadolint error
914
apt-get -o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0 \
10-
--no-install-recommends -q --assume-yes install openjdk-21-jre-headless=21* adduser=3* && \
15+
--no-install-recommends -q --assume-yes install libjemalloc-dev=5.* && \
1116
# Clean apt cache \
1217
apt-get clean && \
1318
rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* && \
1419
rm -rf /var/lib/apt/lists/* && \
15-
# Creating a user for besu
16-
adduser --disabled-password --gecos "" --home /opt/besu besu && \
17-
chown besu:besu /opt/besu
20+
# Starting from version 23.10, Ubuntu comes with an "ubuntu" user with uid 1000. We need 1000 for besu.
21+
userdel ubuntu 2>/dev/null || true && rm -rf /home/ubuntu && \
22+
# Ensure we use a stable UID for besu, as file permissions are tied to UIDs.
23+
useradd --uid 1000 --create-home --home-dir /opt/besu-evmtool --shell /bin/bash --user-group --skel /etc/skel besu && \
24+
chmod 0755 /opt/besu-evmtool
25+
26+
# Copy JRE from the jre-base stage
27+
COPY --from=java-base /opt/java/openjdk /opt/java/openjdk
1828

1929
USER besu
2030
WORKDIR /opt/besu-evmtool
2131

2232
COPY --chown=besu:besu besu-evmtool /opt/besu-evmtool/
2333

24-
ENV PATH="/opt/besu-evmtool/bin:${PATH}"
34+
ENV JAVA_HOME="/opt/java/openjdk"
35+
ENV PATH="/opt/besu-evmtool/bin:${JAVA_HOME}/bin:${PATH}"
2536
ENTRYPOINT ["evmtool"]
2637

2738
# Build-time metadata as defined at http://label-schema.org

0 commit comments

Comments
 (0)