Skip to content

Commit

Permalink
implement jinja templating to handle linux installer updates
Browse files Browse the repository at this point in the history
  • Loading branch information
gdams committed Sep 16, 2024
1 parent 45d34f1 commit d618bc0
Show file tree
Hide file tree
Showing 15 changed files with 458 additions and 113 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,9 @@ Thumbs.db

node_modules/
wix/Workdir/


lib/
bin/
.venv/
adoptium_cache.sqlite
17 changes: 17 additions & 0 deletions linux/config/temurin.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#
# 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
#
# https://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.
#

supported_distributions:
Distros: [alpine]
Versions: [8, 11, 17, 21, 22]
110 changes: 110 additions & 0 deletions linux/generate-linux-specs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# 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
#
# https://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.
#

import os

import requests
import requests_cache
import yaml
from jinja2 import Environment, FileSystemLoader

requests_cache.install_cache("adoptium_cache", expire_after=3600)

# Setup the Jinja2 environment
env = Environment(loader=FileSystemLoader("templates"))

headers = {
"User-Agent": "Adoptium Linux Specfile Updater",
}


def archHelper(arch):
if arch == "x64":
return "x86_64"
else:
return arch


# Load the YAML configuration
with open("config/temurin.yml", "r") as file:
config = yaml.safe_load(file)

for image_type in ["jdk", "jre"]:
# Iterate through supported_distributions
for distro in config["supported_distributions"]["Distros"]:
for version in config["supported_distributions"]["Versions"]:

# Fetch latest release for version from Adoptium API
url = f"https://api.adoptium.net/v3/assets/feature_releases/{version}/ga?page=0&image_type={image_type}&os=alpine-linux&page_size=1&vendor=eclipse"
response = requests.get(url, headers=headers)
response.raise_for_status()
data = response.json()

release = response.json()[0]

# Extract the version number from the release name
openjdk_version = release["release_name"]

# If version doesn't equal 8, get the more accurate version number
if version != 8:
openjdk_version = release["version_data"]["openjdk_version"]
# if openjdk_version contains -LTS remove it
if "-LTS" in openjdk_version:
openjdk_version = openjdk_version.replace("-LTS", "")

# Convert version from 11.0.24+8 to 11.0.24_p8
openjdk_version = openjdk_version.replace("jdk", "")
openjdk_version = openjdk_version.replace("+", "_p")
openjdk_version = openjdk_version.replace("u", ".")
openjdk_version = openjdk_version.replace("-b", ".")

# Generate the data for each architecture
arch_data = {}

for binary in release["binaries"]:
arch_data[archHelper(binary["architecture"])] = {
"download_url": binary["package"]["link"],
"checksum": binary["package"]["checksum"],
"filename": binary["package"]["name"],
}

# Set path to the specfiles
path = f"{image_type}/{distro}/src/main/packaging/temurin/{version}"

# Check that the path exists
os.makedirs(path, exist_ok=True)

# Load the template
template = env.get_template(f"{distro}.spec.j2")

# Render the template
rendered = template.render(
arch_data=arch_data,
openjdk_version=openjdk_version,
release_name=release["release_name"],
version=version,
image_type=image_type,
)

# Set filename based on switch distro e.g APKBUILD for alpine, spec for others
match distro:
case "alpine":
filename = "APKBUILD"
case _:
print(f"Unsupported distro: {distro}")
exit(1)

# Write the rendered template to the file
with open(f"{path}/{filename}", "w") as file:
file.write(rendered)
print(f"Generated {path}/{filename}")
25 changes: 14 additions & 11 deletions linux/jdk/alpine/src/main/packaging/temurin/11/APKBUILD
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Maintainer: Eclipse Adoptium Package Maintainers <[email protected]>
pkgname=temurin-11
pkgver=11.0.24_p8
# replace _p1 with _1
_pkgver=${pkgver/_p/_}
_pkgverplus=${pkgver/_p/+}
_pkgvername=${_pkgverplus/+/%2B}
pkgrel=1
pkgrel=0
pkgdesc="Eclipse Temurin 11"
provider_priority=11
url="https://adoptium.net"
arch="noarch"
arch="x86_64"
license="GPL-2.0-with-classpath-exception"
makedepends="
alsa-lib-dev
Expand All @@ -25,8 +21,9 @@ makedepends="
"
depends=""
subpackages="$pkgname-src:_src:noarch
$pkgname-jdk:_jdk:x86_64"
source="https://github.com/adoptium/temurin11-binaries/releases/download/jdk-$_pkgvername/OpenJDK11U-jdk_x64_alpine-linux_hotspot_$_pkgver.tar.gz
$pkgname-jdk:_jdk"
source="
https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.24%2B8/OpenJDK11U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_11.0.24_8.tar.gz
HelloWorld.java
TestECDSA.java
Expand All @@ -43,7 +40,7 @@ prepare() {
}

