Build graalVM only for multiplatform version 17

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

View File

@ -10,6 +10,8 @@ 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"]
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):
@ -59,6 +61,7 @@ class DockerfileBuildArgs(TypedDict):
VERSION_ID: str VERSION_ID: str
VERSION_SHA1: str VERSION_SHA1: str
class VersionManifest(TypedDict): class VersionManifest(TypedDict):
latest: LatestVersions latest: LatestVersions
versions: list[Version] versions: list[Version]
@ -129,12 +132,7 @@ def download_file(file: DownloadInfo, filename: Path):
return filename return filename
default_build_platforms = ["linux/arm64/v8", "linux/arm/v7", "linux/amd64", "linux/ppc64le"] def docker_buildx(repository: str, tags: list[str], build_platforms: list[DockerPlatforms], dockerfile: str = "Dockerfile", build_args: DockerfileBuildArgs | dict[str, Any] | None = None, directory: str = "."):
def docker_buildx(repository: str, tags: list[str], build_platforms: list[str] | None = None, dockerfile: str = "Dockerfile", build_args: DockerfileBuildArgs | dict[str, Any] | None = None, directory: str = "."):
if build_platforms is None:
build_platforms = default_build_platforms
if build_args is None: if build_args is None:
build_args = dict() build_args = dict()
labels = [f"{repository}:{tag}"for tag in tags] labels = [f"{repository}:{tag}"for tag in tags]
@ -168,13 +166,21 @@ def build_version(manifest: VersionManifest, version_id: str, repository: str =
"DOCKER_IMAGE": "" "DOCKER_IMAGE": ""
} }
print(f"Building version {version['id']} (Java {java_version['majorVersion']})")
# Build GraalVM images # Build GraalVM images
if java_version['majorVersion'] == 17:
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, [version["id"], f"{version['id']}-graalvm"], build_args=build_args, build_platforms=["linux/amd64", "linux/arm64"]) docker_buildx(repository, [f"{version['id']}-graalvm"], graal_platforms, build_args=build_args)
else:
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"
docker_buildx(repository, [f"{version['id']}-temurin"], build_args=build_args) temurin_platforms: list[DockerPlatforms] = ["linux/arm64", "linux/arm/v7", "linux/amd64", "linux/ppc64le"]
docker_buildx(
repository, [version["id"], f"{version['id']}-temurin"], temurin_platforms, build_args=build_args)
if __name__ == "__main__": if __name__ == "__main__":
@ -182,13 +188,20 @@ if __name__ == "__main__":
"build", description="Utility script to build docker images for Minecraft servers.") "build", description="Utility script to build docker images for Minecraft servers.")
parser.add_argument("versions", nargs="*", type=str, parser.add_argument("versions", nargs="*", type=str,
help="Versions to build for.") help="Versions to build for.")
parser.add_argument("--reload", action="store_true", help="Force reload the manifest.") parser.add_argument("--reload", action="store_true",
parser.add_argument("--all", action="store_true", help="Build all versions.") help="Force reload the manifest.")
parser.add_argument("--all", action="store_true",
help="Build all versions.")
parser.add_argument("--force", action="store_true",
help="Force continue on single version build failure.")
args = parser.parse_args() args = parser.parse_args()
manifest = load_manifest(args.reload) manifest = load_manifest(args.reload)
versions: list[str] = list(version["id"] for version in manifest["versions"] if version["type"] == "release") if args.all else args.versions versions: list[str] = list(version["id"] for version in manifest["versions"]
if version["type"] == "release") if args.all else args.versions
for version_id in versions: for version_id in versions:
try: try:
build_version(manifest, version_id) build_version(manifest, version_id)
except Exception as e: except Exception as e:
print(f"Failed building images for version {version_id}:\n\t{e}") print(f"Failed building images for version {version_id}:\n\t{e}")
if not args.force:
break