#!/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 <"$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."