Skip to content

Commit 889ba72

Browse files
authored
RHOAIENG-28514, RHOAIENG-28513: incorporate python-3.12 workbench images into project's Makefile in opendatahub-io/notebooks (#1247)
* RHOAIENG-28514, RHOAIENG-28513: incorporate python-3.12 workbench images into project's Makefile in opendatahub-io/notebooks * building images on github actions * updating Pipfile.lock * running (at least an initial part of) our tests * RHOAIENG-28513: add Python version matrix to GitHub Actions workflows for building notebooks * fixup, reformat Python code in CI scripts for improved readability * fixup, enable additional Python 3.12 Jupyter image builds in Makefile and fix bad syntax * fixup, fix indentation issue in Makefile for Python 3.12 Jupyter image builds
1 parent f6b7e08 commit 889ba72

10 files changed

+105
-16
lines changed

.github/workflows/build-notebooks-TEMPLATE.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ name: Build & Publish Notebook Servers (TEMPLATE)
1111
required: true
1212
description: "make target to build"
1313
type: string
14+
python:
15+
required: true
16+
description: "python version"
17+
type: string
1418
github:
1519
required: true
1620
description: "top workflow's `github`"
@@ -43,7 +47,9 @@ jobs:
4347
TRIVY_VULNDB: "/home/runner/.local/share/containers/trivy_db"
4448
# Targets (and their folder) that should be scanned using FS instead of IMAGE scan due to resource constraints
4549
TRIVY_SCAN_FS_JSON: '{}'
50+
# Makefile variables
4651
BUILD_ARCH: ${{ inputs.platform }}
52+
RELEASE_PYTHON_VERSION: ${{ inputs.python }}
4753

4854
steps:
4955

.github/workflows/build-notebooks-pr-rhel.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ jobs:
7070
if: ${{ fromJson(needs.gen.outputs.has_jobs) }}
7171
with:
7272
target: "${{ matrix.target }}"
73+
python: "${{ matrix.python }}"
7374
github: "${{ toJSON(github) }}"
7475
platform: "${{ matrix.platform }}"
7576
subscription: "${{ matrix.subscription }}"

.github/workflows/build-notebooks-pr.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ jobs:
5656
if: ${{ fromJson(needs.gen.outputs.has_jobs) }}
5757
with:
5858
target: "${{ matrix.target }}"
59+
python: "${{ matrix.python }}"
5960
github: "${{ toJSON(github) }}"
6061
platform: "${{ matrix.platform }}"
6162
subscription: "${{ matrix.subscription }}"

.github/workflows/build-notebooks-push.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
if: ${{ fromJson(needs.gen.outputs.has_jobs) }}
4646
with:
4747
target: "${{ matrix.target }}"
48+
python: "${{ matrix.python }}"
4849
github: "${{ toJSON(github) }}"
4950
platform: "${{ matrix.platform }}"
5051
subscription: "${{ matrix.subscription }}"

.github/workflows/piplock-renewal.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ on: # yamllint disable-line rule:truthy
1818
default: '3.11'
1919
type: choice
2020
options:
21+
- '3.12'
2122
- '3.11'
2223
- '3.9'
2324
- '3.8'

