public inbox for isar-users@googlegroups.com
 help / color / mirror / Atom feed
From: Anton Mikanovich <amikan@ilbers.de>
To: isar-users@googlegroups.com
Cc: Anton Mikanovich <amikan@ilbers.de>
Subject: [PATCH v5 3/9] imager: Move image types to schroot
Date: Wed, 31 May 2023 14:12:30 +0300	[thread overview]
Message-ID: <20230531111236.104373-4-amikan@ilbers.de> (raw)
In-Reply-To: <20230531111236.104373-1-amikan@ilbers.de>

Run imagetype-related commands inside schroot session during images
prepare steps.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
---
 meta/classes/image.bbclass          |  7 ++-
 meta/classes/imagetypes_vm.bbclass  |  9 +--
 meta/classes/imagetypes_wic.bbclass | 89 ++++++++++-------------------
 3 files changed, 38 insertions(+), 67 deletions(-)

diff --git a/meta/classes/image.bbclass b/meta/classes/image.bbclass
index 53859eb9..42e4b0c9 100644
--- a/meta/classes/image.bbclass
+++ b/meta/classes/image.bbclass
@@ -163,7 +163,7 @@ inherit ${IMGCLASSES}
 # convenience variables to be used by CMDs
 IMAGE_FILE_HOST = "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.${type}"
 IMAGE_FILE_CHROOT = "${PP_DEPLOY}/${IMAGE_FULLNAME}.${type}"
