Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add a docker image for Java 21 support #702

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/flow-deploy-release-artifact.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
##
# Copyright (C) 2023 Hedera Hashgraph, LLC
# Copyright (C) 2023-2024 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -153,6 +153,14 @@ jobs:
push: ${{ github.event.inputs.dry-run-enabled != 'true' }}
tags: ghcr.io/${{ github.repository }}/ubi8-init-java17:${{ needs.prepare-release.outputs.version }}

- name: Build Docker Image (ubi8-init-java21)
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
context: docker/ubi8-init-java21
platforms: linux/amd64, linux/arm64
push: ${{ github.event.inputs.dry-run-enabled != 'true' }}
tags: ghcr.io/${{ github.repository }}/ubi8-init-java21:${{ needs.prepare-release.outputs.version }}

- name: Build Docker Image (kubectl-bats)
uses: docker/build-push-action@4a13e500e55cf31b7a5d59a38ab2040ab0f42f56 # v5.1.0
with:
Expand Down
118 changes: 118 additions & 0 deletions docker/ubi8-init-java21/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
#
# Copyright (C) 2023 Hedera Hashgraph, LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

FROM registry.access.redhat.com/ubi8/ubi-init:latest

Check warning on line 17 in docker/ubi8-init-java21/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docker/ubi8-init-java21/Dockerfile#L17

Using latest is prone to errors if the image will ever update. Pin the version explicitly to a release tag
# Define Standard Environment Variables
ENV LC_ALL=C.UTF-8

# Define JDK Environment Variables
ENV JAVA_VERSION "jdk-21.0.1+12"
ENV JAVA_HOME /usr/local/java
ENV PATH ${JAVA_HOME}/bin:${PATH}

# Define Application Environment Variables
ENV JAVA_HEAP_MIN=""
ENV JAVA_HEAP_MAX=""
ENV JAVA_OPTS=""
ENV JAVA_MAIN_CLASS ""
ENV JAVA_CLASS_PATH ""

# Performance Tuning for Malloc
ENV MALLOC_ARENA_MAX 4

# Log Folder Name Override
ENV LOG_DIR_NAME ""

RUN dnf -y install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm && \
/usr/bin/crb enable && \
dnf -y install binutils libsodium openssl zlib readline tzdata gzip tar ca-certificates curl && \
dnf clean all

# Install Java 21 Adoptium JDK
RUN set -eux; \
ARCH="$(dpkg --print-architecture)"; \
case "${ARCH}" in \
aarch64|arm64) \
ESUM='e184dc29a6712c1f78754ab36fb48866583665fa345324f1a79e569c064f95e9'; \
BINARY_URL='https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.1%2B12/OpenJDK21U-jdk_aarch64_linux_hotspot_21.0.1_12.tar.gz'; \
;; \
amd64|i386:x86-64) \
ESUM='1a6fa8abda4c5caed915cfbeeb176e7fbd12eb6b222f26e290ee45808b529aa1'; \
BINARY_URL='https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.1%2B12/OpenJDK21U-jdk_x64_linux_hotspot_21.0.1_12.tar.gz'; \
;; \
ppc64el|powerpc:common64) \
ESUM='9574828ef3d735a25404ced82e09bf20e1614f7d6403956002de9cfbfcb8638f'; \
BINARY_URL='https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.1%2B12/OpenJDK21U-jdk_ppc64le_linux_hotspot_21.0.1_12.tar.gz'; \
;; \
*) \
echo "Unsupported arch: ${ARCH}"; \
exit 1; \
;; \
esac; \
curl -LfsSo /tmp/openjdk.tar.gz ${BINARY_URL}; \
echo "${ESUM} */tmp/openjdk.tar.gz" | sha256sum -c -; \
mkdir -p /usr/local/java; \
tar --extract \
--file /tmp/openjdk.tar.gz \
--directory "/usr/local/java" \
--strip-components 1 \
--no-same-owner \
; \
rm -f /tmp/openjdk.tar.gz /usr/local/java/lib/src.zip;

RUN dnf -y install sudo && \
echo >> /etc/sudoers && \
echo "%hedera ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers

# Configure the standard user account
RUN groupadd --gid 2000 hedera && \
useradd --no-user-group --create-home --uid 2000 --gid 2000 --shell /bin/bash hedera && \
mkdir -p /opt/hgcapp && \
chown -R hedera:hedera /opt/hgcapp

