diff --git a/provider/bootc_image_builder/bootc_image_build_utils.py b/provider/bootc_image_builder/bootc_image_build_utils.py index 8e0cee1d37..fd50e0cbf2 100644 --- a/provider/bootc_image_builder/bootc_image_build_utils.py +++ b/provider/bootc_image_builder/bootc_image_build_utils.py @@ -65,7 +65,10 @@ def podman_command_build(bib_image_url, disk_image_type, image_ref, config=None, os.makedirs("/var/lib/libvirt/images/output") cmd = "sudo podman run --rm -it --privileged --pull=newer --security-opt label=type:unconfined_t -v /var/lib/libvirt/images/output:/output" if config: - cmd += " -v %s:/config.json " % config + if "toml" in config: + cmd += " -v %s:/config.toml " % config + else: + cmd += " -v %s:/config.json " % config if local_container: cmd += " -v /var/lib/containers/storage:/var/lib/containers/storage " @@ -83,7 +86,10 @@ def podman_command_build(bib_image_url, disk_image_type, image_ref, config=None, " --type %s --tls-verify=%s " % (bib_image_url, disk_image_type, tls_verify) if config: - cmd += " --config /config.json " + if "toml" in config: + cmd += " --config /config.toml " + else: + cmd += " --config /config.json " if target_arch: cmd += " --target-arch=%s " % target_arch @@ -173,6 +179,19 @@ def create_config_json_file(params): password = params.get("os_password") kickstart = "yes" == params.get("kickstart") public_key_path = os.path.join(os.path.expanduser("~/.ssh/"), "id_rsa.pub") + filesystem_size_set = "yes" == params.get("filesystem_size_set") + + filesystem_dict = {"filesystem": [ + { + "mountpoint": "/", + "minsize": "10 GiB" + }, + { + "mountpoint": "/var/data", + "minsize": "15 GiB" + } + ] + } if not os.path.exists(public_key_path): LOG.debug("public key doesn't exist, will help create one") key_gen_cmd = "ssh-keygen -q -t rsa -N '' <<< $'\ny' >/dev/null 2>&1" @@ -222,12 +241,84 @@ def create_config_json_file(params): } } + if filesystem_size_set: + cfg['blueprint']['customizations'].update(filesystem_dict) + LOG.debug("what is cfg:%s", cfg) config_json_path = pathlib.Path(folder) / "config.json" config_json_path.write_text(json.dumps(cfg), encoding="utf-8") return os.path.join(folder, "config.json") +def create_config_toml_file(params): + """ + create toml configuration file + + :param params: one dictionary to pass in configuration + """ + folder = params.get("config_file_path") + username = params.get("os_username") + password = params.get("os_password") + kickstart = "yes" == params.get("kickstart") + public_key_path = os.path.join(os.path.expanduser("~/.ssh/"), "id_rsa.pub") + filesystem_size_set = "yes" == params.get("filesystem_size_set") + filesystem_size_str = "" + + if not os.path.exists(public_key_path): + LOG.debug("public key doesn't exist, will help create one") + key_gen_cmd = "ssh-keygen -q -t rsa -N '' <<< $'\ny' >/dev/null 2>&1" + process.run(key_gen_cmd, shell=True, ignore_status=False) + + with open(public_key_path, 'r') as ssh: + key_value = ssh.read().rstrip() + + if filesystem_size_set: + filesystem_size_str = f""" + [[customizations.filesystem]] + mountpoint = "/" + minsize = "10 GiB" + + [[customizations.filesystem]] + mountpoint = "/var/data" + minsize = "20 GiB" + """ + if not kickstart: + container_file_content = f"""\n + [[customizations.user]] + name = "{username}" + password = "{password}" + key = "{key_value}" + groups = ["wheel"] + {filesystem_size_str} + [customizations.kernel] + append = "mitigations=auto,nosmt" + """ + else: + kick_start = {"contents": "user --name %s --password %s --groups wheel\n" + "sshkey --username %s \"%s\"\ntext --non-interactive\nzerombr\n" + "clearpart --all --initlabel --disklabel=gpt\nautopart --noswap --type=lvm\n" + "network --bootproto=dhcp --device=link --activate --onboot=on\n reboot" % (username, password, username, key_value) + } + container_file_content = f"""\n + [customizations.kernel] + append = "mitigations=auto,nosmt" + [customizations.installer.modules] + enable = [ + "org.fedoraproject.Anaconda.Modules.Localization" + ] + disable = [ + "org.fedoraproject.Anaconda.Modules.Users" + ] + {filesystem_size_str} + [customizations.installer.kickstart] + contents = \"""{kick_start.get("contents")}\""" + """ + LOG.debug("what is cfg:%s", cfg) + config_toml_path = pathlib.Path(folder) / "config.toml" + config_toml_path.write_text(textwrap.dedent(container_file_content), encoding="utf8") + return os.path.join(folder, "config.toml") + + def create_auth_json_file(params): """ create authentication json configuration file @@ -843,6 +934,7 @@ def convert_vhd_to_qcow2(params): Convert vhd disk format into qcow2 @param params: one dictionary wrapping various parameter + :return: Converted image path """ original_image_path = params.get('vm_disk_image_path') converted_image_path = original_image_path.replace("vhd", "qcow2") diff --git a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg index ed740b17a9..ec5955b429 100644 --- a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg +++ b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_build.cfg @@ -23,10 +23,13 @@ - use_config_json: os_username = "alice" os_password = "bob" + qcow..upstream_bib: + filesystem_size_set = "yes" anaconda-iso..upstream_bib..fedora_40: kickstart = "yes" anaconda-iso..rhel_9.5_nightly_bib..local_image: kickstart = "yes" + filesystem_size_set = "yes" - unuse_config_json: variants image_ref: - centos: diff --git a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg index cb4329eef2..4eadb29c0d 100644 --- a/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg +++ b/virttools/tests/cfg/bootc_image_builder/bootc_disk_image_install.cfg @@ -52,6 +52,8 @@ roofs = "xfs" anaconda-iso..upstream_bib: kickstart = "yes" + raw..upstream_bib: + filesystem_size_set = "yes" - fedora_latest: only upstream_bib container_url = "quay.io/fedora/fedora-bootc:latest"