-SUDO_CHROOT = "sudo chroot ${BUILDCHROOT_DIR}"
+SUDO_CHROOT = "imager_run -d ${PP_ROOTFS} -u root --"
 
 # hook up IMAGE_CMD_*
 python() {
@@ -235,7 +235,6 @@ python() {
             imager_build_deps.add(dep)
 
         # construct image command
-        cmds.append('\timage_do_mounts')
         image_cmd = localdata.getVar('IMAGE_CMD:' + bt_clean)
         if image_cmd:
             localdata.setVar('type', bt)
@@ -409,6 +408,10 @@ python do_image_tools() {
 }
 addtask image_tools before do_build after do_rootfs
 
+# all imagetypes are depend on schroot and isar-apt
+do_image_tools[depends] = "${SCHROOT_DEP} isar-apt:do_cache_config"
+do_image_tools[deptask] = "do_deploy_deb"
+
 python do_image() {
     """Virtual task"""
     pass
diff --git a/meta/classes/imagetypes_vm.bbclass b/meta/classes/imagetypes_vm.bbclass
index 41f2af06..782b60c1 100644
--- a/meta/classes/imagetypes_vm.bbclass
+++ b/meta/classes/imagetypes_vm.bbclass
@@ -4,8 +4,6 @@
 # This class allows to generate images for VMware and VirtualBox
 #
 
-inherit buildchroot
-
 OVF_TEMPLATE_FILE ?= "vm-img-virtualbox.ovf.tmpl"
 IMAGE_SRC_URI:ova = "file://${OVF_TEMPLATE_FILE}"
 
@@ -35,9 +33,8 @@ CONVERSION_OPTIONS = "${@set_convert_options(d)}"
 
 convert_wic() {
     rm -f '${DEPLOY_DIR_IMAGE}/${VIRTUAL_MACHINE_IMAGE_FILE}'
-    image_do_mounts
     bbnote "Creating ${VIRTUAL_MACHINE_IMAGE_FILE} from ${SOURCE_IMAGE_FILE}"
-    sudo -E  chroot --userspec=$( id -u ):$( id -g ) ${BUILDCHROOT_DIR} \
+    imager_run -p -d ${PP_WORK} -- \
     /usr/bin/qemu-img convert -f raw -O ${VIRTUAL_MACHINE_IMAGE_TYPE} ${CONVERSION_OPTIONS} \
         '${PP_DEPLOY}/${SOURCE_IMAGE_FILE}' '${VIRTUAL_MACHINE_DISK}'
 }
@@ -80,7 +77,7 @@ IMAGE_CMD:ova() {
     export LAST_CHANGE=$(date -u "+%Y-%m-%dT%H:%M:%SZ")
     export OVA_FIRMWARE_UPPERCASE=$(echo ${OVA_FIRMWARE} | tr '[a-z]' '[A-Z]')
     export OVF_TEMPLATE_STAGE2=$(echo ${OVF_TEMPLATE_FILE} | sed 's/.tmpl$//' )
-    sudo -Es chroot --userspec=$( id -u ):$( id -g ) ${BUILDCHROOT_DIR} <<'EOSUDO'
+    imager_run -p -d ${PP_WORK} <<'EOIMAGER'
         set -e
         export DISK_SIZE_BYTES=$(qemu-img info -f vmdk "${VIRTUAL_MACHINE_DISK}" \
                                  | gawk 'match($0, /^virtual size:.*\(([0-9]+) bytes\)/, a) {print a[1]}')
@@ -97,6 +94,6 @@ IMAGE_CMD:ova() {
             tar -uvf ${PP_DEPLOY}/${OVA_NAME}.ova -C ${PP_DEPLOY} ${OVA_NAME}.mf
         fi
         tar -uvf ${PP_DEPLOY}/${OVA_NAME}.ova -C ${PP_DEPLOY} ${VIRTUAL_MACHINE_IMAGE_FILE}
-EOSUDO
+EOIMAGER
 }
 IMAGE_CMD:ova[depends] = "${PN}:do_transform_template"
diff --git a/meta/classes/imagetypes_wic.bbclass b/meta/classes/imagetypes_wic.bbclass
index 5be53f60..9a0bc2b7 100644
--- a/meta/classes/imagetypes_wic.bbclass
+++ b/meta/classes/imagetypes_wic.bbclass
@@ -83,8 +83,6 @@ python () {
             bb.build.addtask('do_transform_template', 'do_image_wic', None, d)
 }
 
-inherit buildchroot
-
 IMAGER_INSTALL:wic += "${WIC_IMAGER_INSTALL}"
 # wic comes with reasonable defaults, and the proper interface is the wks file
 ROOTFS_EXTRA ?= "0"
@@ -95,7 +93,6 @@ STAGING_DIR ?= "${TMPDIR}"
 IMAGE_BASENAME ?= "${PN}-${DISTRO}"
 FAKEROOTCMD ?= "${SCRIPTSDIR}/wic_fakeroot"
 RECIPE_SYSROOT_NATIVE ?= "/"
-BUILDCHROOT_DIR = "${BUILDCHROOT_TARGET_DIR}"
 
 WIC_CREATE_EXTRA_ARGS ?= ""
 WIC_DEPLOY_PARTITIONS ?= "0"
@@ -145,26 +142,11 @@ check_for_wic_warnings() {
 
 do_image_wic[file-checksums] += "${WKS_FILE_CHECKSUM}"
 IMAGE_CMD:wic() {
-    wic_do_mounts
     generate_wic_image
     check_for_wic_warnings
 }
 
-wic_do_mounts[vardepsexclude] += "BITBAKEDIR"
-wic_do_mounts() {
-    buildchroot_do_mounts
-    sudo -s <<'EOSUDO'
-        ( flock 9
-        set -e
-        for dir in ${BBLAYERS} ${STAGING_DIR} ${SCRIPTSDIR} ${BITBAKEDIR}; do
-            mkdir -p ${BUILDCHROOT_DIR}/$dir
-            if ! mountpoint ${BUILDCHROOT_DIR}/$dir >/dev/null 2>&1; then
-                mount --bind --make-private $dir ${BUILDCHROOT_DIR}/$dir
-            fi
-        done
-        ) 9>${MOUNT_LOCKFILE}
-EOSUDO
-}
+SCHROOT_MOUNTS += "${BBLAYERS} ${STAGING_DIR} ${SCRIPTSDIR} ${BITBAKEDIR}"
 
 generate_wic_image[vardepsexclude] += "WKS_FULL_PATH BITBAKEDIR TOPDIR"
 generate_wic_image() {
@@ -177,50 +159,39 @@ generate_wic_image() {
     mkdir -p ${IMAGE_ROOTFS}/../pseudo
     touch ${IMAGE_ROOTFS}/../pseudo/files.db
 
-    # create the temp dir in the buildchroot to ensure uniqueness
-    WICTMP=$(cd ${BUILDCHROOT_DIR}; mktemp -d -p tmp)
-
-    sudo -E chroot ${BUILDCHROOT_DIR} \
-        sh -c ' \
-          BITBAKEDIR="$1"
-          SCRIPTSDIR="$2"
-          WKS_FULL_PATH="$3"
-          STAGING_DIR="$4"
-          MACHINE="$5"
-          WICTMP="$6"
-          IMAGE_FULLNAME="$7"
-          IMAGE_BASENAME="$8"
-          shift 8
-          # The python path is hard-coded as /usr/bin/python3-native/python3 in wic. Handle that.
-          mkdir -p /usr/bin/python3-native/
-          if [ $(head -1 $(which bmaptool) | grep python3) ];then
+    imager_run -p -d ${PP_WORK} -u root <<'EOIMAGER'
+        set -e
+
+        # The python path is hard-coded as /usr/bin/python3-native/python3 in wic. Handle that.
+        mkdir -p /usr/bin/python3-native/
+        if [ $(head -1 $(which bmaptool) | grep python3) ];then
             ln -fs /usr/bin/python3 /usr/bin/python3-native/python3
-          else
+        else
             ln -fs /usr/bin/python2 /usr/bin/python3-native/python3
-          fi
-          export PATH="$BITBAKEDIR/bin:$PATH"
-          "$SCRIPTSDIR"/wic create "$WKS_FULL_PATH" \
-            --vars "$STAGING_DIR/$MACHINE/imgdata/" \
-            -o "/$WICTMP/${IMAGE_FULLNAME}.wic/" \
+        fi
+
+        export PATH="${BITBAKEDIR}/bin:$PATH"
+
+        "${SCRIPTSDIR}"/wic create "${WKS_FULL_PATH}" \
+            --vars "${STAGING_DIR}/${MACHINE}/imgdata/" \
+            -o "/tmp/${IMAGE_FULLNAME}.wic/" \
             --bmap \
-            -e "$IMAGE_BASENAME" $@' \
-              my_script "${BITBAKEDIR}" "${SCRIPTSDIR}" "${WKS_FULL_PATH}" "${STAGING_DIR}" \
-              "${MACHINE}" "${WICTMP}" "${IMAGE_FULLNAME}" "${IMAGE_BASENAME}" \
-              ${WIC_CREATE_EXTRA_ARGS}
+            -e "${IMAGE_BASENAME}" ${WIC_CREATE_EXTRA_ARGS}
+
+        WIC_DIRECT=$(ls -t -1 /tmp/${IMAGE_FULLNAME}.wic/*.direct | head -1)
+        mv -f ${WIC_DIRECT} ${PP_DEPLOY}/${IMAGE_FULLNAME}.wic
+        mv -f ${WIC_DIRECT}.bmap ${PP_DEPLOY}/${IMAGE_FULLNAME}.wic.bmap
+        # deploy partition files if requested (ending with .p<x>)
+        if [ "${WIC_DEPLOY_PARTITIONS}" -eq "1" ]; then
+            # locate *.direct.p<x> partition files
+            find "/tmp/${IMAGE_FULLNAME}.wic/" -type f -regextype sed -regex ".*\.direct.*\.p[0-9]\{1,\}" | while read f; do
+                suffix=$(basename $f | sed 's/.*\.direct\(.*\)/\1/')
+                mv -f ${f} ${PP_DEPLOY}/${IMAGE_FULLNAME}.wic${suffix}
+            done
+        fi
+EOIMAGER
 
     sudo chown -R $(stat -c "%U" ${LAYERDIR_core}) ${LAYERDIR_core} ${LAYERDIR_isar} ${SCRIPTSDIR} || true
-    WIC_DIRECT=$(ls -t -1 ${BUILDCHROOT_DIR}/$WICTMP/${IMAGE_FULLNAME}.wic/*.direct | head -1)
-    sudo chown -R $(id -u):$(id -g) ${BUILDCHROOT_DIR}/${WICTMP}
-    mv -f ${WIC_DIRECT} ${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.wic
-    mv -f ${WIC_DIRECT}.bmap ${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.wic.bmap
-    # deploy partition files if requested (ending with .p<x>)
-    if [ "${WIC_DEPLOY_PARTITIONS}" -eq "1" ]; then
-        # locate *.direct.p<x> partition files
-        find ${BUILDCHROOT_DIR}/${WICTMP} -type f -regextype sed -regex ".*\.direct.*\.p[0-9]\{1,\}" | while read f; do
-            suffix=$(basename $f | sed 's/.*\.direct\(.*\)/\1/')
-            mv -f ${f} ${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.wic${suffix}
-        done
-    fi
-    rm -rf ${BUILDCHROOT_DIR}/${WICTMP}
+    sudo chown -R $(id -u):$(id -g) "${DEPLOY_DIR_IMAGE}/${IMAGE_FULLNAME}.wic"*
     rm -rf ${IMAGE_ROOTFS}/../pseudo
 }
-- 
2.34.1


  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 ` [PATCH v5 2/9] imager: Migrate from buildchroot to schroot Anton Mikanovich
2023-05-31 11:12 ` Anton Mikanovich [this message]
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-4-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