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 v4 06/13] meta: Use cached base-apt repo to debootstrap
Date: Wed, 22 Feb 2023 07:41:18 +0100	[thread overview]
Message-ID: <20230222064125.22754-7-ubely@ilbers.de> (raw)
In-Reply-To: <20230222064125.22754-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.inc         | 92 ++++++++++++++++---
 1 file changed, 78 insertions(+), 14 deletions(-)

diff --git a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
index 01668b93..4a3ef919 100644
--- a/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
+++ b/meta/recipes-core/isar-bootstrap/isar-bootstrap.inc
@@ -29,6 +29,8 @@ DISTRO_BOOTSTRAP_BASE_PACKAGES:append:https-support = ",ca-certificates"
 DISTRO_VARS_PREFIX ?= "${@'HOST_' if d.getVar('BOOTSTRAP_FOR_HOST') == '1' else ''}"
 BOOTSTRAP_DISTRO = "${@d.getVar('HOST_DISTRO' if d.getVar('BOOTSTRAP_FOR_HOST') == '1' else 'DISTRO')}"
 BOOTSTRAP_BASE_DISTRO = "${@d.getVar('HOST_BASE_DISTRO' if d.getVar('BOOTSTRAP_FOR_HOST') == '1' else 'BASE_DISTRO')}"
+BOOTSTRAP_DISTRO_ARCH = "${@d.getVar('HOST_ARCH' if d.getVar('BOOTSTRAP_FOR_HOST') == '1' else 'DISTRO_ARCH')}"
+
 FILESEXTRAPATHS:append = ":${BBPATH}"
 
 inherit deb-dl-dir
@@ -273,12 +275,69 @@ do_bootstrap[dirs] = "${DEPLOY_DIR_BOOTSTRAP}"
 do_bootstrap[depends] = "base-apt:do_cache isar-apt:do_cache_config"
 do_bootstrap[network] = "${TASK_USE_NETWORK_AND_SUDO}"
 
+inherit debrepo
+
+debrepo_bootstrap_prepare() {
+    if [ "${ISAR_USE_CACHED_BASE_REPO}" = "1" ]; then
+        return
+    fi
+
+    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_USE_CACHED_BASE_REPO}" = "1" ]; then
+        debrepo_args="$debrepo_args --no-check-gpg"
+    #fi
+    if [ "${ISAR_ENABLE_COMPAT_ARCH}" = "1" ]; then
+        debrepo_args="$debrepo_args --compatarch=${COMPAT_DISTRO_ARCH}"
+    fi
+
+    debrepo_workdir=${DEBREPO_TARGET_DIR}
+    if [ "${BOOTSTRAP_FOR_HOST}" = "1" ]; then
+        debrepo_args="$debrepo_args --crossarch=${DISTRO_ARCH}"
+        if [ ${HOST_ARCH} != ${DISTRO_ARCH} ]; then
+            debrepo_workdir=${DEBREPO_HOST_DIR}
+        fi
+    else
+        debrepo_args="$debrepo_args --isaraptdir=${REPO_ISAR_DIR}/${DISTRO}"
+    fi
+    mkdir -p "${DEBREPO_WORKDIR}"
+
+    if [ -n "${GNUPGHOME}" ]; then
+        export GNUPGHOME="${GNUPGHOME}"
+    fi
+
+    flock -x "${DEBREPO_WORKDIR}/repo.lock" -c "
+        ${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} \
+            gnupg locales usr-is-merged
+    "
+}
+
 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}"
@@ -292,19 +351,21 @@ do_bootstrap() {
     sudo rm -rf --one-file-system "${ROOTFSDIR}"
     deb_dl_dir_import "${ROOTFSDIR}" "${BOOTSTRAP_BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
 
+    (flock 9
     sudo -E -s <<'EOSUDO'
         set -e
         if [ "${BOOTSTRAP_FOR_HOST}" = "0" ]; then
-            arch_param="--arch=${DISTRO_ARCH}"
+            arch_param="--arch=${BOOTSTRAP_DISTRO_ARCH}"
         fi
-        ${DEBOOTSTRAP} $debootstrap_args \
-                       $arch_param \
-                       ${@get_distro_components_argument(d)} \
-                       "${@get_distro_suite(d)}" \
-                       "${ROOTFSDIR}" \
-                       "${@get_distro_source(d)}" \
-                       ${DISTRO_DEBOOTSTRAP_SCRIPT}
-
+        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}
+        "
         # Install apt config
         mkdir -p "${ROOTFSDIR}/etc/apt/preferences.d"
         install -v -m644 "${APTPREFS}" \
@@ -373,11 +434,13 @@ do_bootstrap() {
             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
+        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
+        "
 
         umount -l "${ROOTFSDIR}/dev/shm"
         umount -l "${ROOTFSDIR}/dev/pts"
@@ -389,6 +452,7 @@ do_bootstrap() {
         # Finalize debootstrap by setting the link in deploy
         ln -Tfsr "${ROOTFSDIR}" "${DEPLOY_ISAR_BOOTSTRAP}"
 EOSUDO
+    ) 9>"${DEBREPO_WORKDIR}/repo.lock"
     deb_dl_dir_export "${ROOTFSDIR}" "${BOOTSTRAP_BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
 
     # Cleanup apt cache
-- 
2.20.1


  parent reply	other threads:[~2023-02-22  6:41 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-22  6:41 [PATCH v4 00/13] Improving base-apt usage PoC Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 01/13] scripts: Add debrepo python script handling base-apt Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 02/13] meta: Add debrepo bbclass handling base-apt prefetching Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 03/13] meta-isar: Add local ubuntu-focal public key Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 04/13] meta: Always use base-apt repo in local mode Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 05/13] meta: move base-apt from deploy directory to the top Uladzimir Bely
2023-02-22  6:41 ` Uladzimir Bely [this message]
2023-02-22  6:41 ` [PATCH v4 07/13] meta: Setup debrepo context for dpkg-base Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 08/13] meta: Setup debrepo context for buildchroot Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 09/13] meta: Setup debrepo context for sbuild-chroot Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 10/13] base-apt: Predownload packages to base-apt before install Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 11/13] meta: Add cache-deb-src functionality to base-apt Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 12/13] meta: Specify grub-efi packages arch Uladzimir Bely
2023-02-22  6:41 ` [PATCH v4 13/13] isar-apt: Fix copying isar-apt to workdir 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=20230222064125.22754-7-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