public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Uladzimir Bely <ubely@ilbers.de>
To: isar-users@googlegroups.com
Subject: [PATCH v7 04/10] meta: Use cached base-apt repo to debootstrap
Date: Thu, 25 Jul 2024 18:07:36 +0300	[thread overview]
Message-ID: <20240725151006.2129-5-ubely@ilbers.de> (raw)
In-Reply-To: <20240725151006.2129-1-ubely@ilbers.de>

This patch makes local base-apt repo to be created before
debootstrap task. So, debootstrap is then done from it.

The required packages are downloaded via python-apt and
reprepro creates debian-like repository from .deb files.

For debian targets host keyring is used while ubuntu/raspbian
targets use keys specified by DISTRO_BOOTSTRAP_KEYS variable.

The goal is have workable base-apt repo before first build completed.

Signed-off-by: Uladzimir Bely <ubely@ilbers.de>
---
 .../isar-bootstrap/isar-bootstrap-host.bb     |  2 +
 .../isar-bootstrap/isar-bootstrap.inc         | 87 +++++++++++++++++--
 2 files changed, 81 insertions(+), 8 deletions(-)

diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap-host.bb b/meta/recipes-core/isar-bootstrap/isar-bootstrap-host.bb
index 4f90fd01..1ace818f 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap-host.bb
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap-host.bb
@@ -15,3 +15,5 @@ require isar-bootstrap.inc
 
 HOST_DISTRO_BOOTSTRAP_KEYS ?= ""
 DISTRO_BOOTSTRAP_KEYS = "${HOST_DISTRO_BOOTSTRAP_KEYS}"
+
+DEBREPO_WORKDIR = "${DEBREPO_HOST_DIR}"
diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
index 9fd928ad..589fa2c1 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
@@ -33,6 +33,13 @@ DISTRO_BOOTSTRAP_BASE_PACKAGES:append:https-support = ",ca-certificates"
 DISTRO_VARS_PREFIX ?= "${@'HOST_' if bb.utils.to_boolean(d.getVar('BOOTSTRAP_FOR_HOST')) else ''}"
 BOOTSTRAP_DISTRO = "${@d.getVar('HOST_DISTRO' if bb.utils.to_boolean(d.getVar('BOOTSTRAP_FOR_HOST')) else 'DISTRO')}"
 BOOTSTRAP_BASE_DISTRO = "${@d.getVar('HOST_BASE_DISTRO' if bb.utils.to_boolean(d.getVar('BOOTSTRAP_FOR_HOST')) else 'BASE_DISTRO')}"
+BOOTSTRAP_DISTRO_ARCH = "${@d.getVar('HOST_ARCH' if d.getVar('BOOTSTRAP_FOR_HOST') == '1' else 'DISTRO_ARCH')}"
+
+# For newer distros "usr-is-merged" indirectly required by debootstrap
+DISTRO_BOOTSTRAP_BASE_PACKAGES:append:bookworm = ",usr-is-merged"
+DISTRO_BOOTSTRAP_BASE_PACKAGES:append:sid = ",usr-is-merged"
+DISTRO_BOOTSTRAP_BASE_PACKAGES:append:sid-ports = ",usr-is-merged"
+
 FILESEXTRAPATHS:append = ":${BBPATH}"
 APT_SNAPSHOT_DATE = "${@ get_apt_snapshot_date(d)}"
 
@@ -291,12 +298,56 @@ do_bootstrap[network] = "${TASK_USE_NETWORK_AND_SUDO}"
 
 inherit compat
 
