diff options
author | Lars Wirzenius <liw@liw.fi> | 2023-12-16 11:39:10 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2023-12-23 09:31:27 +0200 |
commit | c938e3defd64537d3a658330c517c97e4ffcc884 (patch) | |
tree | 46b6545889cf368602f0bba430426cfa66ad6d44 | |
parent | 7d9a301ba38cfa4671644fc8afe35de9def2a8b4 (diff) | |
download | ambient-build-vm-c938e3defd64537d3a658330c517c97e4ffcc884.tar.gz |
feat: add script to build and test an image
Signed-off-by: Lars Wirzenius <liw@liw.fi>
Sponsored-by: author
-rwxr-xr-x | build-and-test.sh | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/build-and-test.sh b/build-and-test.sh new file mode 100755 index 0000000..dd6cbfb --- /dev/null +++ b/build-and-test.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +set -euo pipefail + +image="$1" +cache="$2" +shift 2 + +echo Building image. +rm -f "$cache/ambient.tar.gz" +./ambient-build-vm --data . --cache "$cache" --image "$image" "$@" + +tmp="$(mktemp -d)" +trap 'rm -rf "$tmp"' EXIT + +mkdir "$tmp/files" +cat <<EOF >"$tmp/files/run-ci" +echo xyzzy +EOF +chmod +x "$tmp/files/run-ci" + +tar -cf "$tmp/run-ci.tar" -C "$tmp/files" . +cp "$image" "$tmp/img.qcow2" + +QVMF_FD="/usr/share/ovmf/OVMF.fd" +cp "$QVMF_FD" "$tmp/vars" + +echo Testing image. +kvm \ + -m 1024 \ + -smp cpus=1 \ + -display none \ + -serial "file:/$tmp/log0" \ + -serial "file:/$tmp/log1" \ + -drive if=pflash,format=raw,unit=0,file="$QVMF_FD",readonly=on \ + -drive if=pflash,format=raw,unit=1,file="$tmp/vars" \ + -drive format=qcow2,if=virtio,file="$tmp/img.qcow2" \ + -drive format=raw,if=virtio,file="$tmp/run-ci.tar",readonly=on \ + -nodefaults + +if ! grep -q '^xyzzy' "$tmp/log1" >/dev/null; then + echo "FAILED to perform a simple CI run" 1>&2 + cat -v "$tmp/log1" + exit 1 +fi + +echo "OK. $image is ready to use." |