Skip to content

Commit

Permalink
Simplify image build scripts by removing .new dance (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
delan committed Jan 2, 2025
1 parent 1f1d400 commit 4a3bf0a
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 59 deletions.
8 changes: 0 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,6 @@ To build the base vm image:
- Windows 10 (multi-edition ISO), English (United States): [Win10_22H2_English_x64v1.iso](https://www.microsoft.com/en-us/software-download/windows10ISO) (sha256 = a6f470ca6d331eb353b815c043e327a347f594f37ff525f17764738fe812852e)
- Run the build script: `windows10/build-image.sh`
- FIXME: if Windows fails to autologon (stuck at lock screen): `virsh reboot servo-windows10.new`
- Destroy the old base image (if it exists): `zfs destroy -r tank/base/servo-windows10`
- Rename the new base image: `zfs rename tank/base/servo-windows10{.new,}`
- Create the base libvirt guest (if it doesn’t exist): `virt-clone --preserve-data --check path_in_use=off -o servo-windows10.new -n servo-windows10 -f /dev/zvol/tank/base/servo-windows10`
- Undefine the temporary libvirt guest: `virsh undefine servo-windows10.new`

To clone and start a new runner:

Expand All @@ -134,10 +130,6 @@ Runners created from this image preinstall all dependencies (including those spe
To build the base vm image:

- Run the build script: `ubuntu2204/build-image.sh`
- Destroy the old base image (if it exists): `zfs destroy -r tank/base/servo-ubuntu2204`
- Rename the new base image: `zfs rename tank/base/servo-ubuntu2204{.new,}`
- Create the base libvirt guest (if it doesn’t exist): `virt-clone --preserve-data --check path_in_use=off -o servo-ubuntu2204.new -n servo-ubuntu2204 -f /dev/zvol/tank/base/servo-ubuntu2204`
- Undefine the temporary libvirt guest: `virsh undefine servo-ubuntu2204.new`

To clone and start a new runner:

Expand Down
14 changes: 0 additions & 14 deletions monitor/monitor.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,9 @@ base_image_snapshot = "ready"
github_runner_label = "self-hosted-image:windows10"
target_count = 2

[profiles."servo-windows10.new"]
configuration_name = "windows10"
base_vm_name = "servo-windows10.new"
base_image_snapshot = "ready"
github_runner_label = "self-hosted-image:windows10.new"
target_count = 0

[profiles.servo-ubuntu2204]
configuration_name = "ubuntu2204"
base_vm_name = "servo-ubuntu2204"
base_image_snapshot = "ready"
github_runner_label = "self-hosted-image:ubuntu2204"
target_count = 2

[profiles."servo-ubuntu2204.new"]
configuration_name = "ubuntu2204"
base_vm_name = "servo-ubuntu2204.new"
base_image_snapshot = "ready"
github_runner_label = "self-hosted-image:ubuntu2204.new"
target_count = 0
45 changes: 26 additions & 19 deletions ubuntu2204/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,40 @@ download "$cache_dir" https://cloud-images.ubuntu.com/jammy/20241217/jammy-serve
>&2 echo '[*] Converting qcow2 image to raw image'
qemu-img convert -f qcow2 -O raw "$cache_dir/jammy-server-cloudimg-amd64.img" "$cache_dir/jammy-server-cloudimg-amd64.raw"

>&2 echo '[*] Creating zvol and libvirt guest'
zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new"
>> $undo_commands echo "zfs destroy '$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new'"
>&2 echo '[*] Creating zvol (if needed)'
zfs list -Ho name "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" || zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"

>&2 echo '[*] Creating libvirt guest (or recreating it with new config)'
if virsh domstate -- "$image_name"; then
virsh undefine -- "$image_name"
fi
virsh define -- "$image_dir/guest.xml"
>> $undo_commands echo "virsh undefine -- '$image_name.init'"
virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name.new" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new"
>> $undo_commands echo "virsh undefine -- '$image_name.new'"
virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"
virsh undefine -- "$image_name.init"

>&2 echo '[*] Wiping zvol'
dd bs=1M count=1 if=/dev/zero of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"

>&2 echo '[*] Writing disk images'
dd status=progress bs=1M if="$cache_dir/jammy-server-cloudimg-amd64.raw" of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new"
dd status=progress bs=1M if="$cache_dir/jammy-server-cloudimg-amd64.raw" of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"
genisoimage -V CIDATA -R -o "/var/lib/libvirt/images/$image_name.config.iso" "$image_dir/user-data" "$image_dir/meta-data"

>&2 echo '[*] Starting guest, to expand root filesystem'
virsh start "$image_name.new"
virsh start "$image_name"

>&2 echo '[*] Waiting for guest to shut down (max 40 seconds)' # normally ~19 seconds
if ! time virsh event --timeout 40 -- "$image_name.new" lifecycle; then
if ! time virsh event --timeout 40 -- "$image_name" lifecycle; then
>&2 echo 'virsh event timed out!'
exit 1
fi

>&2 echo '[*] Forcing update of partition block device geometry'
# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks)
blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"
sleep 1

>&2 echo '[*] Waiting for partition block device to appear'
partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new-part1
partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name-part1
t=0; while ! test -e $partition_block_device; do
if [ $t -ge $SERVO_CI_ZVOL_BLOCK_DEVICE_TIMEOUT ]; then
>&2 printf '[!] Timed out waiting for block device: %s' $partition_block_device
Expand All @@ -49,24 +59,21 @@ t=0; while ! test -e $partition_block_device; do
t=$((t+1))
done

>&2 echo '[*] Forcing update of partition block device geometry'
# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks)
blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new"

>&2 echo '[*] Configuring base image'
./mount-runner.sh "$image_name.new" "$image_dir/configure-base.sh"
./mount-runner.sh "$image_name" "$image_dir/configure-base.sh"

>&2 echo '[*] Starting guest, to apply changes'
virsh start "$image_name.new"
virsh start "$image_name"

>&2 echo '[*] Waiting for guest to shut down (max 2000 seconds)' # normally ~978 seconds
if ! time virsh event --timeout 2000 -- "$image_name.new" lifecycle; then
if ! time virsh event --timeout 2000 -- "$image_name" lifecycle; then
>&2 echo 'virsh event timed out!'
exit 1
fi

>&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready"
zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready"
snapshot=$(date -u +\%FT\%RZ)
>&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot"
zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot"

# TODO: check that servo was actually built correctly

Expand Down
43 changes: 25 additions & 18 deletions windows10/build-image.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,40 @@ image_name=servo-windows10
>&2 echo '[*] Caching downloads'
download "$cache_dir" https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/archive-virtio/virtio-win-0.1.240-1/virtio-win-0.1.240.iso ebd48258668f7f78e026ed276c28a9d19d83e020ffa080ad69910dc86bbcbcc6

>&2 echo '[*] Creating zvol and libvirt guest'
zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new"
>> $undo_commands echo "zfs destroy '$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new'"
>&2 echo '[*] Creating zvol (if needed)'
zfs list -Ho name "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name" || zfs create -V 90G "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"

>&2 echo '[*] Creating libvirt guest (or recreating it with new config)'
if virsh domstate -- "$image_name"; then
virsh undefine -- "$image_name"
fi
virsh define -- "$image_dir/guest.xml"
>> $undo_commands echo "virsh undefine -- '$image_name.init'"
virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name.new" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new"
>> $undo_commands echo "virsh undefine -- '$image_name.new'"
virt-clone --preserve-data --check path_in_use=off -o "$image_name.init" -n "$image_name" -f "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"
virsh undefine -- "$image_name.init"

>&2 echo '[*] Wiping zvol'
dd bs=1M count=1 if=/dev/zero of="/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"

>&2 echo '[*] Writing disk images'
inject /var/lib/libvirt/images "$cache_dir/virtio-win-0.1.240.iso"
genisoimage -J -o "/var/lib/libvirt/images/$image_name.config.iso" "$image_dir/autounattend.xml"

>&2 echo '[*] Starting guest, to install Windows'
virsh start "$image_name.new"
virsh start "$image_name"

>&2 echo '[*] Waiting for guest to shut down (max 640 seconds)' # normally ~313 seconds
if ! time virsh event --timeout 640 -- "$image_name.new" lifecycle; then
if ! time virsh event --timeout 640 -- "$image_name" lifecycle; then
>&2 echo 'virsh event timed out!'
exit 1
fi

>&2 echo '[*] Forcing update of partition block device geometry'
# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks)
blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name"
sleep 1

>&2 echo '[*] Waiting for partition block device to appear'
partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new-part1
partition_block_device=/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name-part1
t=0; while ! test -e $partition_block_device; do
if [ $t -ge $SERVO_CI_ZVOL_BLOCK_DEVICE_TIMEOUT ]; then
>&2 printf '[!] Timed out waiting for block device: %s' $partition_block_device
Expand All @@ -46,24 +56,21 @@ t=0; while ! test -e $partition_block_device; do
t=$((t+1))
done

>&2 echo '[*] Forcing update of partition block device geometry'
# Dec 20 17:12:59 jupiter kernel: EXT4-fs (zd16p1): bad geometry: block count 23564539 exceeds size of device (548091 blocks)
blockdev --rereadpt "/dev/zvol/$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new"

>&2 echo '[*] Configuring base image'
./mount-runner.sh "$image_name.new" "$image_dir/configure-base.sh"
./mount-runner.sh "$image_name" "$image_dir/configure-base.sh"

>&2 echo '[*] Starting guest, to apply changes'
virsh start "$image_name.new"
virsh start "$image_name"

>&2 echo '[*] Waiting for guest to shut down (max 2500 seconds)' # normally ~1218 seconds
if ! time virsh event --timeout 2500 -- "$image_name.new" lifecycle; then
if ! time virsh event --timeout 2500 -- "$image_name" lifecycle; then
>&2 echo 'virsh event timed out!'
exit 1
fi

>&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready"
zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name.new@ready"
snapshot=$(date -u +\%FT\%RZ)
>&2 echo "[*] Taking zvol snapshot: $SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot"
zfs snapshot "$SERVO_CI_ZFS_CLONE_PREFIX/$image_name@build-image-$snapshot"

# TODO: check that servo was actually built correctly

Expand Down

0 comments on commit 4a3bf0a

Please sign in to comment.