Skip to content

Commit 91d862a

Browse files
committed
feat: add support for RedHat OpenJDK via Adoptium Marketplace
Closes #47
1 parent 8fcff34 commit 91d862a

File tree

2 files changed

+159
-0
lines changed

2 files changed

+159
-0
lines changed

bin/redhat.bash

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
set -Euo pipefail
4+
5+
TEMP_DIR=$(mktemp -d)
6+
trap 'rm -rf ${TEMP_DIR}' EXIT
7+
8+
if [[ "$#" -lt 2 ]]
9+
then
10+
echo "Usage: ${0} metadata-directory checksum-directory"
11+
exit 1
12+
fi
13+
14+
# shellcheck source=bin/functions.bash
15+
source "$(dirname "${0}")/functions.bash"
16+
17+
VENDOR='redhat'
18+
METADATA_DIR="${1}/${VENDOR}"
19+
CHECKSUM_DIR="${2}/${VENDOR}"
20+
21+
ensure_directory "${METADATA_DIR}"
22+
ensure_directory "${CHECKSUM_DIR}"
23+
24+
function normalize_version {
25+
local jvm_impl="$1"
26+
local name="$2"
27+
local version="$3"
28+
29+
if [[ "${jvm_impl}" == "openj9" ]] && [[ "${name}" =~ "openj9" ]] && [[ ! "${version}" =~ "openj9" ]]
30+
then
31+
local openj9_version
32+
openj9_version=$(echo "${name}" | perl -pe 's/^.*(?:[_-](openj9[-_]\d+\.\d+\.\d+[a-z]?)){1,}.*\..+$/$1/')
33+
echo "${version}.${openj9_version}"
34+
else
35+
echo "${version}"
36+
fi
37+
}
38+
39+
function normalize_features {
40+
declare -a features
41+
if [[ "${1}" == "large" ]]
42+
then
43+
features+=("large_heap")
44+
fi
45+
echo "${features[@]}"
46+
}
47+
48+
function download {
49+
local json
50+
json=$(echo "$1" | base64 -d)
51+
local filename
52+
filename=$(jq -r '.name' <<< "${json}")
53+
54+
local image_type
55+
image_type="$(jq -r '.image_type' <<< "${json}")"
56+
57+
case "${image_type}" in
58+
jre|jdk)
59+
;;
60+
*)
61+
echo "Skipping non-JRE, non-JDK image ${filename}"
62+
return 0
63+
;;
64+
esac
65+
66+
local ext
67+
# shellcheck disable=SC2016
68+
ext=$(echo "${filename}" | perl -pe 's/^.*\.(zip|tar\.gz|tar\.xz)$/$1/g')
69+
local url
70+
url=$(jq -r '.link' <<< "${json}")
71+
local archive="${METADATA_DIR}/${filename}"
72+
73+
local version
74+
version="$(jq -r '.version' <<< "${json}")"
75+
local jvm_impl
76+
jvm_impl="$(jq -r '.jvm_impl' <<< "${json}")"
77+
local normalized_version
78+
normalized_version="$(normalize_version "${jvm_impl}" "${filename}" "${version}")"
79+
80+
local metadata_file="${METADATA_DIR}/${filename}.json"
81+
if [[ -f "${metadata_file}" ]]
82+
then
83+
echo "Skipping ${filename}"
84+
else
85+
if ! download_file "${url}" "${archive}"
86+
then
87+
echo "Failed to download ${url}"
88+
return 0
89+
fi
90+
91+
local md_json
92+
md_json="$(metadata_json \
93+
"${VENDOR}" \
94+
"${filename}" \
95+
'ga' \
96+
"${normalized_version}" \
97+
"$(jq -r '.java_version' <<< "${json}")" \
98+
"${jvm_impl}" \
99+
"$(normalize_os "$(jq -r '.os' <<< "${json}")")" \
100+
"$(normalize_arch "$(jq -r '.architecture' <<< "${json}")")" \
101+
"${ext}" \
102+
"$(jq -r '.image_type' <<< "${json}")" \
103+
"$(normalize_features "$(jq -r '.heap_size' <<< "${json}")")" \
104+
"${url}" \
105+
"$(hash_file 'md5' "${archive}" "${CHECKSUM_DIR}")" \
106+
"$(hash_file 'sha1' "${archive}" "${CHECKSUM_DIR}")" \
107+
"$(hash_file 'sha256' "${archive}" "${CHECKSUM_DIR}")" \
108+
"$(hash_file 'sha512' "${archive}" "${CHECKSUM_DIR}")" \
109+
"$(file_size "${archive}")" \
110+
"${filename}"
111+
)"
112+
113+
echo "${md_json}" > "${metadata_file}"
114+
rm -f "${METADATA_DIR}/${filename}"
115+
fi
116+
}
117+
118+
RELEASES_FILE="${TEMP_DIR}/available-releases.json"
119+
download_file 'https://marketplace-api.adoptium.net/v1/info/available_releases/redhat' "${RELEASES_FILE}"
120+
AVAILABLE_RELEASES=$(jq '.available_releases[]' "${RELEASES_FILE}")
121+
122+
for release in ${AVAILABLE_RELEASES}
123+
do
124+
page=0
125+
while download_file "https://marketplace-api.adoptium.net/v1/assets/feature_releases/redhat/${release}?page=${page}&page_size=20&sort_order=ASC" "${TEMP_DIR}/release-${release}-${page}.json"
126+
do
127+
page=$((page+1))
128+
done
129+
done
130+
131+
FLATTEN_QUERY='add |
132+
.[] |
133+
[{
134+
release_type: .release_type,
135+
java_version: .version_data.openjdk_version,
136+
version: .version_data.semver,
137+
binary: .binaries[],
138+
}] |
139+
.[] |
140+
{
141+
release_type,
142+
java_version,
143+
version,
144+
architecture: .binary.architecture,
145+
os: .binary.os,
146+
heap_size: .binary.heap_size,
147+
image_type: .binary.image_type,
148+
jvm_impl: .binary.jvm_impl,
149+
link: .binary.package.link,
150+
name: .binary.package.name
151+
} | @base64'
152+
153+
for json_b64 in $(jq -r -s "${FLATTEN_QUERY}" "${TEMP_DIR}"/release-*.json)
154+
do
155+
download "${json_b64}"
156+
done
157+
158+
jq -s -S . "${METADATA_DIR}"/java*.json > "${METADATA_DIR}/all.json"

bin/update.bash

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ vendors=(
6767
"$(cmd 'kona21')"
6868
"$(cmd 'ibm')"
6969
"$(cmd 'jetbrains')"
70+
"$(cmd 'redhat')"
7071
)
7172

7273
printf '%s\n' "${vendors[@]}" | parallel -P 4 --verbose "bash {} ${METADATA_DIR}/vendor ${CHECKSUM_DIR} ; echo \"{} EXIT CODE: \$?\""

0 commit comments

Comments
 (0)