Makefile

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ validate-rstudio-image: bin/kubectl
392392
# Default Python version
393393
PYTHON_VERSION ?= 3.11
394394
ROOT_DIR := $(shell pwd)
395-
BASE_DIRS := jupyter/minimal/ubi9-python-$(PYTHON_VERSION) \
395+
ifeq ($(PYTHON_VERSION), 3.11)
396+
BASE_DIRS := \
397+
jupyter/minimal/ubi9-python-$(PYTHON_VERSION) \
396398
jupyter/datascience/ubi9-python-$(PYTHON_VERSION) \
397399
jupyter/pytorch/ubi9-python-$(PYTHON_VERSION) \
398400
jupyter/tensorflow/ubi9-python-$(PYTHON_VERSION) \
@@ -408,6 +410,25 @@ BASE_DIRS := jupyter/minimal/ubi9-python-$(PYTHON_VERSION) \
408410
runtimes/tensorflow/ubi9-python-$(PYTHON_VERSION) \
409411
runtimes/rocm-tensorflow/ubi9-python-$(PYTHON_VERSION) \
410412
runtimes/rocm-pytorch/ubi9-python-$(PYTHON_VERSION)
413+
else ifeq ($(PYTHON_VERSION), 3.12)
414+
BASE_DIRS := \
415+
jupyter/minimal/ubi9-python-$(PYTHON_VERSION) \
416+
jupyter/datascience/ubi9-python-$(PYTHON_VERSION) \
417+
jupyter/pytorch/ubi9-python-$(PYTHON_VERSION) \
418+
jupyter/tensorflow/ubi9-python-$(PYTHON_VERSION)
419+
# jupyter/trustyai/ubi9-python-$(PYTHON_VERSION)
420+
# jupyter/rocm/tensorflow/ubi9-python-$(PYTHON_VERSION)
421+
# jupyter/rocm/pytorch/ubi9-python-$(PYTHON_VERSION)
422+
# codeserver/ubi9-python-$(PYTHON_VERSION)
423+
# runtimes/minimal/ubi9-python-$(PYTHON_VERSION)
424+
# runtimes/datascience/ubi9-python-$(PYTHON_VERSION)
425+
# runtimes/pytorch/ubi9-python-$(PYTHON_VERSION)
426+
# runtimes/tensorflow/ubi9-python-$(PYTHON_VERSION)
427+
# runtimes/rocm-tensorflow/ubi9-python-$(PYTHON_VERSION)
428+
# runtimes/rocm-pytorch/ubi9-python-$(PYTHON_VERSION)
429+
else
430+
$(error Invalid Python version $(PYTHON_VERSION))
431+
endif
411432

412433
# Default value is false, can be overiden
413434
# The below directories are not supported on tier-1
@@ -452,9 +473,11 @@ refresh-pipfilelock-files:
452473
scan-image-vulnerabilities:
453474
python ci/security-scan/quay_security_analysis.py
454475

455-
# This is used primarly for gen_gha_matrix_jobs.py to we know the set of all possible images we may want to build
476+
# This is used primarily for gen_gha_matrix_jobs.py to we know the set of all possible images we may want to build
456477
.PHONY: all-images
457-
all-images: jupyter-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION) \
478+
ifeq ($(RELEASE_PYTHON_VERSION), 3.11)
479+
all-images: \
480+
jupyter-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION) \
458481
jupyter-datascience-ubi9-python-$(RELEASE_PYTHON_VERSION) \
459482
cuda-jupyter-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION) \
460483
cuda-jupyter-tensorflow-ubi9-python-$(RELEASE_PYTHON_VERSION) \
@@ -474,8 +497,33 @@ all-images: jupyter-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION) \
474497
rocm-jupyter-pytorch-ubi9-python-$(RELEASE_PYTHON_VERSION) \
475498
rocm-runtime-pytorch-ubi9-python-$(RELEASE_PYTHON_VERSION) \
476499
rocm-runtime-tensorflow-ubi9-python-$(RELEASE_PYTHON_VERSION)
500+
else ifeq ($(RELEASE_PYTHON_VERSION), 3.12)
501+
all-images: \
502+
jupyter-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION) \
503+
jupyter-datascience-ubi9-python-$(RELEASE_PYTHON_VERSION) \
504+
cuda-jupyter-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION) \
505+
cuda-jupyter-tensorflow-ubi9-python-$(RELEASE_PYTHON_VERSION) \
506+
cuda-jupyter-pytorch-ubi9-python-$(RELEASE_PYTHON_VERSION)
507+
# jupyter-trustyai-ubi9-python-$(RELEASE_PYTHON_VERSION)
508+
# runtime-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION)
509+
# runtime-datascience-ubi9-python-$(RELEASE_PYTHON_VERSION)
510+
# runtime-cuda-pytorch-ubi9-python-$(RELEASE_PYTHON_VERSION)
511+
# runtime-cuda-tensorflow-ubi9-python-$(RELEASE_PYTHON_VERSION)
512+
# codeserver-ubi9-python-$(RELEASE_PYTHON_VERSION)
513+
# rstudio-c9s-python-$(RELEASE_PYTHON_VERSION)
514+
# cuda-rstudio-c9s-python-$(RELEASE_PYTHON_VERSION)
515+
# rstudio-rhel9-python-$(RELEASE_PYTHON_VERSION)
516+
# cuda-rstudio-rhel9-python-$(RELEASE_PYTHON_VERSION)
517+
# rocm-jupyter-minimal-ubi9-python-$(RELEASE_PYTHON_VERSION)
518+
# rocm-jupyter-tensorflow-ubi9-python-$(RELEASE_PYTHON_VERSION)
519+
# rocm-jupyter-pytorch-ubi9-python-$(RELEASE_PYTHON_VERSION)
520+
# rocm-runtime-pytorch-ubi9-python-$(RELEASE_PYTHON_VERSION)
521+
# rocm-runtime-tensorflow-ubi9-python-$(RELEASE_PYTHON_VERSION)
522+
else
523+
$(error Invalid Python version $(RELEASE_PYTHON_VERSION))
524+
endif
477525

