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>,
	Felix Moessbauer <felix.moessbauer@siemens.com>
Subject: [RFC] add uuid to schroot folder
Date: Mon, 11 Jul 2022 21:31:11 +0300	[thread overview]
Message-ID: <20220711183111.3860-1-amikan@ilbers.de> (raw)

PIDs are not unique across containers.
When running the build in a container (e.g. the kas container),
the PID of bitbake is likely the same across multiple simultaneously
running builds.

This is especially the case for CI runners, where it is common that
multiple jobs run in parallel.

This patch adds an additional UUID component stored till the end of
the build in bitbake persistend storage.

Signed-off-by: Anton Mikanovich <amikan@ilbers.de>
Signed-off-by: Felix Moessbauer <felix.moessbauer@siemens.com>
---
 meta/classes/base.bbclass        | 14 ++++++++++++++
 meta/classes/isar-events.bbclass |  3 +++
 meta/classes/sbuild.bbclass      |  2 +-
 meta/conf/bitbake.conf           |  2 +-
 4 files changed, 19 insertions(+), 2 deletions(-)

diff --git a/meta/classes/base.bbclass b/meta/classes/base.bbclass
index 4ec2c81..1d954de 100644
--- a/meta/classes/base.bbclass
+++ b/meta/classes/base.bbclass
@@ -278,3 +278,17 @@ def base_set_filespath(path, d):
             if p != "":
                 filespath.append(os.path.join(p, o))
     return ":".join(filespath)
+
+def calculate_build_uuid(d):
+    import uuid
+
+    uuid_data = bb.persist_data.persist('BB_ISAR_UUID_DATA', d)
+    if "uuid" not in uuid_data or not uuid_data["uuid"]:
+        # Generate new UUID
+        uuid_data["uuid"] = str(uuid.uuid4())
+
+    return uuid_data["uuid"]
+
+# Unique ID for this build, used to avoid name clashes on external mountpoints
+# When running parallel builds in different PID namespaces
+ISAR_BUILD_UUID = "${@ calculate_build_uuid(d)}"
diff --git a/meta/classes/isar-events.bbclass b/meta/classes/isar-events.bbclass
index 92aff20..f52b234 100644
--- a/meta/classes/isar-events.bbclass
+++ b/meta/classes/isar-events.bbclass
@@ -60,6 +60,9 @@ python build_completed() {
                     stdout=subprocess.DEVNULL,
                     stderr=subprocess.DEVNULL,
                 )
+
+    # Cleanup build UUID, the next bitbake run will generate new one
+    bb.persist_data.persist('BB_ISAR_UUID_DATA', d).clear()
 }
 
 build_completed[eventmask] = "bb.event.BuildCompleted"
diff --git a/meta/classes/sbuild.bbclass b/meta/classes/sbuild.bbclass
index f9bfaaf..7c39954 100644
--- a/meta/classes/sbuild.bbclass
+++ b/meta/classes/sbuild.bbclass
@@ -23,7 +23,7 @@ python __anonymous() {
     d.setVar('SCHROOT_DEP', dep)
 }
 
-SBUILD_CHROOT ?= "${DEBDISTRONAME}-${SCHROOT_USER}-${@os.getpid()}"
+SBUILD_CHROOT ?= "${DEBDISTRONAME}-${SCHROOT_USER}-${ISAR_BUILD_UUID}-${@os.getpid()}"
 
 SBUILD_CONF_DIR ?= "${SCHROOT_CONF}/${SBUILD_CHROOT}"
 SCHROOT_CONF_FILE ?= "${SCHROOT_CONF}/chroot.d/${SBUILD_CHROOT}"
diff --git a/meta/conf/bitbake.conf b/meta/conf/bitbake.conf
index 6451cb5..cadfbdd 100644
--- a/meta/conf/bitbake.conf
+++ b/meta/conf/bitbake.conf
@@ -104,7 +104,7 @@ BB_HASHBASE_WHITELIST ?= "TMPDIR FILE PATH PWD BB_TASKHASH BBPATH BBSERVER DL_DI
     WORKDIR STAMPCLEAN PKGDATA_DIR BUILD_ARCH SSTATE_PKGARCH \
     BB_WORKERCONTEXT BB_LIMITEDDEPS DEPLOY_DIR BUILDCHROOT_DIR \
     REPO_ISAR_DIR REPO_ISAR_DB_DIR REPO_BASE_DIR REPO_BASE_DB_DIR LAYERDIR_core \
-    SCRIPTSDIR TOPDIR"
+    SCRIPTSDIR TOPDIR ISAR_BUILD_UUID"
 BB_HASHCONFIG_WHITELIST ?= "${BB_HASHBASE_WHITELIST} DATE TIME SSH_AGENT_PID \
     SSH_AUTH_SOCK PSEUDO_BUILD BB_ENV_EXTRAWHITE DISABLE_SANITY_CHECKS \
     BB_NUMBER_THREADS BB_ORIGENV BB_INVALIDCONF BBINCLUDED \
-- 
2.17.1


             reply	other threads:[~2022-07-11 18:31 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-11 18:31 Anton Mikanovich [this message]
2022-07-11 18:34 ` Anton Mikanovich
2022-07-12 13:38   ` Moessbauer, Felix
2022-07-13 13:23     ` Anton Mikanovich
2022-07-13 13:52       ` Moessbauer, Felix

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=20220711183111.3860-1-amikan@ilbers.de \
    --to=amikan@ilbers.de \
    --cc=felix.moessbauer@siemens.com \
    --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