+inherit debrepo
+
+debrepo_bootstrap_prepare() {
+    [ "${ISAR_PREFETCH_BASE_APT}" != "1" ] && return
+    [ "${ISAR_USE_CACHED_BASE_REPO}" = "1" ] && return
+
+    debrepo_args=""
+    if [ "${BASE_DISTRO}" != "debian" ]; then
+        if [ "${BASE_DISTRO}" != "raspbian" ] && [ "${BASE_DISTRO}" != "raspios" ] || [ "${BOOTSTRAP_FOR_HOST}" = "0" ]; then
+            debrepo_args="$debrepo_args --keydir=${WORKDIR}"
+        fi
+    else
+        if [ "${BASE_DISTRO_CODENAME}" = "sid" ]; then
+            debrepo_args="$debrepo_args --keydir=${WORKDIR}"
+        fi
+    fi
+    if [ "${ISAR_ENABLE_COMPAT_ARCH}" = "1" ]; then
+        debrepo_args="$debrepo_args --compatarch=${COMPAT_DISTRO_ARCH}"
+    fi
+
+    if [ "${BOOTSTRAP_FOR_HOST}" = "1" ]; then
+        debrepo_args="$debrepo_args --crossarch=${DISTRO_ARCH}"
+    fi
+
+    if [ -n "${GNUPGHOME}" ]; then
+        export GNUPGHOME="${GNUPGHOME}"
+    fi
+
+    ${SCRIPTSDIR}/debrepo --init \
+        --workdir="${DEBREPO_WORKDIR}" \
+        --aptsrcsfile="${APTSRCS_INIT}" \
+        --repodir="${REPO_BASE_DIR}" \
+        --repodbdir="${REPO_BASE_DB_DIR}" \
+        --mirror="${@get_distro_source(d)}" \
+        --arch="${BOOTSTRAP_DISTRO_ARCH}" \
+        --distro="${BOOTSTRAP_BASE_DISTRO}" \
+        --codename="${BASE_DISTRO_CODENAME}" \
+        ${debrepo_args} \
+        ${DISTRO_BOOTSTRAP_BASE_PACKAGES}
+}
+
 do_bootstrap() {
     if [ "${ISAR_ENABLE_COMPAT_ARCH}" = "1" ]; then
         if [ -z "${COMPAT_DISTRO_ARCH}" ]; then
             bbfatal "${DISTRO_ARCH} does not have a compat arch"
         fi
     fi
+
+    debrepo_bootstrap_prepare
+
     debootstrap_args="--verbose --variant=minbase --include=${DISTRO_BOOTSTRAP_BASE_PACKAGES}"
     if [ -f "${DISTRO_BOOTSTRAP_KEYRING}" ]; then
         debootstrap_args="$debootstrap_args --keyring=${DISTRO_BOOTSTRAP_KEYRING}"
@@ -314,8 +365,19 @@ do_bootstrap() {
     sudo -E -s <<'EOSUDO'
         set -e
         if [ "${BOOTSTRAP_FOR_HOST}" = "0" ]; then
-            arch_param="--arch=${DISTRO_ARCH}"
+            arch_param="--arch=${BOOTSTRAP_DISTRO_ARCH}"
         fi
+        if [ "${ISAR_PREFETCH_BASE_APT}" = "1" ]; then
+            flock -x "${REPO_BASE_DIR}/repo.lock" -c "
+                ${DEBOOTSTRAP} $debootstrap_args \
+                            $arch_param \
+                            ${@get_distro_components_argument(d)} \
+                            ${@get_distro_suite(d)} \
+                            ${ROOTFSDIR} \
+                            file://${REPO_BASE_DIR}/${BOOTSTRAP_BASE_DISTRO} \
+                            ${DISTRO_DEBOOTSTRAP_SCRIPT}
+            "
+        else
         ${DEBOOTSTRAP} $debootstrap_args \
                        $arch_param \
                        ${@get_distro_components_argument(d)} \
@@ -323,7 +385,7 @@ do_bootstrap() {
                        "${ROOTFSDIR}" \
                        "${@get_distro_source(d)}" \
                        ${DISTRO_DEBOOTSTRAP_SCRIPT}
-
+        fi
         # Install apt config
         mkdir -p "${ROOTFSDIR}/etc/apt/preferences.d"
         install -v -m644 "${APTPREFS}" \
@@ -395,12 +457,21 @@ do_bootstrap() {
         if [ "${ISAR_ENABLE_COMPAT_ARCH}" = "1" ]; then
             chroot "${ROOTFSDIR}" /usr/bin/dpkg --add-architecture ${COMPAT_DISTRO_ARCH}
         fi
-
-        chroot "${ROOTFSDIR}" /usr/bin/apt-get update -y \
-                                -o APT::Update::Error-Mode=any
-        chroot "${ROOTFSDIR}" /usr/bin/apt-get install -y -f
-        chroot "${ROOTFSDIR}" /usr/bin/apt-get dist-upgrade -y \
-                                -o Debug::pkgProblemResolver=yes
+        if [ "${ISAR_PREFETCH_BASE_APT}" = "1" ]; then
+            flock -x "${REPO_BASE_DIR}/repo.lock" -c "
+                chroot ${ROOTFSDIR} /usr/bin/apt-get update -y \
+                                        -o APT::Update::Error-Mode=any
+                chroot ${ROOTFSDIR} /usr/bin/apt-get install -y -f
+                chroot ${ROOTFSDIR} /usr/bin/apt-get dist-upgrade -y \
+                                        -o Debug::pkgProblemResolver=yes
+            "
+        else
+            chroot ${ROOTFSDIR} /usr/bin/apt-get update -y \
+                                    -o APT::Update::Error-Mode=any
+            chroot ${ROOTFSDIR} /usr/bin/apt-get install -y -f
+            chroot ${ROOTFSDIR} /usr/bin/apt-get dist-upgrade -y \
+                                    -o Debug::pkgProblemResolver=yes
+        fi
 
         umount "${ROOTFSDIR}/dev/shm"
         umount "${ROOTFSDIR}/dev/pts"
-- 
2.44.2

-- 
You received this message because you are subscribed to the Google Groups "isar-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to isar-users+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/isar-users/20240725151006.2129-5-ubely%40ilbers.de.

  parent reply	other threads:[~2024-07-25 15:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-25 15:07 [PATCH v7 00/10] Improving base-apt usage Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 01/10] scripts: Add debrepo python script handling base-apt Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 02/10] meta: Add debrepo bbclass handling base-apt prefetching Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 03/10] meta: Always use base-apt repo in local mode Uladzimir Bely
2024-07-25 15:07 ` Uladzimir Bely [this message]
2024-07-25 15:07 ` [PATCH v7 05/10] base-apt: Predownload packages to base-apt before install Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 06/10] meta: Add cache-deb-src functionality in base-apt mode Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 07/10] testsuite: Set ISAR_PREFETCH_BASE_APT by default Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 08/10] Disable deb-dl-dir in base-apt prefetch mode Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 09/10] kas: Add PREFETCH_BASE_APT config entry Uladzimir Bely
2024-07-25 15:07 ` [PATCH v7 10/10] ci_build.sh: Install python3-apt if not installed Uladzimir Bely
2024-08-01  8:57 ` [PATCH v7 00/10] Improving base-apt usage 'MOESSBAUER, Felix' via isar-users
2024-08-02  5:37   ` Uladzimir Bely

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240725151006.2129-5-ubely@ilbers.de \
    --to=ubely@ilbers.de \
    --cc=isar-users@googlegroups.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox