diff --git a/docker/Dockerfile b/docker/Dockerfile index 2f7915e7032..4e02bb35e6e 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -1,31 +1,17 @@ FROM ubuntu:24.04 ARG VERSION="dev" +ARG OPENJDK_VERSION="8u514-b01~us1-0ubuntu1~24.04.1" ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0" ENV TMP_DIR="/tron-build" -ENV OPENJDK8_URL="https://api.adoptium.net/v3/binary/latest/8/ga/linux/x64/jdk/hotspot/normal/eclipse" -ENV ADOPTIUM_SIGNING_FINGERPRINT="3B04D753C9050D9A5D343F39843C48A565F8F04B" -ENV JDK_DIR="/usr/local/openjdk-8" ENV BASE_DIR="/java-tron" +ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64" -# Update and install dependencies without using any cache -RUN apt-get update $NO_PROXY_CACHE && \ - apt-get --quiet --yes install git 7zip curl jq libtcmalloc-minimal4 gnupg dirmngr ca-certificates && \ - cd /usr/local \ - && FETCH_URL="$(curl -fsS -w "%{redirect_url}" -o /dev/null "$OPENJDK8_URL")" \ - && JDK_TAR="$(curl -fsSL -w "%{filename_effective}" -O "$FETCH_URL")" \ - && curl -fsSLo "$JDK_TAR.sig" "$FETCH_URL.sig" \ - && GNUPGHOME="$(mktemp -d)" \ - && export GNUPGHOME \ - && gpg --batch --keyserver hkps://keyserver.ubuntu.com --recv-keys "$ADOPTIUM_SIGNING_FINGERPRINT" \ - && gpg --batch --verify "$JDK_TAR.sig" "$JDK_TAR" \ - && rm -rf "$GNUPGHOME" "$JDK_TAR.sig" \ - && mkdir -p "$JDK_DIR" \ - && tar -zxf "$JDK_TAR" -C "$JDK_DIR" --strip-components=1 \ - && rm "$JDK_TAR" \ - && export JAVA_HOME=$JDK_DIR \ - && export CLASSPATH=$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar \ - && export PATH=$PATH:$JAVA_HOME/bin \ +# Apply Ubuntu updates to packages inherited from the base image before installing build tools. +RUN apt-get --error-on=any update $NO_PROXY_CACHE \ + && DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends --with-new-pkgs upgrade \ + && apt-get --quiet --yes --no-install-recommends install ca-certificates git libtcmalloc-minimal4 \ + "openjdk-8-jdk-headless=$OPENJDK_VERSION" "openjdk-8-jre-headless=$OPENJDK_VERSION" \ && echo "git clone" \ && mkdir -p $TMP_DIR \ && cd $TMP_DIR \ @@ -34,20 +20,22 @@ RUN apt-get update $NO_PROXY_CACHE && \ && git checkout master \ && ./gradlew clean build -x test -x check --no-daemon \ && cd build/distributions \ - && 7z x -y java-tron-1.0.0.zip \ - && cp $TMP_DIR/java-tron/framework/src/main/resources/config.conf java-tron-1.0.0/config.conf \ - && mv java-tron-1.0.0 $BASE_DIR \ + && "$JAVA_HOME/bin/jar" xf java-tron-1.0.0.zip \ + && mv java-tron-1.0.0 "$BASE_DIR" \ + && chmod 755 "$BASE_DIR/bin/FullNode" "$BASE_DIR/bin/FullNode.bat" \ + && cp ../../framework/src/main/resources/config.conf "$BASE_DIR/config.conf" \ + && cd / \ && rm -rf $TMP_DIR \ && rm -rf ~/.gradle \ - && mv $JDK_DIR/jre /usr/local \ - && rm -rf $JDK_DIR \ + && apt-get --quiet --yes purge --auto-remove git openjdk-8-jdk-headless \ # Clean apt cache && apt-get clean \ && rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* \ && rm -rf /var/lib/apt/lists/* -ENV JAVA_HOME="/usr/local/jre" -ENV PATH=$PATH:$JAVA_HOME/bin +# The explicitly installed Java 8 JRE stays in this directory after the JDK is purged. +ENV JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/jre" +ENV PATH=$JAVA_HOME/bin:$PATH ENV LD_PRELOAD="/usr/lib/x86_64-linux-gnu/libtcmalloc_minimal.so.4" ENV TCMALLOC_RELEASE_RATE=10 diff --git a/docker/arm64/Dockerfile b/docker/arm64/Dockerfile index 8b4601223b6..b46afcee147 100644 --- a/docker/arm64/Dockerfile +++ b/docker/arm64/Dockerfile @@ -1,13 +1,18 @@ FROM ubuntu:24.04 ARG VERSION="dev" +ARG OPENJDK_VERSION="17.0.21.1+2-1~24.04.1" ENV NO_PROXY_CACHE="-o Acquire::BrokenProxy=true -o Acquire::http::No-Cache=true -o Acquire::http::Pipeline-Depth=0" ENV TMP_DIR="/tron-build" ENV BASE_DIR="/java-tron" +ENV JAVA_HOME="/usr/lib/jvm/java-17-openjdk-arm64" +ENV PATH=$JAVA_HOME/bin:$PATH -# Update and install dependencies without using any cache -RUN apt-get update $NO_PROXY_CACHE \ - && apt-get --quiet --yes install git 7zip curl jq libtcmalloc-minimal4 openjdk-17-jre-headless=17* \ +# Apply Ubuntu updates to packages inherited from the base image before installing build tools. +RUN apt-get --error-on=any update $NO_PROXY_CACHE \ + && DEBIAN_FRONTEND=noninteractive apt-get --quiet --yes --no-install-recommends --with-new-pkgs upgrade \ + && apt-get --quiet --yes --no-install-recommends install ca-certificates git libtcmalloc-minimal4 \ + "openjdk-17-jre-headless=$OPENJDK_VERSION" \ && echo "git clone" \ && mkdir -p $TMP_DIR \ && cd $TMP_DIR \ @@ -16,18 +21,19 @@ RUN apt-get update $NO_PROXY_CACHE \ && git checkout master \ && ./gradlew clean build -x test -x check --no-daemon \ && cd build/distributions \ - && 7z x -y java-tron-1.0.0.zip \ - && cp $TMP_DIR/java-tron/framework/src/main/resources/config.conf java-tron-1.0.0/config.conf \ - && mv java-tron-1.0.0 $BASE_DIR \ + && java -m jdk.jartool/sun.tools.jar.Main xf java-tron-1.0.0.zip \ + && mv java-tron-1.0.0 "$BASE_DIR" \ + && chmod 755 "$BASE_DIR/bin/FullNode" "$BASE_DIR/bin/FullNode.bat" \ + && cp ../../framework/src/main/resources/config.conf "$BASE_DIR/config.conf" \ + && cd / \ && rm -rf $TMP_DIR \ && rm -rf ~/.gradle \ + && apt-get --quiet --yes purge --auto-remove git \ # Clean apt cache && apt-get clean \ && rm -rf /var/cache/apt/archives/* /var/cache/apt/archives/partial/* \ && rm -rf /var/lib/apt/lists/* -ENV JAVA_HOME="/usr/lib/jvm/java-17-openjdk-arm64" -ENV PATH=$PATH:$JAVA_HOME/bin ENV LD_PRELOAD="/usr/lib/aarch64-linux-gnu/libtcmalloc_minimal.so.4" ENV TCMALLOC_RELEASE_RATE=10 diff --git a/docker/docker.md b/docker/docker.md index 4941139ae64..fdfdb9ea1cd 100644 --- a/docker/docker.md +++ b/docker/docker.md @@ -159,6 +159,14 @@ $ bash docker.sh --build amd64 $ bash docker.sh --build arm64 ``` +To override the pin for one build, set `OPENJDK_VERSION` to the full Ubuntu package version for the target architecture. + +```shell +OPENJDK_VERSION='' bash docker.sh --build arm64 +``` + +A successful build updates the local `tronprotocol/java-tron:latest` tag used by `--run`. To test a candidate version under a separate tag, follow [Update a pinned OpenJDK package](#update-a-pinned-openjdk-package). + Building for an architecture different from the Docker daemon requires a builder with the corresponding emulation support. Docker Desktop provides this by default; standalone Docker Engine installations may require QEMU/binfmt configuration. Docker may reuse cached layers, so rebuilding does not necessarily fetch the latest remote `master`. To fetch the source again, run one of the following commands from the java-tron repository root. The helper does not accept `--no-cache`; use Docker directly: @@ -179,11 +187,41 @@ When the script is used from a java-tron checkout, only the Dockerfile and build Standalone `--build` using only a downloaded `docker.sh` is currently unavailable. The helper downloads only the architecture-specific Dockerfile from `develop`, but the current `develop` Dockerfiles also require `docker-entrypoint.sh`, which is missing from the temporary build context. Use a complete checkout containing the matching Dockerfiles until those files are synchronized to `develop` and standalone builds are verified for both architectures. +### Update a pinned OpenJDK package + +Each Dockerfile pins an exact OpenJDK package version from the Ubuntu 24.04 repositories. When Ubuntu replaces that version in the package index, a fresh build for the affected architecture can fail with `Version ... was not found`. Check the versions available for that architecture. + +```shell +# amd64 requires the same version of both Java 8 packages +docker run --rm --platform linux/amd64 ubuntu:24.04 sh -ec \ + 'apt-get --error-on=any update -qq && apt-cache madison openjdk-8-jdk-headless openjdk-8-jre-headless' + +# arm64 uses the Java 17 runtime +docker run --rm --platform linux/arm64 ubuntu:24.04 sh -ec \ + 'apt-get --error-on=any update -qq && apt-cache madison openjdk-17-jre-headless' +``` + +Choose the full version from the second column, including the Ubuntu revision. For a security update, check the fixed version for Ubuntu 24.04 in the relevant [Ubuntu Security Notice](https://ubuntu.com/security/notices). From the repository root, substitute the chosen version in the build command for the affected architecture. + +```shell +# amd64 +docker build --no-cache --platform linux/amd64 \ + --build-arg OPENJDK_VERSION='' \ + -f docker/Dockerfile -t java-tron:check-amd64 docker + +# arm64 +docker build --no-cache --platform linux/arm64 \ + --build-arg OPENJDK_VERSION='' \ + -f docker/arm64/Dockerfile -t java-tron:check-arm64 docker +``` + +Verify the runtime with `docker run --rm --platform --entrypoint java -version` and confirm FullNode starts with your usual configuration. Then update the `ARG OPENJDK_VERSION` default in the corresponding Dockerfile so subsequent builds use the verified version. + ## Options ### Commands -- **`--build [amd64|arm64]`**: build `tronprotocol/java-tron:latest` from the remote `master` branch, optionally for the specified architecture +- **`--build [amd64|arm64]`**: build `tronprotocol/java-tron:latest` from the remote `master` branch, optionally for the specified architecture. Set `OPENJDK_VERSION` to override the pinned Ubuntu OpenJDK package version for that build. - **`--pull`**: download `tronprotocol/java-tron:latest` from Docker Hub - **`--run`**: run `tronprotocol/java-tron:latest` - **`--start`**: start the existing java-tron container diff --git a/docker/docker.sh b/docker/docker.sh index 0a9f511d0b9..a5b4e9eb73e 100644 --- a/docker/docker.sh +++ b/docker/docker.sh @@ -314,6 +314,7 @@ build() { local build_context="$SCRIPT_DIR" local temporary_context="" local build_status + local -a build_args=() if [[ $# -gt 1 ]]; then echo "build: expected at most one architecture argument" >&2 @@ -363,11 +364,17 @@ build() { fi fi + if [[ -n "${OPENJDK_VERSION:-}" ]]; then + build_args+=(--build-arg "OPENJDK_VERSION=$OPENJDK_VERSION") + printf 'build: overriding OPENJDK_VERSION=%q for %s\n' "$OPENJDK_VERSION" "$platform" + fi + echo "docker build --platform $platform --file $dockerfile_path" docker build \ --platform "$platform" \ --file "$dockerfile_path" \ --tag "$IMAGE_REFERENCE" \ + "${build_args[@]}" \ "$build_context" build_status=$?