|
36 | 36 | """
|
37 | 37 |
|
38 | 38 | import argparse
|
| 39 | +import configparser |
39 | 40 | import logging
|
40 | 41 | import os
|
41 | 42 | import pathlib
|
@@ -280,8 +281,7 @@ def create_common_container_engine_args(cli, target):
|
280 | 281 | "ctdb_rados_mutex_skip_reg"
|
281 | 282 | )
|
282 | 283 |
|
283 |
| - if cli.extra_build_arg: |
284 |
| - args.extend(cli.extra_build_arg) |
| 284 | + args.extend(cli.extra_build_arguments()) |
285 | 285 |
|
286 | 286 | for tname in target.all_names(baseless=cli.without_repo_bases):
|
287 | 287 | args.append("-t")
|
@@ -600,6 +600,60 @@ def print_tags(cli, target):
|
600 | 600 | print(f"{prefix}{name}")
|
601 | 601 |
|
602 | 602 |
|
| 603 | +class CLIContext: |
| 604 | + def __init__(self, cli): |
| 605 | + self._cli = cli |
| 606 | + self._customizations = None |
| 607 | + |
| 608 | + def __getattr__(self, key): |
| 609 | + return getattr(self._cli, key) |
| 610 | + |
| 611 | + def read_customizations(self): |
| 612 | + if not self._cli.customizations: |
| 613 | + return |
| 614 | + self._customizations = configparser.ConfigParser() |
| 615 | + files = self._customizations.read(self._cli.customizations) |
| 616 | + if not files: |
| 617 | + raise ValueError("no customization files could be read") |
| 618 | + |
| 619 | + def customizations(self): |
| 620 | + if self._customizations is None: |
| 621 | + self.read_customizations() |
| 622 | + return self._customizations or configparser.ConfigParser() |
| 623 | + |
| 624 | + def extra_build_arguments(self): |
| 625 | + args = [] |
| 626 | + # extra args from customizations file |
| 627 | + if "image" in self.customizations(): |
| 628 | + cimg = self.customizations()["image"] |
| 629 | + for build_arg, vtype, name in self._args_custom_vars(): |
| 630 | + cvalue = cimg.get(name, None) |
| 631 | + if cvalue is None: |
| 632 | + continue |
| 633 | + if vtype is list: |
| 634 | + cvalue = " ".join(cvalue.strip().split()) |
| 635 | + elif vtype is bool: |
| 636 | + cvalue = str(int(bool(cvalue))) |
| 637 | + args.append(f"--build-arg={build_arg}={cvalue}") |
| 638 | + if xargs := cimg.get("extra_arguments"): |
| 639 | + args.extend(shlex.split(xargs.strip())) |
| 640 | + # CLI extra args |
| 641 | + if self._cli.extra_build_arg: |
| 642 | + args.extend(self._cli.extra_build_arg) |
| 643 | + return args |
| 644 | + |
| 645 | + def _args_custom_vars(self): |
| 646 | + return [ |
| 647 | + ("INSTALL_PACKAGES_FROM", str, "install_packages_from"), |
| 648 | + ("SAMBA_VERSION_SUFFIX", str, "samba_version_suffix"), |
| 649 | + ("SAMBACC_VERSION_SUFFIX", str, "sambacc_version_suffix"), |
| 650 | + ("SAMBA_SPECIFICS", str, "samba_specifics"), |
| 651 | + ("INSTALL_CUSTOM_REPOS", list, "custom_repos"), |
| 652 | + ("PACKAGE_SELECTION", str, "package_selection"), |
| 653 | + ("CEPH_FROM_CUSTOM", bool, "ceph_from_custom"), |
| 654 | + ] |
| 655 | + |
| 656 | + |
603 | 657 | def main():
|
604 | 658 | parser = argparse.ArgumentParser()
|
605 | 659 | parser.add_argument(
|
@@ -719,6 +773,12 @@ def main():
|
719 | 773 | " without the repo base"
|
720 | 774 | ),
|
721 | 775 | )
|
| 776 | + parser.add_argument( |
| 777 | + "--customizations", |
| 778 | + "-C", |
| 779 | + type=pathlib.Path, |
| 780 | + help="", |
| 781 | + ) |
722 | 782 | parser.add_argument(
|
723 | 783 | "--distro-qualified",
|
724 | 784 | action=argparse.BooleanOptionalAction,
|
@@ -767,7 +827,7 @@ def main():
|
767 | 827 | " for a given FQIN. Requires FQIN to already exist locally."
|
768 | 828 | ),
|
769 | 829 | )
|
770 |
| - cli = parser.parse_args() |
| 830 | + cli = CLIContext(parser.parse_args()) |
771 | 831 |
|
772 | 832 | if os.environ.get("BUILD_IMAGE_DEBUG") in ("1", "yes"):
|
773 | 833 | cli.log_level = logging.DEBUG
|
|
0 commit comments