Skip to content

downgrade sudo to sg libvirt #9

downgrade sudo to sg libvirt

downgrade sudo to sg libvirt #9

name: Sunbeam Multi-node
on:
# Runs on pushes targeting the default branch
push:
branches: ["act"]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
inputs:
workaround:
description: 'Apply a workaround'
required: true
default: true
type: boolean
hardware_profile:
description: 'Specs for each machine'
required: true
default: minimal
type: choice
options:
- minimal
- minimal-with-cpu-overcommit
- tutorial
- allowance
permissions:
contents: read
env:
COLUMNS: 160 # default: 80
DEBIAN_FRONTEND: noninteractive
defaults:
run:
shell: bash -ex {0}
jobs:
sunbeam-multi-node-tutorial:
name: Sunbeam Multi-node Tutorial
runs-on: [ubuntu-24.04]
steps:
- uses: actions/checkout@v4
- name: Check machine specs
run: |
systemd-detect-virt || true
lscpu
free -h
lsblk
lsblk -f
cat /etc/os-release
ip -br a
ip r
resolvectl --no-pager
# TODO: check if greenfield or brownfield first
- name: Install prerequisites
if: ${{ !env.ACT }}
run: |
sudo apt-get update
sudo apt-get install -y uvtool j2cli
- name: Download a VM image
if: ${{ !env.ACT }}
run: |
sg libvirt 'uvt-simplestreams-libvirt sync release=noble arch=amd64'
sg libvirt 'uvt-simplestreams-libvirt query'
- name: Prepare SSH, virtual network bridge, and virtual machines
if: ${{ !env.ACT }}
run: |
# SSH
ssh-keygen -t ed25519 -f ~/.ssh/id_ed25519 -N ''
cat <<EOF | tee -a ~/.ssh/config
Host sunbeam-machine-1
User ubuntu
Hostname 192.168.124.11
Host sunbeam-machine-2
User ubuntu
Hostname 192.168.124.12
Host sunbeam-machine-3
User ubuntu
Hostname 192.168.124.13
EOF
# bridge
sg libvirt 'virsh -c qemu:///system net-define /dev/stdin <<EOF
<network>
<name>sunbeam-virbr0</name>
<bridge name="sunbeam-virbr0" stp="off"/>
<forward mode="nat"/>
<ip address="192.168.124.1" netmask="255.255.255.0" />
</network>
EOF
'
sg libvirt 'virsh -c qemu:///system net-autostart sunbeam-virbr0'
sg libvirt 'virsh -c qemu:///system net-start sunbeam-virbr0'
- name: Clean up previous virtual machines
if: ${{ env.ACT }}
run: |
for i in {1..3}; do
# FIXME: the requirement of FQDN is not documented well in each tutorial
sg libvirt "uvt-kvm destroy 'sunbeam-machine-${i}.localdomain'" || true
done
- name: Prepare virtual machines
run: |
for i in {1..3}; do
sg libvirt "uvt-kvm create \
--machine-type q35 \
--cpu '4' \
--host-passthrough \
--memory '$((16 * 1024))' \
--disk '128' \
--ephemeral-disk '128' \
--ephemeral-disk '128' \
--unsafe-caching \
--bridge sunbeam-virbr0 \
--network-config /dev/stdin \
--ssh-public-key-file ~/.ssh/id_ed25519.pub \
--no-start \
sunbeam-machine-${i}.localdomain \
release=noble <<EOF
network:
version: 2
ethernets:
enp1s0:
dhcp4: false
dhcp6: false
accept-ra: false
addresses:
- 192.168.124.1${i}/24
routes:
- to: default
via: 192.168.124.1
nameservers:
addresses:
- 192.168.124.1
EOF
"
done
# secondary NIC
for i in {1..3}; do
sg libvirt "virsh -c qemu:///system attach-interface 'sunbeam-machine-${i}.localdomain' \
network sunbeam-virbr0 \
--model virtio --config
"
done
for i in {1..3}; do
sg libvirt "virsh -c qemu:///system start 'sunbeam-machine-${i}.localdomain'"
done
for i in {1..3}; do
until ssh -oStrictHostKeyChecking=no "sunbeam-machine-${i}" -- 'cloud-init status --wait; ip -br a; lsblk'; do
sleep 5
done
done