478-
# This is used primarly for konflux_generate_component_build_pipelines.py to we know the build release version
526+
# This is used primarily for `konflux_generate_component_build_pipelines.py` to we know the build release version
479527
.PHONY: print-release
480528
print-release:
481529
@echo "$(RELEASE)"

ci/cached-builds/gen_gha_matrix_jobs.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,17 @@
2727
}
2828

2929

30-
def extract_image_targets(makefile_dir: pathlib.Path | str | None = None) -> list[str]:
30+
def extract_image_targets(
31+
makefile_dir: pathlib.Path | str | None = None, env: dict[str, str] | None = None
32+
) -> list[str]:
3133
if makefile_dir is None:
3234
makefile_dir = os.getcwd()
35+
if env is None:
36+
env = {}
3337

3438
makefile_all_target = "all-images"
3539

36-
output = makefile_helper.dry_run_makefile(target=makefile_all_target, makefile_dir=makefile_dir)
40+
output = makefile_helper.dry_run_makefile(target=makefile_all_target, makefile_dir=makefile_dir, env=env)
3741

3842
# Extract the 'all-images' entry and its values
3943
all_images = []
@@ -89,7 +93,9 @@ def main() -> None:
8993
)
9094
args = argparser.parse_args()
9195

92-
targets = extract_image_targets()
96+
targets = extract_image_targets(env={"RELEASE_PYTHON_VERSION": "3.11"}) + extract_image_targets(
97+
env={"RELEASE_PYTHON_VERSION": "3.12"}
98+
)
9399

