-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.sh
executable file
·68 lines (55 loc) · 1.92 KB
/
test.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env bash
set -e
# example: sudo OS_NAME=ubuntu ./test.sh quay.io/metalstack/ubuntu:22.04
hash ignite 2>/dev/null || { echo >&2 "ignite not found please install from: https://github.com/weaveworks/ignite"; exit 1; }
IMAGE="${1}"
VM_NAME="vm-${OS_NAME}"
MACHINE_TYPE="machine"
KERNEL_IMAGE="weaveworks/ignite-kernel:5.10.51"
if [[ "$OS_NAME" == *firewall ]]; then
MACHINE_TYPE="firewall"
# for firewalls we take the metal-stack kernel for nftables support by the kernel
KERNEL_IMAGE="metal-kernel"
fi
if [ "${KERNEL_IMAGE}" == "metal-kernel" ]; then
echo "build metal-kernel oci"
cd test && docker build . -t metal-kernel:latest && cd -
echo "import metal-kernel image to ignite"
sudo ignite kernel rm -f metal-kernel:latest || true
sudo ignite kernel import --runtime=docker metal-kernel:latest
fi
echo "import image oci to ignite: ${IMAGE}"
sudo ignite stop "${VM_NAME}" || true
sudo ignite rm "${VM_NAME}" || true
# cleaning up all prior images to prevent ambiguous image names
for image in $(sudo ignite images -q); do
sudo ignite image rm -f "$image"
done
sudo ignite image import --runtime=docker --log-level debug "${IMAGE}"
echo "create ignite / firecracker vm"
chmod 0600 ./test/key
chmod 0644 ./test/key.pub
sudo ignite run "${IMAGE}" \
--name "${VM_NAME}" \
--kernel-image "${KERNEL_IMAGE}" \
--size 4G \
--ssh=./test/key.pub \
--copy-files=${PWD}/test/ssh-default:/etc/default/ssh \
--memory 1G --cpus 1 \
--log-level debug
echo "determine ip address of vm"
# this is for ignite < v0.9.0
# IP=$(sudo ignite inspect vm "${VM_NAME}" -t "{{ .Status.IPAddresses }}")
# for version >= v0.9.0
IP=$(sudo ignite inspect vm "${VM_NAME}" -t "{{ .Status.Network.IPAddresses }}")
while ! nc -z "${IP}" 22; do
echo "ssh is not available yet"
sleep 2
done
echo "ssh is available"
sleep 5
cd test
IP=${IP} MACHINE_TYPE=${MACHINE_TYPE} ./test.sh
cd -
sudo ignite stop "${VM_NAME}"
sudo ignite rm "${VM_NAME}"