Aggregate errors

This commit is contained in:
Michael Chen 2022-11-15 09:37:31 +01:00
parent 3bd942d471
commit c3e881d52b
Signed by: cnml
GPG Key ID: 5845BF3F82D5F629

View File

@ -10,8 +10,10 @@ import argparse
from datetime import datetime, timedelta from datetime import datetime, timedelta
ReleaseType = Literal["release", "snapshot", "old_beta", "old_alpha"] ReleaseType = Literal["release", "snapshot", "old_beta", "old_alpha"]
DockerPlatforms = 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"] DockerPlatforms = Literal["linux/amd64", "linux/amd64/v2", "linux/amd64/v3", "linux/arm64", "linux/riscv64",
supported_docker_platforms: list[DockerPlatforms] = ["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"] "linux/ppc64le", "linux/s390x", "linux/386", "linux/mips64le", "linux/mips64", "linux/arm/v7", "linux/arm/v6"]
supported_docker_platforms: list[DockerPlatforms] = ["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"]
class LatestVersions(TypedDict): class LatestVersions(TypedDict):
@ -152,9 +154,11 @@ default_java_version: JavaVersion = {
"majorVersion": 8 "majorVersion": 8
} }
class NoServerException(Exception): class NoServerException(Exception):
pass pass
def build_version(manifest: VersionManifest, version_id: str, repository: str = "hub.cnml.de/minecraft"): def build_version(manifest: VersionManifest, version_id: str, repository: str = "hub.cnml.de/minecraft"):
matching_version = list( matching_version = list(
filter(lambda v: v["id"] == version_id, manifest["versions"])) filter(lambda v: v["id"] == version_id, manifest["versions"]))
@ -167,7 +171,8 @@ def build_version(manifest: VersionManifest, version_id: str, repository: str =
server_jar_file = Path("versions") / version['id'] / "server.jar" server_jar_file = Path("versions") / version['id'] / "server.jar"
server_jar = version["downloads"].get("server") server_jar = version["downloads"].get("server")
if server_jar is None: if server_jar is None:
raise NoServerException(f"No server build exists for {version['id']} (Java {java_version['majorVersion']})") raise NoServerException(
f"No server build exists for {version['id']} (Java {java_version['majorVersion']})")
download_file(server_jar, server_jar_file) download_file(server_jar, server_jar_file)
@ -177,19 +182,23 @@ def build_version(manifest: VersionManifest, version_id: str, repository: str =
"DOCKER_IMAGE": "" "DOCKER_IMAGE": ""
} }
print(f"Building version {version['id']} (Java {java_version['majorVersion']})") print(
f"Building version {version['id']} (Java {java_version['majorVersion']})")
# Build GraalVM images # Build GraalVM images
if java_version['majorVersion'] == 17: if java_version['majorVersion'] == 17:
graal_platforms: list[DockerPlatforms] = ["linux/arm64", "linux/amd64"] graal_platforms: list[DockerPlatforms] = ["linux/arm64", "linux/amd64"]
build_args["DOCKER_IMAGE"] = f"ghcr.io/graalvm/jdk:java{java_version['majorVersion']}" build_args["DOCKER_IMAGE"] = f"ghcr.io/graalvm/jdk:java{java_version['majorVersion']}"
docker_buildx(repository, [f"{version['id']}-graalvm"], graal_platforms, build_args=build_args) docker_buildx(repository, [
f"{version['id']}-graalvm"], graal_platforms, build_args=build_args)
else: else:
print(f"No GraalVM image can be built for {version['id']} (Java {java_version['majorVersion']})") print(
f"No GraalVM image can be built for {version['id']} (Java {java_version['majorVersion']})")
# Build Temurin # Build Temurin
build_args["DOCKER_IMAGE"] = f"eclipse-temurin:{java_version['majorVersion']}-jre" build_args["DOCKER_IMAGE"] = f"eclipse-temurin:{java_version['majorVersion']}-jre"
temurin_platforms: list[DockerPlatforms] = ["linux/arm64", "linux/arm/v7", "linux/amd64", "linux/ppc64le"] temurin_platforms: list[DockerPlatforms] = [
"linux/arm64", "linux/arm/v7", "linux/amd64", "linux/ppc64le"]
docker_buildx( docker_buildx(
repository, [version["id"], f"{version['id']}-temurin"], temurin_platforms, build_args=build_args) repository, [version["id"], f"{version['id']}-temurin"], temurin_platforms, build_args=build_args)
@ -209,15 +218,21 @@ if __name__ == "__main__":
manifest = load_manifest(args.reload) manifest = load_manifest(args.reload)
versions: list[str] = list(version["id"] for version in manifest["versions"] versions: list[str] = list(version["id"] for version in manifest["versions"]
if version["type"] == "release") if args.all else args.versions if version["type"] == "release") if args.all else args.versions
errors: list[tuple[str, Exception]] = []
for version_id in versions: for version_id in versions:
print() print()
try: try:
build_version(manifest, version_id) build_version(manifest, version_id)
except NoServerException as e: except NoServerException as e:
print(e) print(e)
errors.append((version_id, e))
except Exception as e: except Exception as e:
print(f"Failed building images for version {version_id}") print(f"Failed building images for version {version_id}")
if args.force: if args.force:
print(e) print(e)
errors.append((version_id, e))
else: else:
raise raise
for (version_id, e) in errors:
print(f"Error building version {version_id}:\n\t{e}")