From bee6f5bb7b39a6add94f67ccedbd4c92bfa0de1e Mon Sep 17 00:00:00 2001 From: Piyush Gupta Date: Thu, 9 Feb 2023 09:47:57 +0000 Subject: [PATCH] setup.py: Add support for binary photon-iso-builder upon installation. photon_installer/isoBuilder.py: Add a main module to be called from entrypoint. Provide multiple repos with append action. Ex - photon-iso-builder -p packages_minimal.json -r local1.repo -r local2.repo -v 4.0 -f build-iso. Change-Id: I895cb1b0514a6ab04e2fbb4c4aa2f9e6bd33cf75 --- photon_installer/generate_initrd.sh | 4 ++-- photon_installer/isoBuilder.py | 31 ++++++++++++----------------- setup.py | 3 ++- 3 files changed, 17 insertions(+), 21 deletions(-) diff --git a/photon_installer/generate_initrd.sh b/photon_installer/generate_initrd.sh index a0cfbc5..de8d981 100755 --- a/photon_installer/generate_initrd.sh +++ b/photon_installer/generate_initrd.sh @@ -41,7 +41,7 @@ EOF rpmdb_init_cmd="rpm --root ${INITRD} --initdb --dbpath /var/lib/rpm" echo "${rpmdb_init_cmd}" if [ "$(rpm -E %{_db_backend})" != "sqlite" ]; then - rpmdb_init_cmd="docker run --ulimit nofile=1024:1024 --rm -v ${INITRD}:${INITRD} photon:$PHOTON_RELEASE_VER /bin/bash -c \"tdnf install -y rpm && ${rpmdb_init_cmd}\"" + rpmdb_init_cmd="docker run --privileged --ulimit nofile=1024:1024 --rm -v ${INITRD}:${INITRD} photon:$PHOTON_RELEASE_VER /bin/bash -c \"tdnf install -y rpm && ${rpmdb_init_cmd}\"" fi if ! eval "${rpmdb_init_cmd}"; then @@ -58,7 +58,7 @@ TDNF_CMD="tdnf install -qy \ echo $TDNF_CMD -$TDNF_CMD || docker run --ulimit nofile=1024:1024 --rm -v $RPMS_PATH:$RPMS_PATH -v $WORKINGDIR:$WORKINGDIR photon:$PHOTON_RELEASE_VER /bin/bash -c "$TDNF_CMD" +$TDNF_CMD || docker run --privileged --ulimit nofile=1024:1024 --rm -v $RPMS_PATH:$RPMS_PATH -v $WORKINGDIR:$WORKINGDIR photon:$PHOTON_RELEASE_VER /bin/bash -c "$TDNF_CMD" #mkdir -p $WORKINGDIR/isolinux #cp -r ${INITRD}/usr/share/photon-isolinux/* $WORKINGDIR/isolinux/ diff --git a/photon_installer/isoBuilder.py b/photon_installer/isoBuilder.py index 4f73360..4bec77c 100755 --- a/photon_installer/isoBuilder.py +++ b/photon_installer/isoBuilder.py @@ -135,7 +135,7 @@ def downloadPkgs(self): # Using --alldeps option to include all dependencies even though package might be installed on system. tdnf_download_cmd = (f"tdnf --releasever {self.photon_release_version} --alldeps --downloadonly -y " f"--downloaddir={self.working_dir}/RPMS install {pkg_list}") - download_cmd = (f"docker run --rm {additionalRepo} -v {self.rpms_path}:{self.rpms_path} " + download_cmd = (f"docker run --privileged --rm {additionalRepo} -v {self.rpms_path}:{self.rpms_path} " f"-v {self.working_dir}:{self.working_dir} photon:{self.photon_release_version} " f"/bin/bash -c \"tdnf clean all && tdnf update tdnf -y && {tdnf_download_cmd}\"") self.logger.info("Starting to download packages...") @@ -204,7 +204,7 @@ def createIsolinux(self): self.logger.debug(tdnf_install_cmd) # When using tdnf --installroot or rpm --root on chroot folder without /proc mounted, we must limit number of open files # to avoid librpm hang scanning all possible FDs. - self.runCmd((f'docker run --ulimit nofile=1024:1024 --rm -v {self.working_dir}:{self.working_dir}' + self.runCmd((f'docker run --privileged --ulimit nofile=1024:1024 --rm -v {self.working_dir}:{self.working_dir}' f' photon:{self.photon_release_version} /bin/bash -c "{tdnf_install_cmd}"')) self.logger.debug("Succesfully installed photon-iso-config syslinux...") @@ -263,25 +263,17 @@ def build(self): build_iso_cmd += "popd" self.runCmd(build_iso_cmd) - -if __name__ == '__main__': +def main(): usage = "Usage: %prog [options]" parser = ArgumentParser(usage) parser.add_argument("-l", "--log-level", dest="log_level", default="info") - parser.add_argument("-f", "--function", dest="function", - default="build-iso", help="Building Options", choices=['build-iso', 'build-initrd']) - parser.add_argument("-v", "--photon-release-version", - dest="photon_release_version", required=True) - parser.add_argument("-c", "--custom-initrd-pkgs", dest="custom_initrd_pkgs", default=None, - help="optional parameter to provide cutom initrd pkg list file.") - parser.add_argument('-r', '--additional_repos', nargs='*', default=None, - help=' Pass repo file as input to download rpms from external repo') - parser.add_argument("-p", "--custom-packages-json", - dest="custom_packages_json", default="") - parser.add_argument("-k", "--kickstart-path", - dest="kickstart_path", default=f'{os.path.dirname(__file__)}/sample_ks.cfg') - parser.add_argument("-b", "--boot-cmdline-param", - dest="boot_cmdline_param", default="") + parser.add_argument("-f", "--function", dest="function", default="build-iso", help="Building Options", choices=["build-iso", "build-initrd"]) + parser.add_argument("-v", "--photon-release-version", dest="photon_release_version", required=True) + parser.add_argument("-c", "--custom-initrd-pkgs", dest="custom_initrd_pkgs", default=None, help="optional parameter to provide cutom initrd pkg list file.") + parser.add_argument("-r", "--additional_repos", action="append", default=None, help=" Pass repo file as input to download rpms from external repo") + parser.add_argument("-p", "--custom-packages-json", dest="custom_packages_json", default="") + parser.add_argument("-k", "--kickstart-path", dest="kickstart_path", default=f"{os.path.dirname(__file__)}/sample_ks.cfg") + parser.add_argument("-b", "--boot-cmdline-param", dest="boot_cmdline_param", default="") options = parser.parse_args() @@ -304,3 +296,6 @@ def build(self): raise Exception(f"{options.function} not supported...") isoBuilder.cleanUp() + +if __name__ == '__main__': + main() diff --git a/setup.py b/setup.py index ba562fa..2e786c0 100644 --- a/setup.py +++ b/setup.py @@ -21,7 +21,8 @@ zip_safe=False, entry_points={ 'console_scripts': [ - 'photon-installer = photon_installer.main:main' + 'photon-installer = photon_installer.main:main', + 'photon-iso-builder = photon_installer.isoBuilder:main' ] }, version='2.0+'+get_installer_version(),