|
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,61 @@ 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 |
| 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, names in self._args_custom_vars(): |
| 630 | + for name in names: |
| 631 | + cvalue = cimg.get(name, None) |
| 632 | + if cvalue is None: |
| 633 | + continue |
| 634 | + if vtype is list: |
| 635 | + cvalue = " ".join(cvalue.strip().split()) |
| 636 | + args.append(f"--build-arg={build_arg}={cvalue}") |
| 637 | + # CLI extra args |
| 638 | + if self._cli.extra_build_arg: |
| 639 | + args.extend(self._cli.extra_build_arg) |
| 640 | + return args |
| 641 | + |
| 642 | + def _args_custom_vars(self): |
| 643 | + return [ |
| 644 | + ("INSTALL_PACKAGES_FROM", str, ("install_packages_from",)), |
| 645 | + ("SAMBA_VERSION_SUFFIX", str, ("samba_version_suffix",)), |
| 646 | + ("SAMBACC_VERSION_SUFFIX", str, ("sambacc_version_suffix",)), |
| 647 | + ("SAMBA_SPECIFICS", str, ("samba_specifics",)), |
| 648 | + ( |
| 649 | + "INSTALL_CUSTOM_REPO", |
| 650 | + str, |
| 651 | + ("install_custom_repo", "samba_custom_repo"), |
| 652 | + ), |
| 653 | + ("PACKAGE_SELECTION", str, ("package_selection",)), |
| 654 | + ("CUSTOM_REPOS", list, ("custom_repos",)), |
| 655 | + ] |
| 656 | + |
| 657 | + |
603 | 658 | def main():
|
604 | 659 | parser = argparse.ArgumentParser()
|
605 | 660 | parser.add_argument(
|
@@ -719,6 +774,12 @@ def main():
|
719 | 774 | " without the repo base"
|
720 | 775 | ),
|
721 | 776 | )
|
| 777 | + parser.add_argument( |
| 778 | + "--customizations", |
| 779 | + "-C", |
| 780 | + type=pathlib.Path, |
| 781 | + help="", |
| 782 | + ) |
722 | 783 | parser.add_argument(
|
723 | 784 | "--distro-qualified",
|
724 | 785 | action=argparse.BooleanOptionalAction,
|
@@ -767,7 +828,7 @@ def main():
|
767 | 828 | " for a given FQIN. Requires FQIN to already exist locally."
|
768 | 829 | ),
|
769 | 830 | )
|
770 |
| - cli = parser.parse_args() |
| 831 | + cli = CLIContext(parser.parse_args()) |
771 | 832 |
|
772 | 833 | if os.environ.get("BUILD_IMAGE_DEBUG") in ("1", "yes"):
|
773 | 834 | cli.log_level = logging.DEBUG
|
|
0 commit comments