Skip to content

Commit 5b239a4

Browse files
committed
Modify build_bootc_images.py to accept multiple layer directories
1 parent 2e00a33 commit 5b239a4

1 file changed

Lines changed: 26 additions & 15 deletions

File tree

test/bin/pyutils/build_bootc_images.py

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -348,11 +348,10 @@ def should_skip(file):
348348
# Run template command on the input file
349349
bf_outfile = os.path.join(BOOTC_IMAGE_DIR, bootcfile)
350350
run_template_cmd(bf_path, bf_outfile, dry_run)
351-
# Templating may generate an empty file
352-
if not dry_run:
353-
if not common.file_has_valid_lines(bf_outfile):
354-
common.print_msg(f"Skipping an empty {bootcfile} file")
355-
return
351+
# Templating may generate an empty file or in dry-run mode the file may not exist
352+
if not os.path.exists(bf_outfile) or (not dry_run and not common.file_has_valid_lines(bf_outfile)):
353+
common.print_msg(f"Skipping {bootcfile} file (not created or empty)")
354+
return
356355

357356
common.print_msg(f"Processing {bootcfile} with logs in {bf_logfile}")
358357
start_process_bootc_image = time.time()
@@ -462,6 +461,10 @@ def ostree_rev_in_registry(ce_imgref):
462461
# Run template command on the input file
463462
ce_outfile = os.path.join(BOOTC_IMAGE_DIR, containerfile)
464463
run_template_cmd(ce_path, ce_outfile, dry_run)
464+
# Templating may generate an empty file or in dry-run mode the file may not exist
465+
if not os.path.exists(ce_outfile) or (not dry_run and not common.file_has_valid_lines(ce_outfile)):
466+
common.print_msg(f"Skipping {containerfile} file (not created or empty)")
467+
return
465468

466469
common.print_msg(f"Processing {containerfile} with logs in {ce_logfile}")
467470
start_process_container_encapsulate = time.time()
@@ -581,7 +584,7 @@ def main():
581584
choices=["image-bootc", "containerfile", "container-encapsulate"],
582585
help="Only build images of the specified type.")
583586
dirgroup = parser.add_mutually_exclusive_group(required=False)
584-
dirgroup.add_argument("-l", "--layer-dir", type=str, help="Path to the layer directory to process.")
587+
dirgroup.add_argument("-l", "--layer-dir", type=str, help="Path to the layer directory to process. Accepts comma-separated list of directories.")
585588
dirgroup.add_argument("-g", "--group-dir", type=str, help="Path to the group directory to process.")
586589
dirgroup.add_argument("-t", "--template", type=str, help="Path to a template to build. Allows glob patterns (requires double qoutes).")
587590

@@ -600,13 +603,19 @@ def main():
600603
args.group_dir = os.path.abspath(args.group_dir)
601604
dir2process = args.group_dir
602605
if args.layer_dir:
603-
args.layer_dir = os.path.abspath(args.layer_dir)
604-
dir2process = args.layer_dir
606+
# Handle comma-separated layer directories
607+
layer_dirs = [d.strip() for d in args.layer_dir.split(",")]
608+
args.layer_dir = ",".join([os.path.abspath(d) for d in layer_dirs])
609+
# Validate each layer directory exists
610+
for layer_dir in layer_dirs:
611+
abs_layer_dir = os.path.abspath(layer_dir)
612+
if not os.path.isdir(abs_layer_dir):
613+
raise Exception(f"The layer directory '{abs_layer_dir}' does not exist")
605614
if args.template:
606615
args.template = os.path.abspath(args.template)
607616
dir2process = os.path.dirname(args.template)
608617
pattern = os.path.basename(args.template)
609-
# Make sure the input directory exists (only if specified)
618+
# Make sure the input directory exists (only if specified for group_dir)
610619
if dir2process and not os.path.isdir(dir2process):
611620
raise Exception(f"The input directory '{dir2process}' does not exist")
612621
# Make sure the local RPM repository exists
@@ -650,7 +659,8 @@ def main():
650659
if BREW_NIGHTLY_RELEASE_VERSION:
651660
extract_container_images(BREW_NIGHTLY_RELEASE_VERSION, BREW_REPO, CONTAINER_LIST, args.dry_run)
652661
# Sort the images list, only leaving unique entries
653-
common.sort_uniq_file(CONTAINER_LIST)
662+
if os.path.exists(CONTAINER_LIST):
663+
common.sort_uniq_file(CONTAINER_LIST)
654664
# Process package source templates
655665
ipkgdir = f"{SCRIPTDIR}/../package-sources-bootc"
656666
for ifile in os.listdir(ipkgdir):
@@ -672,11 +682,12 @@ def main():
672682
PULL_SECRET = opull_secret
673683
# Process layer directory contents sorted by length and then alphabetically
674684
if args.layer_dir:
675-
for item in sorted(os.listdir(args.layer_dir), key=lambda i: (len(i), i)):
676-
item_path = os.path.join(args.layer_dir, item)
677-
# Check if this item is a directory
678-
if os.path.isdir(item_path):
679-
process_group(item_path, args.build_type, dry_run=args.dry_run)
685+
for layer_dir in args.layer_dir.split(","):
686+
for item in sorted(os.listdir(layer_dir), key=lambda i: (len(i), i)):
687+
item_path = os.path.join(layer_dir, item)
688+
# Check if this item is a directory
689+
if os.path.isdir(item_path):
690+
process_group(item_path, args.build_type, dry_run=args.dry_run)
680691
else:
681692
# Process individual group directory or template
682693
process_group(dir2process, args.build_type, pattern, args.dry_run)

0 commit comments

Comments
 (0)