Skip to content

Commit ed363c7

Browse files
jiridanekcaponetto
andauthored
RHOAIENG-9822: chore(Makefile): allow not pushing built images in Makefile and allow skipping building dependent images (#657)
Co-authored-by: Guilherme Caponetto <[email protected]>
1 parent f84cf69 commit ed363c7

File tree

6 files changed

+58
-25
lines changed

6 files changed

+58
-25
lines changed

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,21 +123,20 @@ jobs:
123123
env:
124124
IMAGE_REGISTRY: "ghcr.io/${{ github.repository }}/workbench-images"
125125
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }} --cache-to ${{ env.CACHE }}"
126+
# dependent images were already built and pushed, so just let podman pull it
127+
BUILD_DEPENDENT_IMAGES: "no"
126128

127129
# https://docs.github.com/en/actions/using-workflows/events-that-trigger-workflows#pull_request
128130
- name: "pull_request: make ${{ inputs.target }}"
129131
run: |
130-
# start a black hole container registry as make target always does a push
131-
mkdir -p $HOME/.config/containers/registries.conf.d/
132-
cp ci/cached-builds/insecure_localhost_registry.conf $HOME/.config/containers/registries.conf.d/insecure_localhost_registry.conf
133-
go run ci/cached-builds/dev_null_container_registry.go &
134-
# build and push the image
135132
make ${{ inputs.target }}
136133
if: "${{ fromJson(inputs.github).event_name == 'pull_request' }}"
137134
env:
138135
IMAGE_TAG: "${{ github.sha }}"
139136
IMAGE_REGISTRY: "localhost:5000/workbench-images"
140137
CONTAINER_BUILD_CACHE_ARGS: "--cache-from ${{ env.CACHE }}"
138+
# We don't have access to image registry, so disable pushing
139+
PUSH_IMAGES: "no"
141140

142141
- name: "Show podman images information"
143142
run: podman images

Makefile

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@ IMAGE_REGISTRY ?= quay.io/opendatahub/workbench-images
22
RELEASE ?= 2024a
33
# additional user-specified caching parameters for $(CONTAINER_ENGINE) build
44
CONTAINER_BUILD_CACHE_ARGS ?= --no-cache
5+
# whether to build all dependent images or just the one specified
6+
BUILD_DEPENDENT_IMAGES ?= yes
7+
# whether to push the images to a registry as they are built
8+
PUSH_IMAGES ?= yes
59

610
# OS dependant: Generate date, select appropriate cmd to locate container engine
711
ifeq ($(OS), Windows_NT)
@@ -58,10 +62,19 @@ endef
5862
# ARG 1: Image tag name.
5963
# ARG 2: Path of image context we want to build.
6064
# ARG 3: Base image tag name (optional).
65+
#
66+
# BUILD_DEPENDENT_IMAGES: only build images that were explicitly given as a goal on command line
67+
# PUSH_IMAGES: allows skipping podman push
6168
define image
6269
$(info #*# Image build directory: <$(2)> #(MACHINE-PARSED LINE)#*#...)
63-
$(call build_image,$(1),$(2),$(3))
64-
$(call push_image,$(1))
70+
71+
$(if $(or $(BUILD_DEPENDENT_IMAGES:no=), $(filter $@,$(MAKECMDGOALS))),
72+
$(call build_image,$(1),$(2),$(3))
73+
74+
$(if $(PUSH_IMAGES:no=),
75+
$(call push_image,$(1))
76+
)
77+
)
6578
endef
6679

6780
####################################### Buildchain for Python 3.8 using ubi8 #######################################

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ To build a workbench image, you can execute the following command:
3737
make ${WORKBENCH_NAME} -e IMAGE_REGISTRY=quay.io/${YOUR_USER}/workbench-images -e RELEASE=2023x
3838
```
3939

40-
Using `IMAGE_REGISTRY` and `RELEASE` variables you can overwrite the default values and use a different registry or release tag
40+
Using `IMAGE_REGISTRY` and `RELEASE` variables you can overwrite the default values and use a different registry or release tag
41+
42+
Using `CONTAINER_BUILD_CACHE_ARGS` (default: `--no-cache`), `BUILD_DEPENDENT_IMAGES`, and `PUSH_IMAGES` variables you can further customize the build process.
4143

4244
### Local Execution
4345

ci/cached-builds/dev_null_container_registry.go

Lines changed: 0 additions & 14 deletions
This file was deleted.

ci/cached-builds/insecure_localhost_registry.conf

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/test_main.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from __future__ import annotations
22

3+
import os
4+
import logging
35
import pathlib
6+
import subprocess
47
import tomllib
58
from typing import TYPE_CHECKING
69

@@ -32,3 +35,36 @@ def test_files_that_should_be_same_are_same(subtests: pytest_subtests.plugin.Sub
3235
with subtests.test(msg=f"Checking {group_name}"):
3336
for file in rest:
3437
assert first_file.read_text() == file.read_text(), f"The files {first_file} and {file} do not match"
38+
39+
40+
def test_make_building_only_specified_images(subtests: pytest_subtests.plugin.SubTests):
41+
for goals in (["rocm-jupyter-tensorflow-ubi9-python-3.9"], ["rocm-jupyter-tensorflow-ubi9-python-3.9", "base-ubi9-python-3.9"]):
42+
with subtests.test(msg="Running goals", goals=goals):
43+
lines = dryrun_make(goals, env={"BUILD_DEPENDENT_IMAGES": "no"})
44+
builds_number = 0
45+
for line in lines:
46+
if "podman build" in line:
47+
builds_number += 1
48+
assert builds_number == len(goals)
49+
50+
51+
def test_make_disable_pushing():
52+
lines = dryrun_make(["rocm-jupyter-tensorflow-ubi9-python-3.9"], env={"PUSH_IMAGES": ""})
53+
for line in lines:
54+
assert "podman push" not in line
55+
56+
57+
def dryrun_make(make_args: list[str], env: dict[str, str] | None = None) -> list[str]:
58+
env = env or {}
59+
60+
try:
61+
logging.info(f"Running make in --just-print mode for target(s) {make_args} with env {env}")
62+
lines = subprocess.check_output(["make", "--just-print", *make_args], encoding="utf-8",
63+
env={**os.environ, **env},
64+
cwd=PROJECT_ROOT).splitlines()
65+
for line in lines:
66+
logging.debug(line)
67+
return lines
68+
except subprocess.CalledProcessError as e:
69+
print(e.stderr, e.stdout)
70+
raise

0 commit comments

Comments
 (0)