Skip to content

Commit

Permalink
Merge "setup.py: Add support for binary photon-iso-builder upon insta…
Browse files Browse the repository at this point in the history
…llation."
  • Loading branch information
tapakund authored and Gerrit Code Review committed Feb 14, 2023
2 parents 1928151 + bee6f5b commit 4aacf5a
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 21 deletions.
4 changes: 2 additions & 2 deletions photon_installer/generate_initrd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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/
Expand Down
31 changes: 13 additions & 18 deletions photon_installer/isoBuilder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down Expand Up @@ -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...")
Expand Down Expand Up @@ -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='<Optional> 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="<Optional> 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()

Expand All @@ -304,3 +296,6 @@ def build(self):
raise Exception(f"{options.function} not supported...")

isoBuilder.cleanUp()

if __name__ == '__main__':
main()
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down

0 comments on commit 4aacf5a

Please sign in to comment.