From 05e71b38409b5a7cef41ebc864223466292268bb Mon Sep 17 00:00:00 2001 From: Tobias Koch Date: Thu, 11 Apr 2019 17:46:00 +0200 Subject: [PATCH] Do not include any snaps in ubuntu-cpc:minimized builds --- debian/changelog | 15 +++++++++++++++ live-build/auto/build | 12 +++++++++++- live-build/auto/config | 21 ++++++++++++++++++++- live-build/functions | 14 +++++++++++--- 4 files changed, 57 insertions(+), 5 deletions(-) diff --git a/debian/changelog b/debian/changelog index 9f258abf..1306e445 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,18 @@ +livecd-rootfs (2.577) UNRELEASED; urgency=medium + + [ Tobias Koch ] + * Detect which core snaps are required and install them on-the-fly. + + [ Michael Hudson-Doyle ] + * Slim down ubuntu-cpc:minimized builds: + - Do not include any snaps in ubuntu-cpc:minimized builds (erroring if any + snap other than lxd is seeded). + - Install the lxd-installer package instead, which installs the lxd snap + when invoked. + - Install lxd snap in unminimize. + + -- Tobias Koch Thu, 11 Apr 2019 17:25:25 +0200 + livecd-rootfs (2.576) disco; urgency=medium * When the "snap-tool" script encounters a core snap it will switch to diff --git a/live-build/auto/build b/live-build/auto/build index 09447a1d..22981da5 100755 --- a/live-build/auto/build +++ b/live-build/auto/build @@ -226,7 +226,17 @@ if dpkg-query --show --showformat='${db:Status-Status}\n' ubuntu-server 2> /dev/ fi EOF fi - cat >> chroot/usr/local/sbin/unminimize <<'EOF' + if [ "$PROJECT" = "ubuntu-cpc" ]; then + cat >> chroot/usr/local/sbin/unminimize <<'EOF' + +echo "Removing lxd installer package..." +apt-get purge -y lxd-installer + +echo "Installing lxd from snap..." +snap install lxd +EOF + fi + cat >> chroot/usr/local/sbin/unminimize <<'EOF' # unminimization succeeded, there is no need to mention it in motd rm -f /etc/update-motd.d/60-unminimize diff --git a/live-build/auto/config b/live-build/auto/config index 89519ae1..46246ebb 100755 --- a/live-build/auto/config +++ b/live-build/auto/config @@ -807,7 +807,7 @@ case $PROJECT in ubuntu-cpc) if [ "${SUBPROJECT:-}" = minimized ]; then add_task install cloud-image - add_package install sudo + add_package install sudo lxd-installer # linux-kvm currently only exists for amd64, so fall back to the # virtual flavour for other architectures if [ "$ARCH" = "amd64" ]; then @@ -896,6 +896,25 @@ esac if [ "$PASSES_TO_LAYERS" != "true" ] && [ -n "${BASE_SEED}" ]; then snap_from_seed "${BASE_SEED}" config/seeded-snaps fi +if [ "$PROJECT:${SUBPROJECT:-}" = ubuntu-cpc:minimized ]; then + # We install a lxc script that installs the snap when invoked. We don't + # want any other snaps to come in without due consideration, so fail the + # build if we see such a snap. + for snap in `cat config/seeded-snaps`; do + case $snap in + lxd) + ;; + *) + echo "Unexpected seeded snap for ubuntu-cpc:minimized build: $snap" + exit 1 + ;; + esac + done + + # Truncate but don't delete to a) prevent any snaps from being seeded, + # while at the same time b) triggering initialization of assertions. + truncate --size 0 config/seeded-snaps +fi # grab a list of packags to remove for a "minimal" installation from the seed # mirror for this project diff --git a/live-build/functions b/live-build/functions index c0dfcdca..6cc87d91 100644 --- a/live-build/functions +++ b/live-build/functions @@ -436,6 +436,17 @@ _snap_preseed() { return fi + # Determine if and what core snap is needed + local core_snap=$(/usr/share/livecd-rootfs/snap-tool info \ + --cohort-key="${COHORT_KEY:-}" \ + --channel="$CHANNEL" "$SNAP_NAME" | \ + grep '^base:' | awk '{print $2}' + ) + + if [ -n "$core_snap" ]; then + _snap_preseed $CHROOT_ROOT $core_snap stable + fi + sh -c " set -x; cd \"$CHROOT_ROOT/var/lib/snapd/seed\"; @@ -544,9 +555,6 @@ snap_prepare() { local CUSTOM_BRAND_MODEL=${2:-generic:generic-classic} snap_prepare_assertions "$CHROOT_ROOT" "$CUSTOM_BRAND_MODEL" - - # Download the core snap - _snap_preseed $CHROOT_ROOT core stable } snap_preseed() {