Skip to content

Commit

Permalink
extraConfigDpu: Use local builder images
Browse files Browse the repository at this point in the history
Registry.ci.openshift.org does not reliably provide images that support
multiarch builds.

Instead, lets save working images locally, and use these instead

Signed-off-by: Salvatore Daniele <[email protected]>
  • Loading branch information
SalDaniele committed Dec 12, 2024
1 parent 0e46430 commit 87e8ec7
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion extraConfigDpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,22 @@
from concurrent.futures import Future, ThreadPoolExecutor
import os
import time
from typing import Optional
from typing import Optional, List
from logger import logger
from clustersConfig import ExtraConfigArgs
import imageRegistry
from common import git_repo_setup
from dpuVendor import init_vendor_plugin, IpuPlugin
from imageRegistry import ImageRegistry
import jinja2
import re

DPU_OPERATOR_REPO = "https://github.com/openshift/dpu-operator.git"
MICROSHIFT_KUBECONFIG = "/root/kubeconfig.microshift"
OSE_DOCKERFILE = "https://pkgs.devel.redhat.com/cgit/containers/dpu-operator/tree/Dockerfile?h=rhaos-4.17-rhel-9"
P4_IMG = "wsfd-advnetlab217.anl.eng.bos2.dc.redhat.com:5000/intel-ipu-sdk:kubecon-aarch64"
BUILDER_IMAGE = "wsfd-advnetlab-amp04.anl.eng.bos2.dc.redhat.com:5000/ocp/builder:rhel-9-golang-1.22-openshift-4.18"
BASE_IMAGE = "wsfd-advnetlab-amp04.anl.eng.bos2.dc.redhat.com:5000/ocp/4.18:base-rhel9"

KERNEL_RPMS = [
"https://download-01.beak-001.prod.iad2.dc.redhat.com/brewroot/vol/rhel-9/packages/kernel/5.14.0/427.2.1.el9_4/x86_64/kernel-5.14.0-427.2.1.el9_4.x86_64.rpm",
Expand Down Expand Up @@ -109,8 +112,49 @@ def copy_local_registry_certs(host: host.Host, path: str) -> None:
host.copy_to(f"{directory}/{file}", f"{path}/{file}")


def find_dockerfiles(repo: str) -> List[str]:
if not os.path.exists(repo):
logger.error_and_exit(f"The specified path '{repo}' does not exist.")
if not os.path.isdir(repo):
logger.error_and_exit(f"The specified path '{repo}' is not a directory.")

dockerfiles: List[str] = []
for file_name in os.listdir(repo):
full_path = os.path.join(repo, file_name)
if file_name.startswith("Dockerfile") and os.path.isfile(full_path):
dockerfiles.append(full_path)

return dockerfiles


# The images in registry.ci.openshift.org do not always support multiarch.
# As a result we will pin working images, and use these locally instead.
def update_dpu_operator_dockerfiles(repo: str) -> None:
dockerfiles = find_dockerfiles(repo)
for dockerfile in dockerfiles:
try:
with open(dockerfile, 'r') as file:
content = file.read()

# Replace builder image
builder_pattern = r"^FROM\s+([^\s]+)\s+AS\s+builder"
content = re.sub(builder_pattern, f"FROM {BUILDER_IMAGE} AS builder", content, flags=re.MULTILINE)

# Replace base image
base_pattern = r"^FROM\s+([^\s]+)$"
content = re.sub(base_pattern, f"FROM {BASE_IMAGE}", content, flags=re.MULTILINE)

with open(dockerfile, 'w') as file:
file.write(content)

logger.info(f"Updated Dockerfile '{dockerfile}' with builder image '{BUILDER_IMAGE}' and base image '{BASE_IMAGE}'.")
except Exception as e:
logger.error_and_exit(f"Failed to update dockerfile {dockerfile} err: {e}")


def dpu_operator_build_push(repo: Optional[str]) -> None:
h = host.LocalHost()
update_dpu_operator_dockerfiles(repo)
logger.info(f"Building dpu operator images in {repo} on {h.hostname()}")
h.run_or_die(f"make -C {repo} local-buildx")
h.run_or_die(f"make -C {repo} local-pushx")
Expand Down

0 comments on commit 87e8ec7

Please sign in to comment.