repo_bootstrap: simplify custom mirrors (MR 2252)

We now have support for having mirrors per-aports repo, drop the
mirrors_postmarketos arg from chroot.init and instead have
repo_bootstrap call apk.update_repository_list() explicitly to exclude
the mirrors for the repository we're going to update.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
Caleb Connolly 2024-06-10 02:37:04 +02:00 committed by Oliver Smith
parent 807424ee2b
commit 15ffc2f370
No known key found for this signature in database
GPG key ID: 5AE7F5513E0885CB
4 changed files with 16 additions and 14 deletions

View file

@ -24,14 +24,14 @@ from pmb.core import Chroot, get_context
from pmb.types import PathString from pmb.types import PathString
@Cache("chroot") @Cache("chroot", mirrors_exclude=[])
def update_repository_list(chroot: Chroot, postmarketos_mirror=True, def update_repository_list(chroot: Chroot, mirrors_exclude: List[str]=[],
check=False): check=False):
""" """
Update /etc/apk/repositories, if it is outdated (when the user changed the Update /etc/apk/repositories, if it is outdated (when the user changed the
--mirror-alpine or --mirror-pmOS parameters). --mirror-alpine or --mirror-pmOS parameters).
:param postmarketos_mirror: add postmarketos mirror URLs :param mirrors_exclude: mirrors to exclude from the repository list
:param check: This function calls it self after updating the :param check: This function calls it self after updating the
/etc/apk/repositories file, to check if it was successful. /etc/apk/repositories file, to check if it was successful.
Only for this purpose, the "check" parameter should be set to Only for this purpose, the "check" parameter should be set to
@ -50,8 +50,7 @@ def update_repository_list(chroot: Chroot, postmarketos_mirror=True,
pmb.helpers.run.root(["mkdir", "-p", path.parent]) pmb.helpers.run.root(["mkdir", "-p", path.parent])
# Up to date: Save cache, return # Up to date: Save cache, return
exclude = ["pmaports"] if not postmarketos_mirror else [] lines_new = pmb.helpers.repo.urls(mirrors_exclude=mirrors_exclude)
lines_new = pmb.helpers.repo.urls(mirrors_exclude=exclude)
if lines_old == lines_new: if lines_old == lines_new:
return return
@ -66,7 +65,7 @@ def update_repository_list(chroot: Chroot, postmarketos_mirror=True,
for line in lines_new: for line in lines_new:
pmb.helpers.run.root(["sh", "-c", "echo " pmb.helpers.run.root(["sh", "-c", "echo "
f"{shlex.quote(line)} >> {path}"]) f"{shlex.quote(line)} >> {path}"])
update_repository_list(chroot, postmarketos_mirror, True) update_repository_list(chroot, mirrors_exclude, True)
@Cache("chroot") @Cache("chroot")

View file

@ -9,6 +9,7 @@ import os
import pmb.chroot import pmb.chroot
import pmb.chroot.binfmt import pmb.chroot.binfmt
import pmb.chroot.apk
import pmb.chroot.apk_static import pmb.chroot.apk_static
import pmb.config import pmb.config
import pmb.config.workdir import pmb.config.workdir
@ -97,8 +98,7 @@ def warn_if_chroot_is_outdated(chroot: Chroot):
@Cache("chroot") @Cache("chroot")
def init(chroot: Chroot, usr_merge=UsrMerge.AUTO, def init(chroot: Chroot, usr_merge=UsrMerge.AUTO):
postmarketos_mirror=True):
""" """
Initialize a chroot by copying the resolv.conf and updating Initialize a chroot by copying the resolv.conf and updating
/etc/apk/repositories. If /bin/sh is missing, create the chroot from /etc/apk/repositories. If /bin/sh is missing, create the chroot from
@ -107,7 +107,6 @@ def init(chroot: Chroot, usr_merge=UsrMerge.AUTO,
:param usr_merge: set to ON to force having a merged /usr. With AUTO it is :param usr_merge: set to ON to force having a merged /usr. With AUTO it is
only done if the user chose to install systemd in only done if the user chose to install systemd in
pmbootstrap init. pmbootstrap init.
:param postmarketos_mirror: add postmarketos mirror URLs
""" """
# When already initialized: just prepare the chroot # When already initialized: just prepare the chroot
arch = chroot.arch arch = chroot.arch
@ -119,14 +118,14 @@ def init(chroot: Chroot, usr_merge=UsrMerge.AUTO,
if (chroot / "bin/sh").is_symlink(): if (chroot / "bin/sh").is_symlink():
pmb.config.workdir.chroot_check_channel(chroot) pmb.config.workdir.chroot_check_channel(chroot)
copy_resolv_conf(chroot) copy_resolv_conf(chroot)
pmb.chroot.apk.update_repository_list(chroot, postmarketos_mirror) pmb.chroot.apk.update_repository_list(chroot)
warn_if_chroot_is_outdated(chroot) warn_if_chroot_is_outdated(chroot)
return return
# Require apk-tools-static # Require apk-tools-static
pmb.chroot.apk_static.init() pmb.chroot.apk_static.init()
logging.info(f"({chroot}) install alpine-base") logging.info(f"({chroot}) Creating chroot")
# Initialize cache # Initialize cache
apk_cache = config.work / f"cache_apk_{arch}" apk_cache = config.work / f"cache_apk_{arch}"
@ -136,7 +135,7 @@ def init(chroot: Chroot, usr_merge=UsrMerge.AUTO,
# Initialize /etc/apk/keys/, resolv.conf, repositories # Initialize /etc/apk/keys/, resolv.conf, repositories
init_keys() init_keys()
copy_resolv_conf(chroot) copy_resolv_conf(chroot)
pmb.chroot.apk.update_repository_list(chroot, postmarketos_mirror) pmb.chroot.apk.update_repository_list(chroot)
pmb.config.workdir.chroot_save_init(chroot) pmb.config.workdir.chroot_save_init(chroot)

View file

@ -79,6 +79,8 @@ def zap(confirm=True, dry=False, pkgs_local=False, http=False,
# Chroots were zapped, so no repo lists exist anymore # Chroots were zapped, so no repo lists exist anymore
Cache.clear_cache(pmb.chroot.apk.update_repository_list) Cache.clear_cache(pmb.chroot.apk.update_repository_list)
# Let chroot.init be called again
Cache.clear_cache(pmb.chroot.init)
# Print amount of cleaned up space # Print amount of cleaned up space
if dry: if dry:

View file

@ -10,8 +10,9 @@ import glob
import pmb.config.pmaports import pmb.config.pmaports
import pmb.helpers.repo import pmb.helpers.repo
import pmb.build import pmb.build
import pmb.chroot
import pmb.chroot.apk
from pmb.build import BuildQueueItem from pmb.build import BuildQueueItem
from pmb.core import Config
from pmb.core import get_context from pmb.core import get_context
from pmb import commands from pmb import commands
@ -111,7 +112,8 @@ class RepoBootstrap(commands.Command):
self.log_progress(f"initializing {chroot} chroot (merge /usr: {usr_merge.name})") self.log_progress(f"initializing {chroot} chroot (merge /usr: {usr_merge.name})")
# Initialize without pmOS binary package repo # Initialize without pmOS binary package repo
pmb.chroot.init(chroot, usr_merge, postmarketos_mirror=False) pmb.chroot.apk.update_repository_list(chroot, mirrors_exclude=[self.repo])
pmb.chroot.init(chroot, usr_merge)
bootstrap_stage = int(step.split("bootstrap_", 1)[1]) bootstrap_stage = int(step.split("bootstrap_", 1)[1])
def log_wrapper(pkg: BuildQueueItem): def log_wrapper(pkg: BuildQueueItem):