94100
if args.from_ref:
95101
logging.info("Skipping targets not modified in the PR")
@@ -122,6 +128,11 @@ def main() -> None:
122128
"include": [
123129
{
124130
"target": target,
131+
"python": "3.11"
132+
if "-python-3.11" in target
133+
else "3.12"
134+
if "-python-3.12" in target
135+
else "invalid-python-version",
125136
"platform": platform,
126137
"subscription": "rhel" in target,
127138
}

ci/cached-builds/gha_pr_changed_files.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,21 @@ def list_changed_files(from_ref: str, to_ref: str) -> list[str]:
2929
return files
3030

3131

32-
def _query_build(make_target: str, query: str) -> str:
32+
def _query_build(make_target: str, query: str, env: dict[str, str] | None = None) -> str:
3333
results = []
3434

35+
if env is None:
36+
env = {}
37+
38+
envs = []
39+
for k, v in env.items():
40+
envs.extend(("-e", f"{k}={v}"))
41+
3542
pattern = re.compile(r"#\*# " + query + r": <(?P<result>[^>]+)> #\(MACHINE-PARSED LINE\)#\*#\.\.\.")
3643
try:
3744
logging.debug(f"Running make in --just-print mode for target {make_target}")
3845
for line in subprocess.check_output(
39-
[MAKE, make_target, "--just-print"], encoding="utf-8", cwd=PROJECT_ROOT
46+
[MAKE, make_target, "--just-print", *envs], encoding="utf-8", cwd=PROJECT_ROOT
4047
).splitlines():
4148
if m := pattern.match(line):
4249
results.append(m["result"])
@@ -51,12 +58,12 @@ def _query_build(make_target: str, query: str) -> str:
5158
return results[0]
5259

5360

54-
def get_build_directory(make_target) -> str:
55-
return _query_build(make_target, "Image build directory")
61+
def get_build_directory(make_target, env: dict[str, str] | None = None) -> str:
62+
return _query_build(make_target, "Image build directory", env=env)
5663

5764

58-
def get_build_dockerfile(make_target) -> str:
59-
return _query_build(make_target, "Image build Dockerfile")
65+
def get_build_dockerfile(make_target: str, env: dict[str, str] | None = None) -> str:
66+
return _query_build(make_target, "Image build Dockerfile", env=env)
6067

6168

6269
def find_dockerfiles(directory: str) -> list:
@@ -97,7 +104,10 @@ def should_build_target(changed_files: list[str], target_directory: str) -> str:
97104
def filter_out_unchanged(targets: list[str], changed_files: list[str]) -> list[str]:
98105
changed = []
99106
for target in targets:
100-
build_directory = get_build_directory(target)
107+
python_version = (
108+
"3.11" if "-python-3.11" in target else "3.12" if "-python-3.12" in target else "invalid-python-version"
109+
)
110+
build_directory = get_build_directory(target, env={"RELEASE_PYTHON_VERSION": python_version})
101111
if reason := should_build_target(changed_files, build_directory):
102112
logging.info(f"✅ Will build {target} because file {reason} has been changed")
103113
changed.append(target)

ci/cached-builds/has_tests.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ def check_tests(target: str) -> bool:
3838
if target.startswith(("rocm-jupyter-minimal-", "rocm-jupyter-datascience-")):
3939
return False # we don't have specific tests for -minimal-, ... in ci-operator/config
4040

41+
if target.endswith("-python-3.12"):
42+
return False # we haven't yet enabled on-cluster testing because that needs valid manifests
43+
4144
build_directory = gha_pr_changed_files.get_build_directory(target)
4245
kustomization = (
4346
pathlib.Path(gha_pr_changed_files.PROJECT_ROOT) / build_directory / "kustomize/base/kustomization.yaml"

ci/cached-builds/makefile_helper.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,14 @@ def exec_makefile(target: str, makefile_dir: pathlib.Path | str, options: list[s
3434
return result.stdout
3535

3636

37-
def dry_run_makefile(target: str, makefile_dir: pathlib.Path | str) -> str:
37+
def dry_run_makefile(target: str, makefile_dir: pathlib.Path | str, env: dict[str, str] | None = None) -> str:
38+
if env is None:
39+
env = {}
40+
41+
envs = []
42+
for k, v in env.items():
43+
envs.extend(("-e", f"{k}={v}"))
44+
3845
return exec_makefile(
39-
target=target, makefile_dir=makefile_dir, options=["--dry-run", "--print-data-base", "--quiet"]
46+
target=target, makefile_dir=makefile_dir, options=["--dry-run", "--print-data-base", "--quiet", *envs]
4047
)

0 commit comments

Comments
 (0)