Skip to content

Commit

Permalink
feat: Bump JDK21 to Temurin 21+35 LTS version (#860)
Browse files Browse the repository at this point in the history
* fix: Use Temurin JDK21 stable URLs

fixup of #839

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>

* feat: bump JDK21 to 21+35 GA stable

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>

---------

Signed-off-by: Damien Duportal <damien.duportal@gmail.com>
  • Loading branch information
dduportal authored Oct 19, 2023
1 parent 6f6a95b commit ae50ed8
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 44 deletions.
2 changes: 1 addition & 1 deletion goss/goss.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ command:
exec: /opt/jdk-21/bin/java --version
exit-status: 0
stdout:
- 21-beta
- 21+35
trivy:
exec: trivy --version
exit-status: 0
Expand Down
2 changes: 1 addition & 1 deletion provisioning/tools-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ goss_version: 0.4.2
hadolint_version: 2.12.0
jdk11_version: 11.0.21+9
jdk17_version: 17.0.8.1+1
jdk21_version: 21+35-ea-beta
jdk21_version: 21+35
jdk8_version: 8u382-b05
jenkins_remoting_version: 3174.v2c9e67f8f9df
jq_version: 1.6
Expand Down
90 changes: 49 additions & 41 deletions provisioning/ubuntu-provision.sh
Original file line number Diff line number Diff line change
Expand Up @@ -280,55 +280,63 @@ function install_git_gitlfs() {
rm -rf /tmp/git-lfs*
}

function install_jdk() {
apt-get update --quiet
## Prevent Java null pointer exception due to missing fontconfig / add jq that should already be installed but make this install_jdk function idempotent
apt-get install --yes --no-install-recommends fontconfig jq="${JQ_VERSION}*"
# Reusable function to perform a Temurin JDK installations
function download_temurin_jdk() {
JDK_VERSION="$1"

## OpenJDKs: Adoptium - https://adoptium.net/installation.html
for jdkVersion in 8 11 17 21; do
mkdir -p "/opt/jdk-$jdkVersion"
done
local jdk_short_version major_jdk_version cpu_arch_short download_url

# JDK8
jdk8_short_version="${JDK8_VERSION//-/}"
cpu_arch_short="$(uname -m)"
if test "${cpu_arch_short}" == "x86_64"
if test "${cpu_arch_short}" == 'x86_64'
then
# Damn :'(
cpu_arch_short="x64"
# Custom Temurin Architecture ID...
cpu_arch_short='x64'
fi
curl -sSL -o /tmp/jdk8.tgz \
"https://github.com/adoptium/temurin8-binaries/releases/download/jdk${JDK8_VERSION}/OpenJDK8U-jdk_${cpu_arch_short}_linux_hotspot_${jdk8_short_version}.tar.gz"
tar --extract --gunzip --file=/tmp/jdk8.tgz --directory=/opt/jdk-8 --strip-components=1

# JDK11
jdk11_short_version="${JDK11_VERSION//+/_}"
curl -sSL -o /tmp/jdk11.tgz \
"https://github.com/adoptium/temurin11-binaries/releases/download/jdk-${JDK11_VERSION}/OpenJDK11U-jdk_${cpu_arch_short}_linux_hotspot_${jdk11_short_version}.tar.gz"
tar --extract --gunzip --file=/tmp/jdk11.tgz --directory=/opt/jdk-11 --strip-components=1

# JDK17
jdk17_short_version="${JDK17_VERSION//+/_}"
curl -sSL -o /tmp/jdk17.tgz \
"https://github.com/adoptium/temurin17-binaries/releases/download/jdk-${JDK17_VERSION}/OpenJDK17U-jdk_${cpu_arch_short}_linux_hotspot_${jdk17_short_version}.tar.gz"
tar --extract --gunzip --file=/tmp/jdk17.tgz --directory=/opt/jdk-17 --strip-components=1

# JDK21 https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21%2B35-ea-beta/OpenJDK21U-jdk_x64_linux_hotspot_ea_21-0-35.tar.gz
jdk21_version_urlencoded=$(echo "$JDK21_VERSION" | jq "@uri" -jRr)
jdk21_build_number="${JDK21_VERSION##*+}"
curl -sSL -o /tmp/jdk21.tgz \
"https://github.com/adoptium/temurin21-binaries/releases/download/jdk-${jdk21_version_urlencoded}/OpenJDK21U-jdk_${cpu_arch_short}_linux_hotspot_ea_21-0-${jdk21_build_number//-ea-beta/}.tar.gz"
tar --extract --gunzip --file=/tmp/jdk21.tgz --directory=/opt/jdk-21 --strip-components=1

# JDK8 has different URL pattern
if test "${JDK_VERSION:0:2}" == '8u'
then
jdk_short_version="${JDK_VERSION//-/}"
major_jdk_version='8'
download_url="https://github.com/adoptium/temurin8-binaries/releases/download/jdk${JDK_VERSION}/OpenJDK8U-jdk_${cpu_arch_short}_linux_hotspot_${jdk_short_version}.tar.gz"
else
jdk_short_version="${JDK_VERSION//+/_}"
major_jdk_version="$(\
echo "${JDK_VERSION%+*}" `# Remove suffix after any eventual '+' character` \
| cut -d'.' -f1 `# Only keep the first number (there can be no '.' or multiple)` \
)"
download_url="https://github.com/adoptium/temurin${major_jdk_version}-binaries/releases/download/jdk-${JDK_VERSION}/OpenJDK${major_jdk_version}U-jdk_${cpu_arch_short}_linux_hotspot_${jdk_short_version}.tar.gz"
fi

local temp_archive="/tmp/jdk${major_jdk_version}.tgz"
local installation_dir="/opt/jdk-$major_jdk_version"

curl --fail --silent --show-error --location --output "${temp_archive}" "${download_url}"

mkdir -p "${installation_dir}"
tar --extract --gunzip --file="${temp_archive}" --directory="${installation_dir}" --strip-components=1

# Define JDK installations
# The priority of a JDK is the last argument.
# Starts by setting priority to the JDK major version: higher version is the expected default
update-alternatives --install /usr/bin/java java /opt/jdk-8/bin/java 8
update-alternatives --install /usr/bin/java java /opt/jdk-11/bin/java 11
update-alternatives --install /usr/bin/java java /opt/jdk-17/bin/java 17
update-alternatives --install /usr/bin/java java /opt/jdk-21/bin/java 21
# Then, use the DEFAULT_JDK env var to set the priority of the specified default JDK to 1000 to ensure its the one used by update-alternatives
update-alternatives --install /usr/bin/java java "${installation_dir}"/bin/java "${major_jdk_version}"

rm -f "${temp_archive}"
}

function install_jdks() {
apt-get update --quiet
## Prevent Java null pointer exception due to missing fontconfig / add jq that should already be installed but make this install_jdk function idempotent
apt-get install --yes --no-install-recommends fontconfig jq="${JQ_VERSION}*"

for jdk_version_to_install in "${JDK8_VERSION}" "${JDK11_VERSION}" "${JDK17_VERSION}" "${JDK21_VERSION}"
do
echo "=== Installing Temurin JDK version ${jdk_version_to_install}..."
download_temurin_jdk "${jdk_version_to_install}"
echo "=== Installation of Temurin JDK version ${jdk_version_to_install} done."
done

# Use the DEFAULT_JDK env var to set the priority of the specified default JDK to 1000 to ensure its the one used by update-alternatives
update-alternatives --install /usr/bin/java java "/opt/jdk-${DEFAULT_JDK}/bin/java" 1000
echo "JAVA_HOME=/opt/jdk-${DEFAULT_JDK}" >> /etc/environment
}
Expand Down Expand Up @@ -695,7 +703,7 @@ function main() {
install_asdf # Before all the others but after the jenkins home is created
install_goss # needed by the pipeline
install_docker # needed by the pipeline
install_jdk # needed by the pipeline
install_jdks # needed by the pipeline
install_chromium
install_datadog
install_JA_requirements
Expand Down
2 changes: 1 addition & 1 deletion provisioning/windows-provision.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ $downloads = [ordered]@{
}
};
'jdk21' = @{
'url' = 'https://github.com/adoptium/temurin21-binaries/releases/download/jdk-{0}/OpenJDK21U-jdk_x64_windows_hotspot_ea_21-0-{1}.zip' -f [System.Web.HTTPUtility]::UrlEncode($env:JDK21_VERSION),$env:JDK21_VERSION.Split('[+-]')[1];
'url' = 'https://github.com/adoptium/temurin21-binaries/releases/download/jdk-{0}/OpenJDK21U-jdk_x64_windows_hotspot_{1}.zip' -f [System.Web.HTTPUtility]::UrlEncode($env:JDK21_VERSION),$env:JDK21_VERSION.Replace('+', '_');
'local' = "$baseDir\temurin21.zip";
'expandTo' = $baseDir;
'postExpand' = {
Expand Down

0 comments on commit ae50ed8

Please sign in to comment.