From 513932b3c8dc2d22bb17fd0680c7461c013de433 Mon Sep 17 00:00:00 2001 From: "B. Stack" Date: Mon, 13 May 2024 14:46:34 -0400 Subject: add initial research for rpm --- build.py | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 69 insertions(+), 1 deletion(-) (limited to 'build.py') diff --git a/build.py b/build.py index 55a8286..c3aad91 100755 --- a/build.py +++ b/build.py @@ -120,6 +120,73 @@ def build_package_deb( f"{docker_run_cmd} --volume {repo_root_dir}:/jellyfin --volume {repo_root_dir}/out/{build_type}:/dist --env JELLYFIN_VERSION={jellyfin_version} --name {imagename} {imagename}" ) +def build_package_rpm( + jellyfin_version, build_type, build_arch, build_version, local=False +): + """ + Build a .rpm package (Fedora) within a Docker container that matches the requested distribution version + """ + log(f"> Building an {build_arch} {build_type} .rpm package...") + log("") + + try: + os_type = build_type if build_type in configurations.keys() else None + if os_type is None: + raise ValueError( + f"{build_type} is not a valid OS type in {configurations.keys()}" + ) + os_version = ( + build_version + if int(build_version) in [int(i) for i in configurations[build_type]["releases"]] + else None + ) + if os_version is None: + raise ValueError( + f"{build_version} is not a valid {build_type} version in {configurations[build_type]['releases']}" + ) + PACKAGE_ARCH = _determine_arch(build_type, build_arch, build_version) + except Exception as e: + log(f"Invalid/unsupported arguments: {e}") + exit(1) + + # Set the dockerfile + dockerfile = configurations[build_type]["dockerfile"] + + # Prepare the debian changelog file + changelog_src = f"{repo_root_dir}/debian/changelog.in" + changelog_dst = f"{repo_root_dir}/debian/changelog" + + with open(changelog_src) as fh: + changelog = fh.read() + + if "v" in jellyfin_version: + comment = f"Jellyfin release {jellyfin_version}, see https://github.com/jellyfin/jellyfin/releases/{jellyfin_version} for details." + else: + comment = f"Jellyin unstable release {jellyfin_version}." + jellyfin_version = jellyfin_version.replace("v", "") + + changelog = changelog.format( + package_version=jellyfin_version, + package_build=f"{build_type[:3]}{os_version.replace('.', '')}", + release_comment=comment, + release_date=format_datetime(localtime()), + ) + + with open(changelog_dst, "w") as fh: + fh.write(changelog) + + # Use a unique docker image name for consistency + imagename = f"{configurations[build_type]['imagename']}-{jellyfin_version}_{build_arch}-{build_type}-{build_version}" + + # Build the dockerfile and packages + os.system( + f"{docker_build_cmd} --build-arg PACKAGE_TYPE={os_type} --build-arg PACKAGE_VERSION={os_version} --build-arg PACKAGE_ARCH={PACKAGE_ARCH} --file {repo_root_dir}/{dockerfile} --tag {imagename} {repo_root_dir}" + ) + os.system( + f"{docker_run_cmd} --volume {repo_root_dir}:/jellyfin --volume {repo_root_dir}/out/{build_type}:/dist --env JELLYFIN_VERSION={jellyfin_version} --name {imagename} {imagename}" + ) + + def build_linux( jellyfin_version, build_type, build_arch, _build_version, local=False @@ -520,6 +587,7 @@ def usage(): # Define a map of possible build functions from the YAML configuration function_definitions = { "build_package_deb": build_package_deb, + "build_package_rpm": build_package_rpm, "build_portable": build_portable, "build_linux": build_linux, "build_windows": build_windows, @@ -555,7 +623,7 @@ if build_type not in ["portable", "docker", "nuget"] and not build_arch: # Autocorrect "master" to a dated version string if jellyfin_version in ["auto", "master"]: - jellyfin_version = datetime.now().strftime("%Y%m%d%H") + jellyfin_version = datetime.now().strftime("%Y%m%d%H%M") log(f"NOTE: Autocorrecting 'master' version to {jellyfin_version}") # Launch the builder function -- cgit