check() {
local _java_bin="./jdk-$_pkgverplus/bin"
local _java_bin="./jdk-11.0.24+8/bin"

# 1) compile and run a simple hello world
$_java_bin/javac -d . "$srcdir"/HelloWorld.java
Expand All @@ -60,7 +57,7 @@ check() {

package() {
mkdir -p "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-"$_pkgverplus"/* "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-11.0.24+8/* "$pkgdir/$_java_home"
}

_src() {
Expand Down Expand Up @@ -94,8 +91,14 @@ _jdk() {
"$_toroot/lib/security/cacerts"
}

case "$CARCH" in
x86_64)
_arch_sum="ae988c72eeb2d78bb729a3387601ce0ea84305734ebdbe95d276f39952a8e019"
;;
esac

sha256sums="
ae988c72eeb2d78bb729a3387601ce0ea84305734ebdbe95d276f39952a8e019 OpenJDK11U-jdk_x64_alpine-linux_hotspot_$_pkgver.tar.gz
$_arch_sum OpenJDK11U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_11.0.24_8.tar.gz
e9185736dde99a4dc570a645a20407bdb41c1f48dfc34d9c3eb246cf0435a378 HelloWorld.java
22d2ff9757549ebc64e09afd3423f84b5690dcf972cd6535211c07c66d38fab0 TestCryptoLevel.java
9fb00c7b0220de8f3ee2aa398459a37d119f43fd63321530a00b3bb9217dd933 TestECDSA.java
Expand Down
25 changes: 14 additions & 11 deletions linux/jdk/alpine/src/main/packaging/temurin/17/APKBUILD
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
# Maintainer: Eclipse Adoptium Package Maintainers <[email protected]>
pkgname=temurin-17
pkgver=17.0.12_p7
# replace _p1 with _1
_pkgver=${pkgver/_p/_}
_pkgverplus=${pkgver/_p/+}
_pkgvername=${_pkgverplus/+/%2B}
pkgrel=1
pkgrel=0
pkgdesc="Eclipse Temurin 17"
provider_priority=17
url="https://adoptium.net"
arch="noarch"
arch="x86_64"
license="GPL-2.0-with-classpath-exception"
makedepends="
alsa-lib-dev
Expand All @@ -25,8 +21,9 @@ makedepends="
"
depends=""
subpackages="$pkgname-src:_src:noarch
$pkgname-jdk:_jdk:x86_64"
source="https://github.com/adoptium/temurin17-binaries/releases/download/jdk-$_pkgvername/OpenJDK17U-jdk_x64_alpine-linux_hotspot_$_pkgver.tar.gz
$pkgname-jdk:_jdk"
source="
https://github.com/adoptium/temurin17-binaries/releases/download/jdk-17.0.12%2B7/OpenJDK17U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_17.0.12_7.tar.gz
HelloWorld.java
TestECDSA.java
Expand All @@ -43,7 +40,7 @@ prepare() {
}

check() {
local _java_bin="./jdk-$_pkgverplus/bin"
local _java_bin="./jdk-17.0.12+7/bin"

# 1) compile and run a simple hello world
$_java_bin/javac -d . "$srcdir"/HelloWorld.java
Expand All @@ -60,7 +57,7 @@ check() {

package() {
mkdir -p "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-"$_pkgverplus"/* "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-17.0.12+7/* "$pkgdir/$_java_home"
}

_src() {
Expand Down Expand Up @@ -94,8 +91,14 @@ _jdk() {
"$_toroot/lib/security/cacerts"
}

case "$CARCH" in
x86_64)
_arch_sum="6d274a292a717a6f8d00a3ed0695497405c5c634c27fec1692dd13784f6ff6fa"
;;
esac

sha256sums="
6d274a292a717a6f8d00a3ed0695497405c5c634c27fec1692dd13784f6ff6fa OpenJDK17U-jdk_x64_alpine-linux_hotspot_$_pkgver.tar.gz
$_arch_sum OpenJDK17U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_17.0.12_7.tar.gz
e9185736dde99a4dc570a645a20407bdb41c1f48dfc34d9c3eb246cf0435a378 HelloWorld.java
22d2ff9757549ebc64e09afd3423f84b5690dcf972cd6535211c07c66d38fab0 TestCryptoLevel.java
9fb00c7b0220de8f3ee2aa398459a37d119f43fd63321530a00b3bb9217dd933 TestECDSA.java
Expand Down
20 changes: 8 additions & 12 deletions linux/jdk/alpine/src/main/packaging/temurin/21/APKBUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Maintainer: Eclipse Adoptium Package Maintainers <[email protected]>
pkgname=temurin-21
pkgver=21.0.4_p7
# replace _p1 with _1
_pkgver=${pkgver/_p/_}
_pkgverplus=${pkgver/_p/+}
_pkgvername=${_pkgverplus/+/%2B}
pkgrel=1
pkgrel=0
pkgdesc="Eclipse Temurin 21"
provider_priority=21
url="https://adoptium.net"
Expand All @@ -27,7 +23,7 @@ depends=""
subpackages="$pkgname-src:_src:noarch
$pkgname-jdk:_jdk"
source="
https://github.com/adoptium/temurin21-binaries/releases/download/jdk-$_pkgvername/OpenJDK21u-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_$_pkgver.tar.gz
https://github.com/adoptium/temurin21-binaries/releases/download/jdk-21.0.4%2B7/OpenJDK21U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_21.0.4_7.tar.gz
HelloWorld.java
TestECDSA.java
Expand All @@ -44,7 +40,7 @@ prepare() {
}

check() {
local _java_bin="./jdk-$_pkgverplus/bin"
local _java_bin="./jdk-21.0.4+7/bin"

# 1) compile and run a simple hello world
$_java_bin/javac -d . "$srcdir"/HelloWorld.java
Expand All @@ -61,7 +57,7 @@ check() {

package() {
mkdir -p "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-"$_pkgverplus"/* "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-21.0.4+7/* "$pkgdir/$_java_home"
}

_src() {
Expand Down Expand Up @@ -96,16 +92,16 @@ _jdk() {
}

case "$CARCH" in
x86_64)
_arch_sum="8fa232fc9de5a861c1a6b0cbdc861d0b0a2bdbdd27da53d991802a460a7f0973"
;;
aarch64)
_arch_sum="849c6d5a62a1f3dc2a3d2d7be07ffda089d35b862f6160b2a288c0408c2d8be8"
;;
x86_64)
_arch_sum="8fa232fc9de5a861c1a6b0cbdc861d0b0a2bdbdd27da53d991802a460a7f0973"
;;
esac

sha256sums="
$_arch_sum OpenJDK21u-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_$_pkgver.tar.gz
$_arch_sum OpenJDK21U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_21.0.4_7.tar.gz
e9185736dde99a4dc570a645a20407bdb41c1f48dfc34d9c3eb246cf0435a378 HelloWorld.java
22d2ff9757549ebc64e09afd3423f84b5690dcf972cd6535211c07c66d38fab0 TestCryptoLevel.java
9fb00c7b0220de8f3ee2aa398459a37d119f43fd63321530a00b3bb9217dd933 TestECDSA.java
Expand Down
20 changes: 8 additions & 12 deletions linux/jdk/alpine/src/main/packaging/temurin/22/APKBUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
# Maintainer: Eclipse Adoptium Package Maintainers <[email protected]>
pkgname=temurin-22
pkgver=22.0.2_p9
# replace _p1 with _1
_pkgver=${pkgver/_p/_}
_pkgverplus=${pkgver/_p/+}
_pkgvername=${_pkgverplus/+/%2B}
pkgrel=1
pkgrel=0
pkgdesc="Eclipse Temurin 22"
provider_priority=22
url="https://adoptium.net"
Expand All @@ -27,7 +23,7 @@ depends=""
subpackages="$pkgname-src:_src:noarch
$pkgname-jdk:_jdk"
source="
https://github.com/adoptium/temurin22-binaries/releases/download/jdk-$_pkgvername/OpenJDK22u-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_$_pkgver.tar.gz
https://github.com/adoptium/temurin22-binaries/releases/download/jdk-22.0.2%2B9/OpenJDK22U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_22.0.2_9.tar.gz
HelloWorld.java
TestECDSA.java
Expand All @@ -44,7 +40,7 @@ prepare() {
}

check() {
local _java_bin="./jdk-$_pkgverplus/bin"
local _java_bin="./jdk-22.0.2+9/bin"

# 1) compile and run a simple hello world
$_java_bin/javac -d . "$srcdir"/HelloWorld.java
Expand All @@ -61,7 +57,7 @@ check() {

package() {
mkdir -p "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-"$_pkgverplus"/* "$pkgdir/$_java_home"
cp -r "$srcdir"/jdk-22.0.2+9/* "$pkgdir/$_java_home"
}

_src() {
Expand Down Expand Up @@ -96,16 +92,16 @@ _jdk() {
}

case "$CARCH" in
x86_64)
_arch_sum="49f73414824b1a7c268a611225fa4d7ce5e25600201e0f1cd59f94d1040b5264"
;;
aarch64)
_arch_sum="8ac93a2d5a55aabbc0f7156c2f9032026e87c185689d628ef8a4184b6e9ab006"
;;
x86_64)
_arch_sum="49f73414824b1a7c268a611225fa4d7ce5e25600201e0f1cd59f94d1040b5264"
;;
esac

sha256sums="
$_arch_sum OpenJDK22u-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_$_pkgver.tar.gz
$_arch_sum OpenJDK22U-jdk_${CARCH/x86_64/x64}_alpine-linux_hotspot_22.0.2_9.tar.gz
e9185736dde99a4dc570a645a20407bdb41c1f48dfc34d9c3eb246cf0435a378 HelloWorld.java
22d2ff9757549ebc64e09afd3423f84b5690dcf972cd6535211c07c66d38fab0 TestCryptoLevel.java
9fb00c7b0220de8f3ee2aa398459a37d119f43fd63321530a00b3bb9217dd933 TestECDSA.java
Expand Down
Loading

0 comments on commit d618bc0

Please sign in to comment.