From: Daan De Meyer Date: Tue, 10 Oct 2023 09:36:59 +0000 (+0200) Subject: Pass around MkosiState in centos based distributions X-Git-Tag: v19~87^2~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=14292ad13c16b399951983cff38cee60463be3f4;p=thirdparty%2Fmkosi.git Pass around MkosiState in centos based distributions We need access to the pkgmngr tree to be able to look for GPG keys or certificates there, so let's pass around MkosiState everywhere. --- diff --git a/mkosi/distributions/alma.py b/mkosi/distributions/alma.py index cb510d55f..6d2f3296a 100644 --- a/mkosi/distributions/alma.py +++ b/mkosi/distributions/alma.py @@ -2,9 +2,9 @@ from pathlib import Path -from mkosi.config import MkosiConfig from mkosi.distributions import centos from mkosi.installer.dnf import Repo +from mkosi.state import MkosiState class Installer(centos.Installer): @@ -13,22 +13,22 @@ class Installer(centos.Installer): return "AlmaLinux" @staticmethod - def gpgurls(config: MkosiConfig) -> tuple[str, ...]: - gpgpath = Path(f"/usr/share/distribution-gpg-keys/alma/RPM-GPG-KEY-AlmaLinux-{config.release}") + def gpgurls(state: MkosiState) -> tuple[str, ...]: + gpgpath = Path(f"/usr/share/distribution-gpg-keys/alma/RPM-GPG-KEY-AlmaLinux-{state.config.release}") if gpgpath.exists(): return (f"file://{gpgpath}",) else: return ("https://repo.almalinux.org/almalinux/RPM-GPG-KEY-AlmaLinux-$releasever",) @classmethod - def repository_variants(cls, config: MkosiConfig, repo: str) -> list[Repo]: - if config.mirror: - url = f"baseurl={config.mirror}/almalinux/$releasever/{repo}/$basearch/os" + def repository_variants(cls, state: MkosiState, repo: str) -> list[Repo]: + if state.config.mirror: + url = f"baseurl={state.config.mirror}/almalinux/$releasever/{repo}/$basearch/os" else: url = f"mirrorlist=https://mirrors.almalinux.org/mirrorlist/$releasever/{repo.lower()}" - return [Repo(repo, url, cls.gpgurls(config))] + return [Repo(repo, url, cls.gpgurls(state))] @classmethod - def sig_repositories(cls, config: MkosiConfig) -> list[Repo]: + def sig_repositories(cls, state: MkosiState) -> list[Repo]: return [] diff --git a/mkosi/distributions/centos.py b/mkosi/distributions/centos.py index 572ad817b..899fee249 100644 --- a/mkosi/distributions/centos.py +++ b/mkosi/distributions/centos.py @@ -7,7 +7,6 @@ from collections.abc import Iterable, Sequence from pathlib import Path from mkosi.architecture import Architecture -from mkosi.config import MkosiConfig from mkosi.distributions import Distribution, DistributionInstaller, PackageType from mkosi.installer.dnf import Repo, invoke_dnf, setup_dnf from mkosi.log import complete_step, die @@ -28,9 +27,8 @@ def move_rpm_db(root: Path) -> None: newdb.symlink_to(os.path.relpath(olddb, start=newdb.parent)) -def join_mirror(config: MkosiConfig, link: str) -> str: - assert config.mirror is not None - return urllib.parse.urljoin(config.mirror, link) +def join_mirror(mirror: str, link: str) -> str: + return urllib.parse.urljoin(mirror, link) class Installer(DistributionInstaller): @@ -102,7 +100,7 @@ class Installer(DistributionInstaller): if release <= 7: die(f"{cls.pretty_name()} 7 or earlier variants are not supported") - setup_dnf(state, cls.repositories(state.config, release)) + setup_dnf(state, cls.repositories(state, release)) (state.pkgmngr / "etc/dnf/vars/stream").write_text(f"{state.config.release}-stream\n") @classmethod @@ -137,7 +135,7 @@ class Installer(DistributionInstaller): return a @staticmethod - def gpgurls(config: MkosiConfig) -> tuple[str, ...]: + def gpgurls(state: MkosiState) -> tuple[str, ...]: gpgurls = [] for key in ("CentOS-Official", "CentOS-SIG-Extras"): @@ -150,80 +148,80 @@ class Installer(DistributionInstaller): return tuple(gpgurls) @classmethod - def repository_variants(cls, config: MkosiConfig, repo: str) -> Iterable[Repo]: - if config.local_mirror: - yield Repo(repo, f"baseurl={config.local_mirror}", cls.gpgurls(config)) + def repository_variants(cls, state: MkosiState, repo: str) -> Iterable[Repo]: + if state.config.local_mirror: + yield Repo(repo, f"baseurl={state.config.local_mirror}", cls.gpgurls(state)) - elif config.mirror: - if int(config.release) <= 8: + elif state.config.mirror: + if int(state.config.release) <= 8: yield Repo( repo.lower(), - f"baseurl={join_mirror(config, f'centos/$stream/{repo}/$basearch/os')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, f'centos/$stream/{repo}/$basearch/os')}", + cls.gpgurls(state), ) yield Repo( f"{repo.lower()}-debuginfo", - f"baseurl={join_mirror(config, 'centos-debuginfo/$stream/$basearch')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, 'centos-debuginfo/$stream/$basearch')}", + cls.gpgurls(state), enabled=False, ) yield Repo( f"{repo.lower()}-source", - f"baseurl={join_mirror(config, f'centos/$stream/{repo}/Source')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, f'centos/$stream/{repo}/Source')}", + cls.gpgurls(state), enabled=False, ) else: if repo == "extras": yield Repo( repo.lower(), - f"baseurl={join_mirror(config, f'SIGs/$stream/{repo}/$basearch/extras-common')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, f'SIGs/$stream/{repo}/$basearch/extras-common')}", + cls.gpgurls(state), ) yield Repo( f"{repo.lower()}-source", - f"baseurl={join_mirror(config, f'SIGs/$stream/{repo}/source/extras-common')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, f'SIGs/$stream/{repo}/source/extras-common')}", + cls.gpgurls(state), enabled=False, ) else: yield Repo( repo.lower(), - f"baseurl={join_mirror(config, f'$stream/{repo}/$basearch/os')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, f'$stream/{repo}/$basearch/os')}", + cls.gpgurls(state), ) yield Repo( f"{repo.lower()}-debuginfo", - f"baseurl={join_mirror(config, f'$stream/{repo}/$basearch/debug/tree')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, f'$stream/{repo}/$basearch/debug/tree')}", + cls.gpgurls(state), enabled=False, ) yield Repo( f"{repo.lower()}-source", - f"baseurl={join_mirror(config, f'$stream/{repo}/source/tree')}", - cls.gpgurls(config), + f"baseurl={join_mirror(state.config.mirror, f'$stream/{repo}/source/tree')}", + cls.gpgurls(state), enabled=False, ) else: - if int(config.release) <= 8: + if int(state.config.release) <= 8: yield Repo( repo.lower(), f"mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo={repo}", - cls.gpgurls(config), + cls.gpgurls(state), ) # These can't be retrieved from the mirrorlist. yield Repo( f"{repo.lower()}-debuginfo", "baseurl=http://debuginfo.centos.org/$stream/$basearch", - cls.gpgurls(config), + cls.gpgurls(state), enabled=False, ) yield Repo( f"{repo.lower()}-source", f"baseurl=https://vault.centos.org/centos/$stream/{repo}/Source", - cls.gpgurls(config), + cls.gpgurls(state), enabled=False, ) else: @@ -233,62 +231,62 @@ class Installer(DistributionInstaller): yield Repo( repo.lower(), f"{url}?arch=$basearch&repo=centos-extras-sig-extras-common-$stream", - cls.gpgurls(config), + cls.gpgurls(state), ) yield Repo( f"{repo.lower()}-source", f"{url}?arch=source&repo=centos-extras-sig-extras-common-source-$stream", - cls.gpgurls(config), + cls.gpgurls(state), enabled=False, ) else: yield Repo( repo.lower(), f"{url}?arch=$basearch&repo=centos-{repo.lower()}-$stream", - cls.gpgurls(config), + cls.gpgurls(state), ) yield Repo( f"{repo.lower()}-debuginfo", f"{url}?arch=$basearch&repo=centos-{repo.lower()}-debug-$stream", - cls.gpgurls(config), + cls.gpgurls(state), enabled=False, ) yield Repo( f"{repo.lower()}-source", f"{url}?arch=source&repo=centos-{repo.lower()}-source-$stream", - cls.gpgurls(config), + cls.gpgurls(state), enabled=False, ) @classmethod - def repositories(cls, config: MkosiConfig, release: int) -> Iterable[Repo]: - if config.local_mirror: - yield from cls.repository_variants(config, "AppStream") + def repositories(cls, state: MkosiState, release: int) -> Iterable[Repo]: + if state.config.local_mirror: + yield from cls.repository_variants(state, "AppStream") else: - yield from cls.repository_variants(config, "BaseOS") - yield from cls.repository_variants(config, "AppStream") - yield from cls.repository_variants(config, "extras") + yield from cls.repository_variants(state, "BaseOS") + yield from cls.repository_variants(state, "AppStream") + yield from cls.repository_variants(state, "extras") if release >= 9: - yield from cls.repository_variants(config, "CRB") + yield from cls.repository_variants(state, "CRB") else: - yield from cls.repository_variants(config, "PowerTools") + yield from cls.repository_variants(state, "PowerTools") - yield from cls.epel_repositories(config) - yield from cls.sig_repositories(config) + yield from cls.epel_repositories(state) + yield from cls.sig_repositories(state) @classmethod - def epel_repositories(cls, config: MkosiConfig) -> Iterable[Repo]: - gpgpath = Path(f"/usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-EPEL-{config.release}") + def epel_repositories(cls, state: MkosiState) -> Iterable[Repo]: + gpgpath = Path(f"/usr/share/distribution-gpg-keys/centos/RPM-GPG-KEY-EPEL-{state.config.release}") if gpgpath.exists(): gpgurls = (f"file://{gpgpath}",) else: - gpgurls = (f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{config.release}",) + gpgurls = (f"https://dl.fedoraproject.org/pub/epel/RPM-GPG-KEY-EPEL-{state.config.release}",) - if config.local_mirror: + if state.config.local_mirror: return - if config.mirror: + if state.config.mirror: for repo, dir in ( ("epel", "epel"), ("epel-next", "epel/next"), @@ -297,19 +295,19 @@ class Installer(DistributionInstaller): ): yield Repo( repo, - f"baseurl={join_mirror(config, f'{dir}/$releasever/Everything/$basearch')}", + f"baseurl={join_mirror(state.config.mirror, f'{dir}/$releasever/Everything/$basearch')}", gpgurls, enabled=False, ) yield Repo( f"{repo}-debuginfo", - f"baseurl={join_mirror(config, f'{dir}/$releasever/Everything/$basearch/debug')}", + f"baseurl={join_mirror(state.config.mirror, f'{dir}/$releasever/Everything/$basearch/debug')}", gpgurls, enabled=False, ) yield Repo( f"{repo}-source", - f"baseurl={join_mirror(config, f'{dir}/$releasever/Everything/source/tree')}", + f"baseurl={join_mirror(state.config.mirror, f'{dir}/$releasever/Everything/source/tree')}", gpgurls, enabled=False, ) @@ -338,8 +336,8 @@ class Installer(DistributionInstaller): ) @classmethod - def sig_repositories(cls, config: MkosiConfig) -> Iterable[Repo]: - if config.local_mirror: + def sig_repositories(cls, state: MkosiState) -> Iterable[Repo]: + if state.config.local_mirror: return sigs = ( @@ -362,47 +360,47 @@ class Installer(DistributionInstaller): gpgurls = tuple(gpgurls) for c in components: - if config.mirror: - if int(config.release) <= 8: + if state.config.mirror: + if int(state.config.release) <= 8: yield Repo( f"{sig}-{c}", - f"baseurl={join_mirror(config, f'centos/$stream/{sig}/$basearch/{c}')}", + f"baseurl={join_mirror(state.config.mirror, f'centos/$stream/{sig}/$basearch/{c}')}", gpgurls, enabled=False, ) yield Repo( f"{sig}-{c}-debuginfo", - f"baseurl={join_mirror(config, f'$stream/{sig}/$basearch')}", + f"baseurl={join_mirror(state.config.mirror, f'$stream/{sig}/$basearch')}", gpgurls, enabled=False, ) yield Repo( f"{sig}-{c}-source", - f"baseurl={join_mirror(config, f'centos/$stream/{sig}/Source')}", + f"baseurl={join_mirror(state.config.mirror, f'centos/$stream/{sig}/Source')}", gpgurls, enabled=False, ) else: yield Repo( f"{sig}-{c}", - f"baseurl={join_mirror(config, f'SIGs/$stream/{sig}/$basearch/{c}')}", + f"baseurl={join_mirror(state.config.mirror, f'SIGs/$stream/{sig}/$basearch/{c}')}", gpgurls, enabled=False, ) yield Repo( f"{sig}-{c}-debuginfo", - f"baseurl={join_mirror(config, f'SIGs/$stream/{sig}/$basearch/{c}/debug')}", + f"baseurl={join_mirror(state.config.mirror, f'SIGs/$stream/{sig}/$basearch/{c}/debug')}", gpgurls, enabled=False, ) yield Repo( f"{sig}-{c}-source", - f"baseurl={join_mirror(config, f'SIGs/$stream/{sig}/source/{c}')}", + f"baseurl={join_mirror(state.config.mirror, f'SIGs/$stream/{sig}/source/{c}')}", gpgurls, enabled=False, ) else: - if int(config.release) <= 8: + if int(state.config.release) <= 8: yield Repo( f"{sig}-{c}", f"mirrorlist=http://mirrorlist.centos.org/?release=$stream&arch=$basearch&repo={sig}-{c}", @@ -450,7 +448,7 @@ class Installer(DistributionInstaller): enabled=False, ) - if int(config.release) >= 9: + if int(state.config.release) >= 9: yield Repo( f"{sig}-{c}-testing-debuginfo", f"baseurl=https://buildlogs.centos.org/centos/$stream/{sig}/$basearch/{c}", diff --git a/mkosi/distributions/rhel_ubi.py b/mkosi/distributions/rhel_ubi.py index eb1884f7d..a8abbb99f 100644 --- a/mkosi/distributions/rhel_ubi.py +++ b/mkosi/distributions/rhel_ubi.py @@ -2,9 +2,9 @@ from collections.abc import Iterable -from mkosi.config import MkosiConfig from mkosi.distributions import centos from mkosi.installer.dnf import Repo +from mkosi.state import MkosiState class Installer(centos.Installer): @@ -13,42 +13,44 @@ class Installer(centos.Installer): return "RHEL UBI" @staticmethod - def gpgurls(config: MkosiConfig) -> tuple[str, ...]: + def gpgurls(state: MkosiState) -> tuple[str, ...]: return ("https://access.redhat.com/security/data/fd431d51.txt",) @classmethod - def repository_variants(cls, config: MkosiConfig, repo: str) -> Iterable[Repo]: - if config.local_mirror: - yield Repo(repo, f"baseurl={config.local_mirror}", cls.gpgurls(config)) + def repository_variants(cls, state: MkosiState, repo: str) -> Iterable[Repo]: + if state.config.local_mirror: + yield Repo(repo, f"baseurl={state.config.local_mirror}", cls.gpgurls(state)) else: - v = config.release + assert state.config.mirror + + v = state.config.release yield Repo( f"ubi-{v}-{repo}-rpms", - f"baseurl={centos.join_mirror(config, f'ubi{v}/{v}/$basearch/{repo}/os')}", - cls.gpgurls(config), + f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/os')}", + cls.gpgurls(state), ) yield Repo( f"ubi-{v}-{repo}-debug-rpms", - f"baseurl={centos.join_mirror(config, f'ubi{v}/{v}/$basearch/{repo}/debug')}", - cls.gpgurls(config), + f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/debug')}", + cls.gpgurls(state), enabled=False, ) yield Repo( f"ubi-{v}-{repo}-source", - f"baseurl={centos.join_mirror(config, f'ubi{v}/{v}/$basearch/{repo}/source')}", - cls.gpgurls(config), + f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/source')}", + cls.gpgurls(state), enabled=False, ) if repo == "codeready-builder": yield Repo( f"ubi-{v}-{repo}", - f"baseurl={centos.join_mirror(config, f'ubi{v}/{v}/$basearch/{repo}/os')}", - cls.gpgurls(config), + f"baseurl={centos.join_mirror(state.config.mirror, f'ubi{v}/{v}/$basearch/{repo}/os')}", + cls.gpgurls(state), enabled=False, ) @classmethod - def repositories(cls, config: MkosiConfig, release: int) -> Iterable[Repo]: - yield from cls.repository_variants(config, "baseos") - yield from cls.repository_variants(config, "appstream") - yield from cls.repository_variants(config, "codeready-builder") + def repositories(cls, state: MkosiState, release: int) -> Iterable[Repo]: + yield from cls.repository_variants(state, "baseos") + yield from cls.repository_variants(state, "appstream") + yield from cls.repository_variants(state, "codeready-builder") diff --git a/mkosi/distributions/rocky.py b/mkosi/distributions/rocky.py index 6f4e87cc2..3db9e930f 100644 --- a/mkosi/distributions/rocky.py +++ b/mkosi/distributions/rocky.py @@ -2,9 +2,9 @@ from pathlib import Path -from mkosi.config import MkosiConfig from mkosi.distributions import centos from mkosi.installer.dnf import Repo +from mkosi.state import MkosiState class Installer(centos.Installer): @@ -13,22 +13,22 @@ class Installer(centos.Installer): return "Rocky Linux" @staticmethod - def gpgurls(config: MkosiConfig) -> tuple[str, ...]: - gpgpath = Path(f"/usr/share/distribution-gpg-keys/rocky/RPM-GPG-KEY-Rocky-{config.release}") + def gpgurls(state: MkosiState) -> tuple[str, ...]: + gpgpath = Path(f"/usr/share/distribution-gpg-keys/rocky/RPM-GPG-KEY-Rocky-{state.config.release}") if gpgpath.exists(): return (f"file://{gpgpath}",) else: return ("https://download.rockylinux.org/pub/rocky/RPM-GPG-KEY-Rocky-$releasever",) @classmethod - def repository_variants(cls, config: MkosiConfig, repo: str) -> list[Repo]: - if config.mirror: - url = f"baseurl={config.mirror}/rocky/$releasever/{repo}/$basearch/os" + def repository_variants(cls, state: MkosiState, repo: str) -> list[Repo]: + if state.config.mirror: + url = f"baseurl={state.config.mirror}/rocky/$releasever/{repo}/$basearch/os" else: url = f"mirrorlist=https://mirrors.rockylinux.org/mirrorlist?arch=$basearch&repo={repo}-$releasever" - return [Repo(repo, url, cls.gpgurls(config))] + return [Repo(repo, url, cls.gpgurls(state))] @classmethod - def sig_repositories(cls, config: MkosiConfig) -> list[Repo]: + def sig_repositories(cls, state: MkosiState) -> list[Repo]: return []