From mboxrd@z Thu Jan 1 00:00:00 1970 X-GM-THRID: 7306407937029701632 Date: Mon, 11 Dec 2023 20:55:20 -0800 (PST) From: Srinuvasan Arjunan To: isar-users Message-Id: In-Reply-To: References: <20231128071401.1894962-1-srinuvasan_a@mentor.com> Subject: Re: [RFC][PATCH] Add sbuildchroot class MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_Part_59768_882689866.1702356920547" X-TUID: LYY6pcr1LYXr ------=_Part_59768_882689866.1702356920547 Content-Type: multipart/alternative; boundary="----=_Part_59769_1031702053.1702356920547" ------=_Part_59769_1031702053.1702356920547 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Friday, December 8, 2023 at 7:45:06=E2=80=AFPM UTC+5:30 Jan Kiszka wrote= : On 28.11.23 08:14, Srinuvasan Arjunan wrote:=20 > From: Srinuvasan A =20 >=20 > In present implementation we are using sbuild/schroot to build the=20 > packages, this schroot created via sessions during package build, and=20 > immediatley vanish once build the packages.=20 >=20 > Some of the downstream projects uses this chroot at many=20 > places for doing some postprocessing the meta data based on the chroot=20 > path, but unfortunately we cannot refer this path due to creating the=20 > chroot via session.=20 Can you be more specific in the use cases? In our case we need to install the custom packages in buildchroot, once we installed the isar-apt packages, later we refer those and do som= e postprocessing before image creation. ISAR provides the provision to pre-install the upstream packages not custom packages and this chroot will be used as a base chroot to build the packages or imager_run, hence SBUILD_FLAVOR would not be helpful atleast for my scenario. SBUILD_CHROOT_PREINSTALL_EXTRA variable directly install the upstream=20 packages in rootfs not custom packages. >=20 > Hence install the required packages in persistence sbuildchroot, to=20 > access isar-apt and other directories we introduces the sbuildchroot=20 > class.=20 Did no one commented yet that we already have SBUILD_FLAVOR to=20 pre-install common packages into reusable sbuild schroots?=20 Jan=20 >=20 > Signed-off-by: Srinuvasan A =20 > ---=20 > meta/classes/sbuildchroot.bbclass | 101 ++++++++++++++++++++++++++++++=20 > 1 file changed, 101 insertions(+)=20 > create mode 100644 meta/classes/sbuildchroot.bbclass=20 >=20 > diff --git a/meta/classes/sbuildchroot.bbclass=20 b/meta/classes/sbuildchroot.bbclass=20 > new file mode 100644=20 > index 00000000..edddd566=20 > --- /dev/null=20 > +++ b/meta/classes/sbuildchroot.bbclass=20 > @@ -0,0 +1,101 @@=20 > +# This software is a part of ISAR.=20 > +# Copyright (C) 2018 Siemens AG=20 > +#=20 > +# SPDX-License-Identifier: MIT=20 > +=20 > +inherit crossvars=20 > +=20 > +MOUNT_LOCKFILE =3D "${SCHROOT_DIR}.lock"=20 > +=20 > +sbuildchroot_do_mounts() {=20 > + if [ "${USE_CCACHE}" =3D "1" ]; then=20 > + mkdir -p "${CCACHE_DIR}"=20 > + if [ "${CCACHE_DEBUG}" =3D "1" ]; then=20 > + mkdir -p "${CCACHE_DIR}/debug"=20 > + fi=20 > + fi=20 > +=20 > + sudo -s <<'EOSUDO'=20 > + ( flock 9=20 > + set -e=20 > +=20 > + mountpoint -q '${SCHROOT_DIR}/isar-apt' ||=20 > + mount --bind '${REPO_ISAR_DIR}/${DISTRO}' '${SCHROOT_DIR}/isar-apt'=20 > + if [ "${USE_CCACHE}" =3D "1" ]; then=20 > + mkdir -p '${SCHROOT_DIR}/ccache'=20 > + mountpoint -q '${SCHROOT_DIR}/ccache' ||=20 > + mount --bind '${CCACHE_DIR}' '${SCHROOT_DIR}/ccache'=20 > + fi=20 > + mountpoint -q '${SCHROOT_DIR}/dev' ||=20 > + ( mount -o bind,private /dev '${SCHROOT_DIR}/dev' &&=20 > + mount -t tmpfs none '${SCHROOT_DIR}/dev/shm' &&=20 > + mount --bind /dev/pts '${SCHROOT_DIR}/dev/pts' )=20 > + mountpoint -q '${SCHROOT_DIR}/proc' ||=20 > + mount -t proc none '${SCHROOT_DIR}/proc'=20 > + mountpoint -q '${SCHROOT_DIR}/sys' ||=20 > + mount --rbind /sys '${SCHROOT_DIR}/sys'=20 > + mount --make-rslave '${SCHROOT_DIR}/sys'=20 > +=20 > + # Mount base-apt if 'ISAR_USE_CACHED_BASE_REPO' is set=20 > + if [=20 "${@repr(bb.utils.to_boolean(d.getVar('ISAR_USE_CACHED_BASE_REPO')))}" =3D= =20 'True' ]=20 > + then=20 > + mkdir -p '${SCHROOT_DIR}/base-apt'=20 > + mountpoint -q '${SCHROOT_DIR}/base-apt' || \=20 > + mount --bind '${REPO_BASE_DIR}' '${SCHROOT_DIR}/base-apt'=20 > + fi=20 > +=20 > + # Refresh or remove /etc/resolv.conf at this chance=20 > + if [ "${@repr(bb.utils.to_boolean(d.getVar('BB_NO_NETWORK')))}" =3D=20 'True' ]=20 > + then=20 > + rm -rf '${SCHROOT_DIR}/etc/resolv.conf'=20 > + else=20 > + cp -L /etc/resolv.conf '${SCHROOT_DIR}/etc'=20 > + fi=20 > +=20 > + ) 9>'${MOUNT_LOCKFILE}'=20 > +EOSUDO=20 > +}=20 > +=20 > +add_isar_apt() {=20 > + sudo -s <<'EOSUDO'=20 > + set -e=20 > +=20 > + mkdir -p '${SCHROOT_DIR}/etc/apt/sources.list.d'=20 > + echo 'deb [trusted=3Dyes] file:///isar-apt ${DEBDISTRONAME} main' > \= =20 > + '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list'=20 > + echo 'deb-src [trusted=3Dyes] file:///isar-apt ${DEBDISTRONAME} main' >= >=20 \=20 > + '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list'=20 > +=20 > + mkdir -p '${SCHROOT_DIR}/etc/apt/preferences.d'=20 > + cat << EOF > '${SCHROOT_DIR}/etc/apt/preferences.d/isar-apt'=20 > +Package: *=20 > +Pin: release n=3D${DEBDISTRONAME}=20 > +Pin-Priority: 1000=20 > +EOF=20 > +EOSUDO=20 > +}=20 > +=20 > +cleanup_isar_apt() {=20 > + sudo -s <<'EOSUDO'=20 > + set -e=20 > + rm -f "${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list"=20 > + rm -f "${SCHROOT_DIR}/etc/apt/preferences.d/isar-apt"=20 > + rm -f "${SCHROOT_DIR}/etc/apt/sources.list.d/base-apt.list"=20 > + rm -f "${SCHROOT_DIR}/etc/apt/apt.conf.d/50isar"=20 > +EOSUDO=20 > +}=20 > +=20 > +image_do_mounts() {=20 > + sudo flock ${MOUNT_LOCKFILE} -c ' \=20 > + mkdir -p "${BUILDROOT_DEPLOY}" "${BUILDROOT_ROOTFS}"=20 "${BUILDROOT_WORK}"=20 > + mount --bind "${DEPLOY_DIR_IMAGE}" "${BUILDROOT_DEPLOY}"=20 > + mount --bind "${IMAGE_ROOTFS}" "${BUILDROOT_ROOTFS}"=20 > + mount --bind "${WORKDIR}" "${BUILDROOT_WORK}"=20 > + '=20 > + sbuildchroot_do_mounts=20 > +}=20 > +=20 > +BUILDROOT =3D "${SCHROOT_DIR}${PP}"=20 > +BUILDROOT_DEPLOY =3D "${SCHROOT_DIR}${PP_DEPLOY}"=20 > +BUILDROOT_ROOTFS =3D "${SCHROOT_DIR}${PP_ROOTFS}"=20 > +BUILDROOT_WORK =3D "${SCHROOT_DIR}${PP_WORK}"=20 --=20 Siemens AG, Technology=20 Linux Expert Center=20 ------=_Part_59769_1031702053.1702356920547 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: quoted-printable

On Friday, December 8, 2023 at 7:45:06= =E2=80=AFPM UTC+5:30 Jan Kiszka wrote:
On 28.11.23 08:14, Srinuvasan Arjunan wrote:
> From: Srinuvasan A <srinuv...@s= iemens.com>
>=20
> In present implementation we are using sbuild/schroot to build t= he
> packages, this schroot created via sessions during package build= , and
> immediatley vanish once build the packages.
>=20
> Some of the downstream projects uses this chroot at many
> places for doing some postprocessing the meta data based on the = chroot
> path, but unfortunately we cannot refer this path due to creatin= g the
> chroot via session.

Can you be more specific in the use cases?

=C2=A0 =C2=A0In our case we need to insta= ll the custom packages in buildchroot,
=C2=A0 =C2=A0once we installed the isar-apt packages, later we refer= those and do some
=C2=A0 =C2=A0= postprocessing before image creation.

=C2=A0 =C2=A0ISAR provides the prov= ision to pre-install the=C2=A0 upstream packages
=C2=A0 = =C2=A0not custom packages and this chroot will be= used as a base chroot to
=C2=A0 =C2=A0=C2=A0build the packages or imager_= run, hence SBUILD_FLAVOR would not be
=C2=A0 =C2=A0helpful atleast for my scenario.

=

=C2=A0 =C2=A0SBUILD_C= HROOT_PREINSTALL_EXTRA variable directly install the upstream=C2=A0<= /div>
=C2=A0 =C2=A0packages in rootfs not cus= tom packages.


>=20
> Hence install the required packages in persistence sbuildchroot,= to
> access isar-apt and other directories we introduces the sbuildch= root
> class.

Did no one commented yet that we already have SBUILD_FLAVOR to
pre-install common packages into reusable sbuild schroots?

Jan

>=20
> Signed-off-by: Srinuvasan A <sr= inuv...@siemens.com>
> ---
> meta/classes/sbuildchroot.bbclass | 101 +++++++++++++++++++++++= +++++++
> 1 file changed, 101 insertions(+)
> create mode 100644 meta/classes/sbuildchroot.bbclass
>=20
> diff --git a/meta/classes/sbuildchroot.bbclass b/meta/classes/sb= uildchroot.bbclass
> new file mode 100644
> index 00000000..edddd566
> --- /dev/null
> +++ b/meta/classes/sbuildchroot.bbclass
> @@ -0,0 +1,101 @@
> +# This software is a part of ISAR.
> +# Copyright (C) 2018 Siemens AG
> +#
> +# SPDX-License-Identifier: MIT
> +
> +inherit crossvars
> +
> +MOUNT_LOCKFILE =3D "${SCHROOT_DIR}.lock"
> +
> +sbuildchroot_do_mounts() {
> + if [ "${USE_CCACHE}" =3D "1" ]; then
> + mkdir -p "${CCACHE_DIR}"
> + if [ "${CCACHE_DEBUG}" =3D "1" ]; then
> + mkdir -p "${CCACHE_DIR}/debug"
> + fi
> + fi
> +
> + sudo -s <<'EOSUDO'
> + ( flock 9
> + set -e
> +
> + mountpoint -q '${SCHROOT_DIR}/isar-apt' ||
> + mount --bind '${REPO_ISAR_DIR}/${DISTRO}' '${SCHROO= T_DIR}/isar-apt'
> + if [ "${USE_CCACHE}" =3D "1" ]; then
> + mkdir -p '${SCHROOT_DIR}/ccache'
> + mountpoint -q '${SCHROOT_DIR}/ccache' ||
> + mount --bind '${CCACHE_DIR}' '${SCHROOT_DIR}/cc= ache'
> + fi
> + mountpoint -q '${SCHROOT_DIR}/dev' ||
> + ( mount -o bind,private /dev '${SCHROOT_DIR}/dev' &= amp;&
> + mount -t tmpfs none '${SCHROOT_DIR}/dev/shm' &= ;&
> + mount --bind /dev/pts '${SCHROOT_DIR}/dev/pts' )
> + mountpoint -q '${SCHROOT_DIR}/proc' ||
> + mount -t proc none '${SCHROOT_DIR}/proc'
> + mountpoint -q '${SCHROOT_DIR}/sys' ||
> + mount --rbind /sys '${SCHROOT_DIR}/sys'
> + mount --make-rslave '${SCHROOT_DIR}/sys'
> +
> + # Mount base-apt if 'ISAR_USE_CACHED_BASE_REPO' is set
> + if [ "${@repr(bb.utils.to_boolean(d.getVar('ISAR_USE_CA= CHED_BASE_REPO')))}" =3D 'True' ]
> + then
> + mkdir -p '${SCHROOT_DIR}/base-apt'
> + mountpoint -q '${SCHROOT_DIR}/base-apt' || \
> + mount --bind '${REPO_BASE_DIR}' '${SCHROOT_DIR}= /base-apt'
> + fi
> +
> + # Refresh or remove /etc/resolv.conf at this chance
> + if [ "${@repr(bb.utils.to_boolean(d.getVar('BB_NO_NETWO= RK')))}" =3D 'True' ]
> + then
> + rm -rf '${SCHROOT_DIR}/etc/resolv.conf'
> + else
> + cp -L /etc/resolv.conf '${SCHROOT_DIR}/etc'
> + fi
> +
> + ) 9>'${MOUNT_LOCKFILE}'
> +EOSUDO
> +}
> +
> +add_isar_apt() {
> + sudo -s <<'EOSUDO'
> + set -e
> +
> + mkdir -p '${SCHROOT_DIR}/etc/apt/sources.list.d'
> + echo 'deb [trusted=3Dyes] file:///isar-apt ${DEBDISTRONAME}= main' > \
> + '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list'
> + echo 'deb-src [trusted=3Dyes] file:///isar-apt ${DEBDISTRON= AME} main' >> \
> + '${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.list'
> +
> + mkdir -p '${SCHROOT_DIR}/etc/apt/preferences.d'
> + cat << EOF > '${SCHROOT_DIR}/etc/apt/preferences.d= /isar-apt'
> +Package: *
> +Pin: release n=3D${DEBDISTRONAME}
> +Pin-Priority: 1000
> +EOF
> +EOSUDO
> +}
> +
> +cleanup_isar_apt() {
> + sudo -s <<'EOSUDO'
> + set -e
> + rm -f "${SCHROOT_DIR}/etc/apt/sources.list.d/isar-apt.l= ist"
> + rm -f "${SCHROOT_DIR}/etc/apt/preferences.d/isar-apt"
> + rm -f "${SCHROOT_DIR}/etc/apt/sources.list.d/base-apt.l= ist"
> + rm -f "${SCHROOT_DIR}/etc/apt/apt.conf.d/50isar"
> +EOSUDO
> +}
> +
> +image_do_mounts() {
> + sudo flock ${MOUNT_LOCKFILE} -c ' \
> + mkdir -p "${BUILDROOT_DEPLOY}" "${BUILDROOT_ROOTFS}" "$= {BUILDROOT_WORK}"
> + mount --bind "${DEPLOY_DIR_IMAGE}" "${BUILDROOT_DEPLOY}= "
> + mount --bind "${IMAGE_ROOTFS}" "${BUILDROOT_ROOTFS}"
> + mount --bind "${WORKDIR}" "${BUILDROOT_WORK}"
> + '
> + sbuildchroot_do_mounts
> +}
> +
> +BUILDROOT =3D "${SCHROOT_DIR}${PP}"
> +BUILDROOT_DEPLOY =3D "${SCHROOT_DIR}${PP_DEPLOY}"
> +BUILDROOT_ROOTFS =3D "${SCHROOT_DIR}${PP_ROOTFS}"
> +BUILDROOT_WORK =3D "${SCHROOT_DIR}${PP_WORK}"

--=20
Siemens AG, Technology
Linux Expert Center

------=_Part_59769_1031702053.1702356920547-- ------=_Part_59768_882689866.1702356920547--