From 0eae42c67ae2309d2724353bb3a96b5e3e8c6da2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20=27sil2100=27=20Zemczak?= Date: Fri, 14 Jun 2024 13:40:17 +0200 Subject: [PATCH] Backport ubuntu-image 3.x support into jammy. --- debian/control | 1 - live-build/auto/build | 51 ++++++++++++++++++++++++++---------------- live-build/auto/config | 42 +++++++++++----------------------- 3 files changed, 45 insertions(+), 49 deletions(-) diff --git a/debian/control b/debian/control index 115870fe..874b73bb 100644 --- a/debian/control +++ b/debian/control @@ -40,7 +40,6 @@ Depends: ${misc:Depends}, squashfs-tools (>= 1:3.3-1), sudo, u-boot-tools [armhf arm64], - ubuntu-image [!i386 !riscv64], python3-vmdkstream [amd64 i386], xz-utils, zerofree diff --git a/live-build/auto/build b/live-build/auto/build index 2e4292ca..55bb30b9 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -87,11 +87,16 @@ fi PREFIX="livecd.$PROJECT${SUBARCH:+-$SUBARCH}" if [ "${IMAGEFORMAT:-}" = "ubuntu-image" ]; then - # Use ubuntu-image instead of live-build + # Use ubuntu-image instead (or as part) of live-build + + export SNAPPY_STORE_NO_CDN=1 + LB_UBUNTU_IMAGE_CHANNEL="${LB_UBUNTU_IMAGE_CHANNEL:-stable}" + snap install \ + --classic --channel="$LB_UBUNTU_IMAGE_CHANNEL" ubuntu-image if [ "$PROJECT" = "ubuntu-core" ]; then - env SNAPPY_STORE_NO_CDN=1 \ - ubuntu-image snap $UBUNTU_IMAGE_ARGS \ + # Ubuntu Core images + /snap/bin/ubuntu-image snap $UBUNTU_IMAGE_ARGS \ -O output "$PREFIX".model-assertion # XXX: currently we only have one image generated, but really # we should be supporting more than one for models that @@ -99,24 +104,32 @@ if [ "${IMAGEFORMAT:-}" = "ubuntu-image" ]; then mv output/*.img "$PREFIX".img xz -0 -T4 "$PREFIX".img mv output/seed.manifest "$PREFIX".manifest + + # All the builds are finished now, exit + exit 0 else - # First we need to build the gadget tree - make -C "config/$PREFIX-gadget" \ - ARCH=$ARCH SERIES=$SUITE $GADGET_TARGET - ubuntu-image classic $UBUNTU_IMAGE_ARGS \ - -s $SUITE -p $PROJECT -a $ARCH --subarch $SUBARCH \ - -O output config/$PREFIX-gadget/install - # XXX: currently we only have one image generated, but really - # we should be supporting more than one for models that - # define those. - mv output/*.img "$PREFIX".img - xz -0 -T4 "$PREFIX".img - # Also link the output image to a filename that cdimage expects - ln "$PREFIX".img.xz livecd.ubuntu-cpc.disk1.img.xz - mv output/filesystem.manifest "$PREFIX".manifest + # Ubuntu classic preinstalled images + /snap/bin/ubuntu-image classic --verbose $UBUNTU_IMAGE_ARGS \ + -O output "$IMAGE_DEFINITION" + # Since the output of the ubuntu-image call can vary based on what + # kind of an image we build, the safest bet is to 'export' all the + # artifacts from the output directory. The image definition file + # should be what defines what is expected, so that we don't have + # to tweak livecd-rootfs everytime a different type of artifact + # is needed. + for artifact in output/*; do + # We want to be dynamic, and want to support even + # two-part extensions. + filename=$(basename $artifact) + noversion=$(echo $filename | sed 's/[0-9][0-9]\.[0-9][0-9]//') + extension=${noversion#*.} + mv $artifact "$PREFIX".$extension + done + [ -f $PREFIX.img ] && xz -0 -T4 "$PREFIX".img + + # All the builds are finished now, exit + exit 0 fi - - exit 0 fi # Setup cleanup function diff --git a/live-build/auto/config b/live-build/auto/config index 58990208..8912fc30 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -493,38 +493,22 @@ case $IMAGEFORMAT in else # classic images - # Certain models have different names but are built from the same source gadget tree - BRANCH="classic" - case $MODEL in - pi|pi-arm64|pi3-arm64) - MODEL=pi - BRANCH="classic-22.04" - ;; - intel-iot) - MODEL=pc + # Sometimes per-project quirks are necessary + IMAGE_PROJECT=$PROJECT + case "$IMAGE_PROJECT" in + ubuntu-cpc) + IMAGE_PROJECT="ubuntu-server" ;; esac - GADGET_TARGET="server" - if [ "$SUBPROJECT" = "desktop-preinstalled" ]; then - GADGET_TARGET="desktop" - fi - - UBUNTU_IMAGE_ARGS="$UBUNTU_IMAGE_ARGS${SUBPROJECT:+ --subproject \"$SUBPROJECT\"}" - UBUNTU_IMAGE_ARGS="$UBUNTU_IMAGE_ARGS${PROPOSED:+ --with-proposed}" - UBUNTU_IMAGE_ARGS="$UBUNTU_IMAGE_ARGS${EXTRA_PPAS:+ --extra-ppas \"$EXTRA_PPAS\"}" - - # We need to look in two places for the gadget tree: - # - Launchpad hosted gadgets will be in the snap-gadget repo - # - Github hosted gadgets are mirrored into a github-mirror repo - git clone git://git.launchpad.net/~canonical-foundations/snap-$MODEL/+git/snap-$MODEL -b $BRANCH config/$PREFIX-gadget || git clone git://git.launchpad.net/~canonical-foundations/snap-$MODEL/+git/github-mirror -b $BRANCH config/$PREFIX-gadget || git clone git://git.launchpad.net/~canonical-foundations/snap-$MODEL/+git/github-mirror-$ARCH -b $BRANCH config/$PREFIX-gadget - - echo "IMAGEFORMAT=$IMAGEFORMAT" >> config/common - echo "SUITE=$SUITE" >> config/common - echo "GADGET_TARGET=$GADGET_TARGET" >> config/common - echo "UBUNTU_IMAGE_ARGS=\"$UBUNTU_IMAGE_ARGS\"" >> config/common - - echo "Configured ubuntu-image for the following gadget model: $MODEL" + LB_UBUNTU_IMAGES_REPO="${LB_UBUNTU_IMAGES_REPO:-git://git.launchpad.net/ubuntu-images}" + LB_UBUNTU_IMAGES_BRANCH="${LB_UBUNTU_IMAGES_BRANCH:-$SUITE}" + git clone "$LB_UBUNTU_IMAGES_REPO" -b "$LB_UBUNTU_IMAGES_BRANCH" image-definitions + IMAGE_DEFINITION="image-definitions/$IMAGE_PROJECT-$MODEL.yaml" + echo "IMAGE_DEFINITION=$IMAGE_DEFINITION" >> config/common + echo "Configured ubuntu-image to use image definition file $IMAGE_DEFINITION which has the following contents:" + cat "$IMAGE_DEFINITION" + echo "----------------------------------------------------------" fi # Save the model name used for building, mostly for any model-specific hook execution