mirror of
https://github.com/jupyter/docker-stacks.git
synced 2025-10-12 20:42:57 +00:00
Rewrite generate_matrix.py
This commit is contained in:
@@ -3,39 +3,53 @@
|
|||||||
# Distributed under the terms of the Modified BSD License.
|
# Distributed under the terms of the Modified BSD License.
|
||||||
import json
|
import json
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from typing import Any
|
|
||||||
|
|
||||||
THIS_DIR = Path(__file__).parent.resolve()
|
THIS_DIR = Path(__file__).parent.resolve()
|
||||||
|
|
||||||
|
RUNS_ON = ["ubuntu-24.04", "ubuntu-24.04-arm"]
|
||||||
|
ARM_INCOMPATIBLE_IMAGES = {"oracledb.dockerfile"}
|
||||||
|
BASE_IMAGE_PREFIX = "ARG BASE_IMAGE="
|
||||||
|
|
||||||
def generate_matrix() -> Any:
|
|
||||||
|
def extract_base_image(dockerfile: Path) -> str:
|
||||||
|
"""Extract base image from dockerfile"""
|
||||||
|
for line in dockerfile.read_text().splitlines():
|
||||||
|
if line.startswith(BASE_IMAGE_PREFIX):
|
||||||
|
full_image = line[len(BASE_IMAGE_PREFIX) :]
|
||||||
|
image_name = full_image[full_image.rfind("/") + 1 :]
|
||||||
|
return "" if ":" in image_name else image_name
|
||||||
|
raise RuntimeError(f"Base image not found in {dockerfile}")
|
||||||
|
|
||||||
|
|
||||||
|
def get_platform(runs_on: str) -> str:
|
||||||
|
"""Get platform architecture based on runner"""
|
||||||
|
return "x86_64" if runs_on == "ubuntu-24.04" else "aarch64"
|
||||||
|
|
||||||
|
|
||||||
|
def generate_matrix() -> dict[str, list[dict[str, str]]]:
|
||||||
|
"""Generate build matrix for GitHub Actions"""
|
||||||
dockerfiles = sorted(THIS_DIR.glob("*.dockerfile"))
|
dockerfiles = sorted(THIS_DIR.glob("*.dockerfile"))
|
||||||
runs_on = ["ubuntu-24.04", "ubuntu-24.04-arm"]
|
configurations: list[dict[str, str]] = []
|
||||||
|
|
||||||
configurations = []
|
|
||||||
for dockerfile in dockerfiles:
|
for dockerfile in dockerfiles:
|
||||||
dockerfile_name = dockerfile.name
|
dockerfile_name = dockerfile.name
|
||||||
for run in runs_on:
|
|
||||||
if dockerfile_name == "oracledb.dockerfile" and run == "ubuntu-24.04-arm":
|
for run in RUNS_ON:
|
||||||
|
# Skip ARM builds for incompatible images
|
||||||
|
if dockerfile_name in ARM_INCOMPATIBLE_IMAGES and run == "ubuntu-24.04-arm":
|
||||||
continue
|
continue
|
||||||
dockerfile_lines = dockerfile.read_text().splitlines()
|
|
||||||
base_image = [
|
|
||||||
line for line in dockerfile_lines if line.startswith("ARG BASE_IMAGE=")
|
|
||||||
][0][15:]
|
|
||||||
base_image_short = base_image[base_image.rfind("/") + 1 :]
|
|
||||||
# Handling a case of `docker.io/jupyter/base-notebook:notebook-6.5.4` image
|
|
||||||
if ":" in base_image_short:
|
|
||||||
base_image_short = ""
|
|
||||||
configurations.append(
|
configurations.append(
|
||||||
{
|
{
|
||||||
"dockerfile": dockerfile_name,
|
"dockerfile": dockerfile_name,
|
||||||
"runs-on": run,
|
"runs-on": run,
|
||||||
"platform": "x86_64" if run == "ubuntu-24.04" else "aarch64",
|
"platform": get_platform(run),
|
||||||
"parent-image": base_image_short,
|
"parent-image": extract_base_image(dockerfile),
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
return {"include": configurations}
|
return {"include": configurations}
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print("matrix=" + json.dumps(generate_matrix()))
|
print(f"matrix={json.dumps(generate_matrix())}")
|
||||||
|
Reference in New Issue
Block a user