mirror of
https://git.launchpad.net/livecd-rootfs
synced 2025-02-23 03:11:12 +00:00
Refactor snap preseeding to allow additional snaps to be preseeded from
hooks
This commit is contained in:
commit
c46962ca2e
8
debian/changelog
vendored
8
debian/changelog
vendored
@ -1,3 +1,11 @@
|
||||
livecd-rootfs (2.519) UNRELEASED; urgency=medium
|
||||
|
||||
[ Robert C Jennings ]
|
||||
* Refactor snap preseeding to allow additional snaps to be preseeded from
|
||||
hooks
|
||||
|
||||
-- Steve Langasek <steve.langasek@ubuntu.com> Tue, 10 Apr 2018 15:58:56 -0700
|
||||
|
||||
livecd-rootfs (2.518) bionic; urgency=medium
|
||||
|
||||
* Make subiquity installer boot quicker, by making dhcp interfaces
|
||||
|
@ -15,6 +15,8 @@ if [ -z "${PROJECT:-}" ]; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
. config/functions
|
||||
|
||||
# Link output files somewhere BuildLiveCD will be able to find them.
|
||||
PREFIX="livecd.$PROJECT${SUBARCH:+-$SUBARCH}"
|
||||
|
||||
@ -35,45 +37,12 @@ Setup_cleanup
|
||||
|
||||
preinstall_snaps() {
|
||||
lb chroot_resolv install
|
||||
snap_channel="stable/ubuntu-$(distro-info --series="$LB_DISTRIBUTION" \
|
||||
-r | awk '{ print $1 }')"
|
||||
chroot chroot sh -c '
|
||||
set -x;
|
||||
cd /var/lib/snapd/seed;
|
||||
SNAPPY_STORE_NO_CDN=1 snap download core'
|
||||
snap_prepare chroot
|
||||
|
||||
for snap in "$@"; do
|
||||
chroot chroot sh -c "
|
||||
set -x;
|
||||
cd /var/lib/snapd/seed;
|
||||
SNAPPY_STORE_NO_CDN=1 snap download --channel=$snap_channel \"${snap%/*}\""
|
||||
snap_preseed chroot "${snap}"
|
||||
done
|
||||
lb chroot_resolv remove
|
||||
|
||||
CORE_SNAP=$(cd chroot/var/lib/snapd/seed; ls -1 core_*.snap)
|
||||
|
||||
cat <<EOF > chroot/var/lib/snapd/seed/seed.yaml
|
||||
snaps:
|
||||
- name: core
|
||||
channel: stable
|
||||
file: ${CORE_SNAP}
|
||||
EOF
|
||||
for snap in "$@"; do
|
||||
snap_name=${snap%/*}
|
||||
cat <<EOF >> chroot/var/lib/snapd/seed/seed.yaml
|
||||
- name: ${snap_name}
|
||||
channel: $snap_channel
|
||||
EOF
|
||||
case ${snap} in */classic) echo " classic: true" >> chroot/var/lib/snapd/seed/seed.yaml;; esac
|
||||
echo -n " file: " >> chroot/var/lib/snapd/seed/seed.yaml
|
||||
(cd chroot/var/lib/snapd/seed; ls -1 ${snap_name}_*.snap) \
|
||||
>> chroot/var/lib/snapd/seed/seed.yaml
|
||||
done
|
||||
|
||||
mkdir -p chroot/var/lib/snapd/seed/snaps \
|
||||
chroot/var/lib/snapd/seed/assertions
|
||||
mv chroot/var/lib/snapd/seed/*.assert \
|
||||
chroot/var/lib/snapd/seed/assertions/
|
||||
mv chroot/var/lib/snapd/seed/*.snap chroot/var/lib/snapd/seed/snaps/
|
||||
}
|
||||
|
||||
rm -f binary.success
|
||||
@ -384,26 +353,6 @@ deb file:/var/lib/preinstalled-pool/ $LB_DISTRIBUTION $LB_PARENT_ARCHIVE_AREAS
|
||||
case $PROJECT:$SUBPROJECT in
|
||||
*)
|
||||
if [ -e "config/seeded-snaps" ]; then
|
||||
assertions_dir="chroot/var/lib/snapd/seed/assertions"
|
||||
model_assertion="$assertions_dir/generic-classic.model"
|
||||
account_key_assertion="$assertions_dir/generic.account-key"
|
||||
account_assertion="$assertions_dir/generic.account"
|
||||
|
||||
mkdir -p "$assertions_dir"
|
||||
snap known --remote model series=16 \
|
||||
model=generic-classic brand-id=generic \
|
||||
> "$model_assertion"
|
||||
account_key=$(sed -n -e's/sign-key-sha3-384: //p' \
|
||||
< "$model_assertion")
|
||||
|
||||
snap known --remote account-key \
|
||||
public-key-sha3-384="$account_key" \
|
||||
> "$account_key_assertion"
|
||||
account=$(sed -n -e's/account-id: //p' \
|
||||
< "$account_key_assertion")
|
||||
|
||||
snap known --remote account account-id=generic \
|
||||
> "$account_assertion"
|
||||
snap_list=$(cat config/seeded-snaps)
|
||||
preinstall_snaps $snap_list
|
||||
fi
|
||||
|
@ -831,9 +831,11 @@ lb config noauto \
|
||||
|
||||
echo "LB_CHROOT_HOOKS=\"$CHROOT_HOOKS\"" >> config/chroot
|
||||
echo "SUBPROJECT=\"${SUBPROJECT:-}\"" >> config/chroot
|
||||
echo "LB_DISTRIBUTION=\"$SUITE\"" >> config/chroot
|
||||
echo "LB_BINARY_HOOKS=\"$BINARY_HOOKS\"" >> config/binary
|
||||
echo "BUILDSTAMP=\"$NOW\"" >> config/binary
|
||||
echo "SUBPROJECT=\"${SUBPROJECT:-}\"" >> config/binary
|
||||
echo "LB_DISTRIBUTION=\"$SUITE\"" >> config/binary
|
||||
|
||||
case $ARCH+$SUBARCH in
|
||||
armhf+raspi2)
|
||||
|
@ -1,6 +1,7 @@
|
||||
# vi: ts=4 expandtab syntax=sh
|
||||
|
||||
imagesize=${IMAGE_SIZE:-$((2252*1024**2))} # 2.2G (the current size we ship)
|
||||
#imagesize=${IMAGE_SIZE:-$((2252*1024**2))} # 2.2G (the current size we ship)
|
||||
imagesize=${IMAGE_SIZE:-2361393152} # 2.2G (the current size we ship)
|
||||
fs_label="${FS_LABEL:-rootfs}"
|
||||
|
||||
rootfs_dev_mapper=
|
||||
@ -360,3 +361,106 @@ recreate_initramfs() {
|
||||
esac
|
||||
mv "$CHROOT"/boot/initrd.img-* $DESTDIR
|
||||
}
|
||||
|
||||
release_ver() {
|
||||
# Return the release version number
|
||||
distro-info --series="$LB_DISTRIBUTION" -r | awk '{ print $1 }'
|
||||
}
|
||||
|
||||
_snap_preseed() {
|
||||
# Download the snap/assertion and add to the preseed
|
||||
local CHROOT_ROOT=$1
|
||||
local SNAP=$2
|
||||
local SNAP_NAME=${SNAP%/*}
|
||||
local CHANNEL=${3:?Snap channel must be specified}
|
||||
|
||||
local seed_dir="$CHROOT_ROOT/var/lib/snapd/seed"
|
||||
local snaps_dir="$seed_dir/snaps"
|
||||
local seed_yaml="$seed_dir/seed.yaml"
|
||||
local assertions_dir="$seed_dir/assertions"
|
||||
|
||||
# Download the snap & assertion
|
||||
local snap_download_failed=0
|
||||
chroot $CHROOT_ROOT sh -c "
|
||||
set -x;
|
||||
cd /var/lib/snapd/seed;
|
||||
SNAPPY_STORE_NO_CDN=1 snap download \
|
||||
--channel=$CHANNEL \"$SNAP_NAME\"" || snap_download_failed=1
|
||||
if [ $snap_download_failed = 1 ] ; then
|
||||
echo "If the channel ($CHANNEL) includes '*/ubuntu-##.##' track per "
|
||||
echo "Ubuntu policy (ex. stable/ubuntu-18.04) the publisher will need "
|
||||
echo "to temporarily create the channel/track to allow fallback during"
|
||||
echo "download (ex. stable/ubuntu-18.04 falls back to stable if the"
|
||||
echo "prior had been created in the past)."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
mv -v $seed_dir/*.assert $assertions_dir
|
||||
mv -v $seed_dir/*.snap $snaps_dir
|
||||
|
||||
# Add the snap to the seed.yaml
|
||||
! [ -e $seed_yaml ] && echo "snaps:" > $seed_yaml
|
||||
cat <<EOF >> $seed_yaml
|
||||
-
|
||||
name: ${SNAP_NAME}
|
||||
channel: ${CHANNEL}
|
||||
EOF
|
||||
|
||||
case ${SNAP} in */classic) echo " classic: true" >> $seed_yaml;; esac
|
||||
|
||||
echo -n " file: " >> $seed_yaml
|
||||
(cd $snaps_dir; ls -1 ${SNAP_NAME}_*.snap) >> $seed_yaml
|
||||
}
|
||||
|
||||
snap_prepare() {
|
||||
# Configure basic snapd assertions and pre-seeds the 'core' snap
|
||||
local CHROOT_ROOT=$1
|
||||
|
||||
local seed_dir="$CHROOT_ROOT/var/lib/snapd/seed"
|
||||
local snaps_dir="$seed_dir/snaps"
|
||||
local assertions_dir="$seed_dir/assertions"
|
||||
local model_assertion="$assertions_dir/generic-classic.model"
|
||||
local account_key_assertion="$assertions_dir/generic.account-key"
|
||||
local account_assertion="$assertions_dir/generic.account"
|
||||
|
||||
mkdir -p "$assertions_dir"
|
||||
mkdir -p "$snaps_dir"
|
||||
|
||||
if ! [ -e "$model_assertion" ] ; then
|
||||
snap known --remote model series=16 \
|
||||
model=generic-classic brand-id=generic \
|
||||
> "$model_assertion"
|
||||
fi
|
||||
|
||||
if ! [ -e "$account_key_assertion" ] ; then
|
||||
local account_key=$(sed -n -e's/sign-key-sha3-384: //p' \
|
||||
< "$model_assertion")
|
||||
snap known --remote account-key \
|
||||
public-key-sha3-384="$account_key" \
|
||||
> "$account_key_assertion"
|
||||
fi
|
||||
|
||||
|
||||
if ! [ -e "$account_assertion" ] ; then
|
||||
local account=$(sed -n -e's/account-id: //p' < "$account_key_assertion")
|
||||
snap known --remote account account-id=$account \
|
||||
> "$account_assertion"
|
||||
fi
|
||||
|
||||
# Download the core snap
|
||||
if ! [ -f $snaps_dir/core_[0-9]*.snap ] ; then
|
||||
_snap_preseed $CHROOT_ROOT core stable
|
||||
fi
|
||||
}
|
||||
|
||||
snap_preseed() {
|
||||
# Preseed a snap in the image
|
||||
local CHROOT_ROOT=$1
|
||||
local SNAP=$2
|
||||
# Per Ubuntu policy, all seeded snaps (with the exception of the core
|
||||
# snap) must pull from stable/ubuntu-$(release_ver) as their channel.
|
||||
local CHANNEL=${3:-"stable/ubuntu-$(release_ver)"}
|
||||
|
||||
snap_prepare $CHROOT_ROOT
|
||||
_snap_preseed $CHROOT_ROOT $SNAP $CHANNEL
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user