# Create Application Folders
RUN mkdir -p "/opt/hgcapp" && \
mkdir -p "/opt/hgcapp/accountBalances" && \
mkdir -p "/opt/hgcapp/eventsStreams" && \
mkdir -p "/opt/hgcapp/recordStreams" && \
mkdir -p "/opt/hgcapp/services-hedera" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data/apps" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data/config" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data/keys" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data/lib" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data/stats" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data/saved" && \
mkdir -p "/opt/hgcapp/services-hedera/HapiApp2.0/data/upgrade"

# Add the entrypoint script and systemd service file
ADD entrypoint.sh /etc/network-node/

Check failure on line 103 in docker/ubi8-init-java21/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docker/ubi8-init-java21/Dockerfile#L103

Use COPY instead of ADD for files and folders
ADD network-node.service /usr/lib/systemd/system/

Check failure on line 104 in docker/ubi8-init-java21/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docker/ubi8-init-java21/Dockerfile#L104

Use COPY instead of ADD for files and folders

# Ensure proper file permissions
RUN chmod -R +x /etc/network-node/entrypoint.sh && \
chown -R 2000:2000 /opt/hgcapp/

RUN mkdir -p /etc/network-node && \
touch /etc/network-node/application.env && \
chown -R 2000:2000 /etc/network-node

# Expose TCP/UDP Port Definitions
EXPOSE 50111/tcp 50211/tcp 50212/tcp

# Set Final Working Directory and User
WORKDIR "/opt/hgcapp"

Check failure on line 118 in docker/ubi8-init-java21/Dockerfile

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docker/ubi8-init-java21/Dockerfile#L118

Use absolute WORKDIR
37 changes: 37 additions & 0 deletions docker/ubi8-init-java21/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

plugins {
id("com.palantir.docker") version "0.35.0"
}

val repo = "ghcr.io"
val registry = "hashgraph/full-stack-testing"
val containerName = "ubi8-init-java21"
val appVersion = project.version.toString()

docker {
name = "${repo}/${registry}/${containerName}:${appVersion}"
version = appVersion
files("entrypoint.sh", "network-node.service")
buildx(true)
if (!System.getenv("CI").isNullOrEmpty()) {
platform("linux/arm64", "linux/amd64")
push(true)
} else {
load(true) // loads the image into the local docker daemon, doesn't support multi-platform
}
}
112 changes: 112 additions & 0 deletions docker/ubi8-init-java21/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
#!/usr/bin/env bash

########################################################################################################################
# Copyright 2016-2022 Hedera Hashgraph, LLC #
# #
# Licensed under the Apache License, Version 2.0 (the "License"); #
# you may not use this file except in compliance with the License. #
# You may obtain a copy of the License at #
# #
# http://www.apache.org/licenses/LICENSE-2.0 #
# #
# Unless required by applicable law or agreed to in writing, software #
# distributed under the License is distributed on an "AS IS" BASIS, #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. #
# See the License for the specific language governing permissions and #
# limitations under the License. #
########################################################################################################################

set -eo pipefail

SCRIPT_PATH="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
cd "${SCRIPT_PATH}" || exit 64

if [[ -z "${JAVA_OPTS}" ]]; then
JAVA_OPTS=""
fi

# Setup Heap Options
JAVA_HEAP_OPTS=""

if [[ -n "${JAVA_HEAP_MIN}" ]]; then
JAVA_HEAP_OPTS="${JAVA_HEAP_OPTS} -Xms${JAVA_HEAP_MIN}"
fi

if [[ -n "${JAVA_HEAP_MAX}" ]]; then
JAVA_HEAP_OPTS="${JAVA_HEAP_OPTS} -Xmx${JAVA_HEAP_MAX}"
fi

# Setup Main Class
[[ -z "${JAVA_MAIN_CLASS}" ]] && JAVA_MAIN_CLASS="com.swirlds.platform.Browser"

# Setup Classpath
JCP_OVERRIDDEN="false"
if [[ -z "${JAVA_CLASS_PATH}" ]]; then
JAVA_CLASS_PATH="data/lib/*"
else
JCP_OVERRIDDEN="true"
fi

if [[ "${JCP_OVERRIDDEN}" != true && "${JAVA_MAIN_CLASS}" != "com.swirlds.platform.Browser" ]]; then
JAVA_CLASS_PATH="${JAVA_CLASS_PATH}:data/apps/*"
fi

