From 74483e57f80cf186dcf3df68a4b8b4b94647290f Mon Sep 17 00:00:00 2001 From: Danny Bessems Date: Mon, 28 Jul 2025 20:37:38 +1000 Subject: [PATCH] build: Start virtual machine w/ cloud-init configuration --- .gitea/workflows/actions.yaml | 33 +++++++++++++++++++++++++++++++-- cloud-init/user-data.template | 5 +++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.gitea/workflows/actions.yaml b/.gitea/workflows/actions.yaml index 6793f8b..627d4ab 100644 --- a/.gitea/workflows/actions.yaml +++ b/.gitea/workflows/actions.yaml @@ -50,17 +50,27 @@ jobs: steps: - name: Check out repository code uses: actions/checkout@v4 + - name: Create folder structure + run: | + mkdir -p \ + ubuntu-vm + - name: Download source Ubuntu iso + run: | + curl -L \ + https://sn.itch.fyi/Repository/iso/Canonical/Ubuntu%20Server%2024.04/ubuntu-24.04-server-cloudimg-amd64.img \ + -o ubuntu-vm/ubuntu.img \ + -u ${{ secrets.REPO_USERNAME }}:${{ secrets.REPO_PASSWORD }} - name: Generate seed ISO - shell: bash run: | apt-get update && \ apt-get install -y \ + gettext \ genisoimage envsubst < cloud-init/user-data.template > cloud-init/user-data genisoimage \ - -output seed.iso \ + -output ubuntu-vm/seed.iso \ -volid cidata \ -joliet \ -rock \ @@ -68,6 +78,25 @@ jobs: env: ROOT_HASHED_PASSWORD: ${{ secrets.ROOT_HASHED_PASSWORD }} PUBLIC_SSHKEY: ${{ secrets.PUBLIC_SSHKEY }} + - name: Start virtual machine + run: | + apt-get update && \ + apt-get install -y \ + qemu-system-x86 \ + qemu-utils + + [ -e /dev/kvm ] && kvm_flag="-enable-kvm" || kvm_flag="" + + qemu-system-x86_64 \ + $kvm_flag \ + -m 3072 \ + -smp 2 \ + -cpu host \ + -drive file=ubuntu-vm/ubuntu.img,if=virtio,format=qcow2 \ + -drive file=ubuntu-vm/seed.iso,format=raw,media=cdrom \ + -nographic \ + -net nic \ + -net user # semrel: # name: Semantic Release diff --git a/cloud-init/user-data.template b/cloud-init/user-data.template index 798202d..cb84c68 100644 --- a/cloud-init/user-data.template +++ b/cloud-init/user-data.template @@ -14,6 +14,11 @@ runcmd: - apt-get install -y linux-modules-extra-$(uname -r) - sysctl -w net.ipv6.conf.all.disable_ipv6=1 - systemctl enable --now qemu-guest-agent.service + - cloud-init clean --logs + - truncate -s 0 /etc/hostname /etc/machine-id + - rm -f /etc/ssh/ssh_host_* /var/lib/dbus/machine-id + - ln -s /etc/machine-id /var/lib/dbus/machine-id + - poweroff disable_root: false users: