Added fallback java 8 version if not specified

This commit is contained in:
Michael Chen 2022-11-15 09:15:48 +01:00
parent 334f1f3e56
commit 8aa106d5bc
Signed by: cnml
GPG Key ID: 5845BF3F82D5F629

View File

@ -1,6 +1,6 @@
#!/usr/bin/env python3
import hashlib
from typing import Any, Literal, TypedDict
from typing import Any, Literal, NotRequired, TypedDict
from pathlib import Path
import urllib.request
import json
@ -52,7 +52,7 @@ class VersionManifestFull(TypedDict):
time: str
releaseTime: str
minimumLauncherVersion: int
javaVersion: JavaVersion
javaVersion: NotRequired[JavaVersion]
downloads: VersionDownloads
@ -147,13 +147,18 @@ def docker_buildx(repository: str, tags: list[str], build_platforms: list[Docker
subprocess.run(command)
default_java_version: JavaVersion = {
"component": "jre",
"majorVersion": 8
}
def build_version(manifest: VersionManifest, version_id: str, repository: str = "hub.cnml.de/minecraft"):
matching_version = list(
filter(lambda v: v["id"] == version_id, manifest["versions"]))
if len(matching_version) == 0:
raise Exception(f"Version {version_id} not found in manifest!")
version = load_version_manifest(matching_version[0])
java_version = version['javaVersion']
java_version = version.get("javaVersion", default_java_version)
print(
f"Version [{version['type']}] {version['id']} requires java version {java_version['majorVersion']} ({java_version['component']})")
server_jar_file = Path("versions") / version['id'] / "server.jar"
@ -202,6 +207,8 @@ if __name__ == "__main__":
try:
build_version(manifest, version_id)
except Exception as e:
print(f"Failed building images for version {version_id}:\n\t{e}")
if not args.force:
break
print(f"Failed building images for version {version_id}")
if args.force:
print(e)
else:
raise