Added image inspecting and check for valid java tag
This commit is contained in:
parent
5f2c645cb6
commit
f8db6b8a23
25
build.py
25
build.py
@ -2,6 +2,7 @@
|
||||
from argparse import ArgumentParser, BooleanOptionalAction
|
||||
from datetime import datetime
|
||||
from re import search
|
||||
from sys import base_prefix
|
||||
from typing import Iterable
|
||||
import docker
|
||||
from ftbtypes import *
|
||||
@ -95,6 +96,24 @@ def get_version_by_description(modpack: ModPackManifest, version_name: str | Non
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
def find_suitable_tag(java_repository: str, java_version: str, ver_to_tag: Callable[[str], str] = lambda x: f"{x}-jre"):
|
||||
java_tag_version = java_version
|
||||
while True:
|
||||
# base_image = f"azul/zulu-openjdk:{java_version}-jre"
|
||||
java_tag = ver_to_tag(java_tag_version)
|
||||
try:
|
||||
print(f"Trying for image: {java_repository} tag {java_tag}!")
|
||||
docker.buildx_imagetools_inspect(java_repository, java_tag)
|
||||
return java_tag
|
||||
except Exception:
|
||||
print(f"Potential base image {java_repository} missing tag {java_tag}!")
|
||||
if '_' in java_tag_version:
|
||||
java_tag_version = java_tag_version[:(java_tag_version.rfind('_'))]
|
||||
elif '.' in java_tag_version:
|
||||
java_tag_version = java_tag_version[:(java_tag_version.rfind('.'))]
|
||||
else:
|
||||
raise Exception(f"Cannot find suitable java base image version for Java {java_version}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
args = parse_arguments()
|
||||
modpack = get_modpack_manifest(args.modpack)
|
||||
@ -116,8 +135,9 @@ if __name__ == "__main__":
|
||||
# java_version = version_without_build(java_target["version"])
|
||||
print(f"Required java version is version {java_target['version']}")
|
||||
java_version = java_target["version"].replace('+', '_')
|
||||
# base_image = f"azul/zulu-openjdk:{java_version}-jre"
|
||||
base_image = f"eclipse-temurin:{java_version}-jre"
|
||||
java_repository = "eclipse-temurin"
|
||||
java_tag = find_suitable_tag(java_repository, java_version)
|
||||
base_image = f"{java_repository}:{java_tag}"
|
||||
print(f"Using docker base image: {base_image}")
|
||||
|
||||
repo = f"hub.cnml.de/{slug}"
|
||||
@ -126,6 +146,7 @@ if __name__ == "__main__":
|
||||
"linux/arm64" if args.arm64 else None,
|
||||
"linux/amd64" if args.amd64 else None
|
||||
]))
|
||||
|
||||
for platform in platforms:
|
||||
installer, checksum = get_installer(modpack, version, platform)
|
||||
tags = list(f"{ver}-{platform[(platform.rfind('/')+1):]}" for ver in semver_version_tags)
|
||||
|
63
docker.py
63
docker.py
@ -1,11 +1,70 @@
|
||||
from subprocess import run
|
||||
from typing import Literal, get_args
|
||||
from subprocess import PIPE, run
|
||||
from typing import Literal, NotRequired, TypedDict, get_args, List
|
||||
from json import loads
|
||||
|
||||
Platforms = Literal["linux/amd64", "linux/amd64/v2", "linux/amd64/v3", "linux/arm64", "linux/riscv64", "linux/ppc64le", "linux/s390x", "linux/386", "linux/mips64le", "linux/mips64", "linux/arm/v7", "linux/arm/v6"]
|
||||
supported_platforms: list[Platforms] = list(get_args(Platforms))
|
||||
|
||||
Progress = Literal["auto", "plain", "tty"]
|
||||
|
||||
class Platform(TypedDict):
|
||||
architecture: str
|
||||
os: str
|
||||
variant: NotRequired[str]
|
||||
|
||||
|
||||
class ManifestsItem(TypedDict):
|
||||
mediaType: str
|
||||
digest: str
|
||||
size: int
|
||||
platform: Platform
|
||||
|
||||
|
||||
class Manifest(TypedDict):
|
||||
schemaVersion: int
|
||||
mediaType: str
|
||||
digest: str
|
||||
size: int
|
||||
manifests: List[ManifestsItem]
|
||||
|
||||
|
||||
class Config(TypedDict):
|
||||
Env: List[str]
|
||||
Cmd: List[str]
|
||||
|
||||
|
||||
class Rootfs(TypedDict):
|
||||
type: str
|
||||
diff_ids: List[str]
|
||||
|
||||
|
||||
class HistoryItem(TypedDict):
|
||||
created: str
|
||||
created_by: str
|
||||
empty_layer: NotRequired[bool]
|
||||
|
||||
|
||||
class PlatformImage(TypedDict):
|
||||
created: str
|
||||
architecture: str
|
||||
variant: NotRequired[str]
|
||||
os: str
|
||||
config: Config
|
||||
rootfs: Rootfs
|
||||
history: List[HistoryItem]
|
||||
|
||||
|
||||
class ImagetoolsInspectResult(TypedDict):
|
||||
name: str
|
||||
manifest: Manifest
|
||||
image: dict[Platform, PlatformImage]
|
||||
|
||||
def buildx_imagetools_inspect(repository: str, tag: str) -> ImagetoolsInspectResult:
|
||||
label = f"{repository}:{tag}"
|
||||
process = run(["docker", "buildx", "imagetools", "inspect", label, "--format", "{{json .}}"], check=True, stdout=PIPE)
|
||||
output = process.stdout.decode("utf-8")
|
||||
return loads(output)
|
||||
|
||||
def semver_tags(version: str):
|
||||
parts = version.split('.')
|
||||
return list('.'.join(parts[:i]) for i in range(1, len(parts) + 1))
|
||||
|
Loading…
Reference in New Issue
Block a user