From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH v5 2/9] imager: Migrate from buildchroot to schroot
Date: Wed, 31 May 2023 14:12:29 +0300 [thread overview]
Message-ID: <20230531111236.104373-3-amikan@ilbers.de> (raw)
In-Reply-To: <20230531111236.104373-1-amikan@ilbers.de>
Install dependencies and perform all imager actions using schroot
instead of buildchroot. All the changes made during imager task will be
lost after the finish. This requires installing imager dependencies
during every run.
Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
meta/classes/image-tools-extension.bbclass | 97 +++++++++++++++-------
1 file changed, 66 insertions(+), 31 deletions(-)
diff --git a/meta/classes/image-tools-extension.bbclass b/meta/classes/image-tools-extension.bbclass
index 7c84505f..04ed1f84 100644
--- a/meta/classes/image-tools-extension.bbclass
+++ b/meta/classes/image-tools-extension.bbclass
@@ -5,43 +5,78 @@
#
# This file extends the image.bbclass to supply tools for futher imager functions
-inherit buildchroot
+inherit sbuild
IMAGER_INSTALL ??= ""
IMAGER_BUILD_DEPS ??= ""
DEPENDS += "${IMAGER_BUILD_DEPS}"
-do_install_imager_deps[depends] = "${BUILDCHROOT_DEP} isar-apt:do_cache_config"
-do_install_imager_deps[deptask] = "do_deploy_deb"
-do_install_imager_deps[lockfiles] += "${REPO_ISAR_DIR}/isar.lock"
-do_install_imager_deps[network] = "${TASK_USE_NETWORK_AND_SUDO}"
-do_install_imager_deps() {
- if [ -z "${@d.getVar("IMAGER_INSTALL").strip()}" ]; then
- exit
- fi
+SCHROOT_MOUNTS = "${WORKDIR}:${PP_WORK} ${IMAGE_ROOTFS}:${PP_ROOTFS} ${DEPLOY_DIR_IMAGE}:${PP_DEPLOY}"
+SCHROOT_MOUNTS += "${REPO_ISAR_DIR}/${DISTRO}:/isar-apt"
+
+imager_run() {
+ schroot_create_configs
+ insert_mounts
+
+ session_id=$(schroot -q -b -c ${SBUILD_CHROOT})
+ echo "Started session: ${session_id}"
+
+ # Schroot session mountpoint for deb downloads import/export
+ schroot_dir="/var/run/schroot/mount/${session_id}"
+
+ # setting up error handler
+ imager_cleanup() {
+ set +e
+ schroot -q -f -e -c ${session_id} > /dev/null 2>&1
+ remove_mounts > /dev/null 2>&1
+ schroot_delete_configs > /dev/null 2>&1
+ }
+ trap 'exit 1' INT HUP QUIT TERM ALRM USR1
+ trap 'imager_cleanup' EXIT
+
+ if [ -n "${@d.getVar("IMAGER_INSTALL").strip()}" ]; then
+ echo "Installing deps: ${IMAGER_INSTALL}"
- distro="${BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
- if [ ${ISAR_CROSS_COMPILE} -eq 1 ]; then
- distro="${HOST_BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
+ distro="${BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
+ if [ ${ISAR_CROSS_COMPILE} -eq 1 ]; then
+ distro="${HOST_BASE_DISTRO}-${BASE_DISTRO_CODENAME}"
+ fi
+
+ # prepare isar-apt
+ schroot -r -c ${session_id} -d / -u root -- sh -c " \
+ mkdir -p '/etc/apt/sources.list.d'
+ echo 'deb [trusted=yes] file:///isar-apt ${DEBDISTRONAME} main' > \
+ '/etc/apt/sources.list.d/isar-apt.list'
+
+ mkdir -p '/etc/apt/preferences.d'
+ cat << EOF > '/etc/apt/preferences.d/isar-apt'
+Package: *
+Pin: release n=${DEBDISTRONAME}
+Pin-Priority: 1000
+EOF"
+
+ E="${@ isar_export_proxies(d)}"
+ deb_dl_dir_import ${schroot_dir} ${distro}
+ schroot -r -c ${session_id} -d / -u root -- sh -c " \
+ apt-get update \
+ -o Dir::Etc::SourceList='sources.list.d/isar-apt.list' \
+ -o Dir::Etc::SourceParts='-' \
+ -o APT::Get::List-Cleanup='0'
+ apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y \
+ --allow-unauthenticated --allow-downgrades --download-only install \
+ ${IMAGER_INSTALL}"
+
+ deb_dl_dir_export ${schroot_dir} ${distro}
+ schroot -r -c ${session_id} -d / -u root -- sh -c " \
+ apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y \
+ --allow-unauthenticated --allow-downgrades install \
+ ${IMAGER_INSTALL}"
fi
- buildchroot_do_mounts
-
- E="${@ isar_export_proxies(d)}"
- deb_dl_dir_import ${BUILDCHROOT_DIR} ${distro}
- sudo -E chroot ${BUILDCHROOT_DIR} sh -c ' \
- apt-get update \
- -o Dir::Etc::SourceList="sources.list.d/isar-apt.list" \
- -o Dir::Etc::SourceParts="-" \
- -o APT::Get::List-Cleanup="0"
- apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y \
- --allow-unauthenticated --allow-downgrades --download-only install \
- ${IMAGER_INSTALL}'
-
- deb_dl_dir_export ${BUILDCHROOT_DIR} ${distro}
- sudo -E chroot ${BUILDCHROOT_DIR} sh -c ' \
- apt-get -o Debug::pkgProblemResolver=yes --no-install-recommends -y \
- --allow-unauthenticated --allow-downgrades install \
- ${IMAGER_INSTALL}'
+ schroot -r -c ${session_id} "$@"
+
+ schroot -e -c ${session_id}
+
+ remove_mounts
+ schroot_delete_configs
}
-addtask install_imager_deps before do_image_tools
--
2.34.1
next prev parent reply other threads:[~2023-05-31 11:12 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 11:12 [PATCH v5 0/9] Imager schroot migration Anton Mikanovich
2023-05-31 11:12 ` [PATCH v5 1/9] isar-apt: Move cleanup to postprocessing Anton Mikanovich
2023-05-31 11:12 ` Anton Mikanovich [this message]
2023-05-31 11:12 ` [PATCH v5 3/9] imager: Move image types to schroot Anton Mikanovich
2023-05-31 11:12 ` [PATCH v5 4/9] imager: Split imager deps between image types Anton Mikanovich
2023-05-31 11:12 ` [PATCH v5 5/9] CI: Fix used chroot recipe name Anton Mikanovich
2023-05-31 11:12 ` [PATCH v5 6/9] meta: Remove buildchroot Anton Mikanovich
2023-05-31 11:12 ` [PATCH v5 7/9] dpkg-gbp: Remove unused mounts Anton Mikanovich
2023-05-31 11:12 ` [PATCH v5 8/9] doc: Update chroot documentation Anton Mikanovich
2023-05-31 11:12 ` [PATCH v5 9/9] RECIPE-API-CHANGELOG.md: Describe imager changes Anton Mikanovich
2023-07-13 13:33 ` [PATCH v5 0/9] Imager schroot migration 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=20230531111236.104373-3-amikan@ilbers.de \
--to=amikan@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