From bd500e2391d2101ba554fc1632faefb7f559006c Mon Sep 17 00:00:00 2001 From: Zygmunt Krynicki Date: Fri, 21 Mar 2025 10:24:19 +0100 Subject: [PATCH] Add support for running image-garden as a snap The new image-garden snap offers a one-stop-shop for integration testing, bundling qemu, spread and image-garden build recipes. Extend the documentation, the run-spread.sh helper script as well as spread.yaml to support this new method. Signed-off-by: Zygmunt Krynicki --- README.md | 17 +++++++++++++++-- run-spread.sh | 26 ++++++++++++++++++-------- spread.yaml | 16 +++++++++++++++- 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index eb403b9a2..fe3acba9d 100644 --- a/README.md +++ b/README.md @@ -214,6 +214,18 @@ in an ephemeral virtual machine. This allows testing in isolation from the host, as well as testing across different commonly used distributions and their real kernels. +Image Garden is available as a snap. If you wish to use it this way then snap +then install the snap with: + +```sh +sudo snap install image-garden +``` + +If you need to install snapd first, see https://snapcraft.io/docs/installing-snapd + +Alternatively you may build image-garden and spread from source, and install +dependencies manually. + ```sh sudo apt install git golang whois ovmf genisoimage qemu-utils qemu-system go install github.com/snapcore/spread/cmd/spread@latest @@ -227,8 +239,9 @@ git clean -xdf # or ~/go/bin/spread -v garden:ubuntu-cloud-24.04:tests/regression/apparmor:at_secure ``` -Running the `run_spread.sh` script, with `spread` on `PATH` will run all the -tests across several supported systems (Debian, Ubuntu and openSUSE). +Running the `run_spread.sh` script, with `image-garden` snap installed or with +`spread` on `PATH` will run all the tests across several supported systems +(Debian, Ubuntu and openSUSE). If you include a `bzImage` file in the root of the repository then that kernel will be used in the integration test. Please look at `spread.yaml` for details. diff --git a/run-spread.sh b/run-spread.sh index da9ac89cf..236f6a831 100755 --- a/run-spread.sh +++ b/run-spread.sh @@ -4,14 +4,24 @@ # quad-core CPU with 8GB of RAM and no desktop session. set -xeu -if test -z "$(command -v spread)"; then - echo "You need to install spread from https://github.com/snapcore/spread with the Go compiler and the command: go install github.com/snapcore/spread/cmd/spread@latest" >&2 - exit 1 -fi +if [ -n "$(command -v image-garden.spread)" ]; then + if ! snap run --shell image-garden -c "snapctl is-connected kvm"; then + echo "Please connect the kvm interface to image-garden" >&2 + echo "snap connect image-garden:kvm" >&2 + exit 1 + fi + SPREAD=image-garden.spread +else + SPREAD=spread + if test -z "$(command -v spread)"; then + echo "You need to install spread from https://github.com/snapcore/spread with the Go compiler and the command: go install github.com/snapcore/spread/cmd/spread@latest" >&2 + exit 1 + fi -if test -z "$(command -v image-garden)"; then - echo "You need to install image-garden from https://gitlab.com/zygoon/image-garden: make install prefix=/usr/local" >&2 - exit 1 + if test -z "$(command -v image-garden)"; then + echo "You need to install image-garden from https://gitlab.com/zygoon/image-garden: make install prefix=/usr/local" >&2 + exit 1 + fi fi rm -rf spread-logs spread-artifacts @@ -23,7 +33,7 @@ for system in \ ubuntu-cloud-22.04 \ ubuntu-cloud-24.04 \ ubuntu-cloud-24.10; do - if ! spread -artifacts ./spread-artifacts -v "$system" | tee spread-logs/"$system".log; then + if ! "$SPREAD" -artifacts ./spread-artifacts -v "$system" | tee spread-logs/"$system".log; then echo "Spread exited with code $?" >spread-logs/"$system".failed fi done diff --git a/spread.yaml b/spread.yaml index ee1ad81ed..41f21da80 100644 --- a/spread.yaml +++ b/spread.yaml @@ -5,6 +5,15 @@ backends: # TODO: Switch to a released version for better stability. type: adhoc allocate: | + # Spread automatically injects /snap/bin to PATH. When we are + # running from the image-garden snap then SPREAD_HOST_PATH is the + # original path before such modifications were applied. Snap + # applications cannot normally run /snap/bin/* entry-points + # successfully so re-set PATH to the original value, as provided by + # snapcraft. + if [ -n "${SPREAD_HOST_PATH-}" ]; then + PATH="${SPREAD_HOST_PATH}" + fi # Use just enough RAM to link the parser on a virtual system with # two cores. Using more cores may easily consume more memory, due # to make -j$(nproc), used below than a small CI/CD system is @@ -38,7 +47,12 @@ backends: # Ask image garden to allocate the system and relay the result back # to spread as either success of failure. exec image-garden allocate "$SPREAD_SYSTEM"."$ARCH" - discard: image-garden discard "$SPREAD_SYSTEM_ADDRESS" + discard: | + # See above for an explanation. + if [ -n "${SPREAD_HOST_PATH-}" ]; then + PATH="${SPREAD_HOST_PATH}" + fi + image-garden discard "$SPREAD_SYSTEM_ADDRESS" systems: # All systems except for the one Ubuntu system are marked as # manual. This way we don't accidentally spin up everything when