# Override Log Directory Name (if provided)
LOG_DIR_NAME="${LOG_DIR_NAME:-output}"

# Ensure the log directory exists
if [[ ! -d "${SCRIPT_PATH}/${LOG_DIR_NAME}" ]]; then
mkdir -p "${SCRIPT_PATH}/${LOG_DIR_NAME}"
fi

cat <<EOF


**************** ****************************************************************************************
************ ************ *
********* ********* *
****** ****** *
**** **** ___ ___ ___ ___ ___ *
*** ĦĦĦĦ ĦĦĦĦ *** /\ \ /\ \ /\ \ /\ \ /\ \ *
** ĦĦĦĦ ĦĦĦĦ ** /::\ \ /::\ \ /::\ \ /::\ \ /::\ \ *
* ĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦ * /:/\:\ \ /:/\:\ \ /:/\:\ \ /:/\:\ \ /:/\:\ \ *
ĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦ /::\~\:\ \ /:/ \:\__\ /::\~\:\ \ /::\~\:\ \ /::\~\:\ \ *
ĦĦĦĦ ĦĦĦĦ /:/\:\ \:\__\ /:/__/ \:|__| /:/\:\ \:\__\ /:/\:\ \:\__\ /:/\:\ \:\__\ *
ĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦ \:\~\:\ \/__/ \:\ \ /:/ / \:\~\:\ \/__/ \/_|::\/:/ / \/__\:\/:/ / *
* ĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦĦ * \:\ \:\__\ \:\ /:/ / \:\ \:\__\ |:|::/ / \::/ / *
** ĦĦĦĦ ĦĦĦĦ ** \:\ \/__/ \:\/:/ / \:\ \/__/ |:|\/__/ /:/ / *
*** ĦĦĦĦ ĦĦĦĦ *** \:\__\ \::/__/ \:\__\ |:| | /:/ / *
**** **** \/__/ ~~ \/__/ \|__| \/__/ *
****** ****** *
********* ********* *
************ ************ *
**************** ****************************************************************************************


#### Starting Hedera Services Node Software ####


EOF

echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN USER IDENT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
id
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< END USER IDENT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
echo

echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN JAVA VERSION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
/usr/bin/env java -version
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< END JAVA VERSION <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"
echo

set +e
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN NODE OUTPUT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
/usr/bin/env java ${JAVA_HEAP_OPTS} ${JAVA_OPTS} -cp "${JAVA_CLASS_PATH}" "${JAVA_MAIN_CLASS}"

Check warning on line 103 in docker/ubi8-init-java21/entrypoint.sh

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

docker/ubi8-init-java21/entrypoint.sh#L103

Double quote to prevent globbing and word splitting.
EC="${?}"
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< END NODE OUTPUT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"

echo
echo ">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> BEGIN EXIT CODE >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>"
printf "Process Exit Code: %s\n" "${EC}"
echo "<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< END EXIT CODE <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<"

printf "\n\n#### Hedera Services Node Software Stopped ####\n\n"
18 changes: 18 additions & 0 deletions docker/ubi8-init-java21/network-node.service
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[Unit]
Description=Hedera Network Node
After=network.target

[Service]
Type=simple
Restart=no
User=hedera
Group=hedera

PassEnvironment=JAVA_HOME JAVA_OPTS JAVA_HEAP_MIN JAVA_HEAP_MAX PATH APP_HOME
EnvironmentFile=/etc/network-node/application.env

WorkingDirectory=/opt/hgcapp/services-hedera/HapiApp2.0
ExecStart=/usr/bin/bash /etc/network-node/entrypoint.sh

[Install]
WantedBy=multi-user.target
4 changes: 3 additions & 1 deletion settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2023 Hedera Hashgraph, LLC
* Copyright (C) 2023-2024 Hedera Hashgraph, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,6 +29,8 @@ include(":docker-ubi8-init-dind", "docker/ubi8-init-dind")

include(":docker-ubi8-init-java17", "docker/ubi8-init-java17")

include(":docker-ubi8-init-java21", "docker/ubi8-init-java21")

include(":fullstack-bom", "fullstack-core/fullstack-bom")

include(":fullstack-alerting-api", "fullstack-core/fullstack-alerting-api")
Expand Down
Loading