/ build-and-test.sh
build-and-test.sh
 1  #!/bin/bash
 2  
 3  set -euo pipefail
 4  
 5  image="$1"
 6  cache="$2"
 7  shift 2
 8  
 9  echo Building image.
10  rm -f "$cache/ambient.tar.gz"
11  ./ambient-build-vm --data . --cache "$cache" --image "$image" "$@"
12  
13  tmp="$(mktemp -d)"
14  trap 'rm -rf "$tmp"' EXIT
15  
16  mkdir "$tmp/files"
17  cat <<EOF >"$tmp/files/run-ci"
18  echo xyzzy
19  EOF
20  chmod +x "$tmp/files/run-ci"
21  
22  tar -cf "$tmp/run-ci.tar" -C "$tmp/files" .
23  cp "$image" "$tmp/img.qcow2"
24  
25  QVMF_FD="/usr/share/ovmf/OVMF.fd"
26  cp "$QVMF_FD" "$tmp/vars"
27  
28  echo Testing image.
29  kvm \
30  	-m 1024 \
31  	-smp cpus=1 \
32  	-display none \
33  	-serial "file:/$tmp/log0" \
34  	-serial "file:/$tmp/log1" \
35  	-drive if=pflash,format=raw,unit=0,file="$QVMF_FD",readonly=on \
36  	-drive if=pflash,format=raw,unit=1,file="$tmp/vars" \
37  	-drive format=qcow2,if=virtio,file="$tmp/img.qcow2" \
38  	-drive format=raw,if=virtio,file="$tmp/run-ci.tar",readonly=on \
39  	-nodefaults
40  
41  if ! grep -q '^xyzzy' "$tmp/log1" >/dev/null; then
42  	echo "FAILED to perform a simple CI run" 1>&2
43  	cat -v "$tmp/log1"
44  	exit 1
45  fi
46  
47  echo "OK. $image is ready to use."