forgejo-runner-pve-ubuntu-l.../build-forgejorunner-template.sh
2024-07-27 10:18:41 +02:00

65 lines
2.4 KiB
Bash
Executable file

#!/bin/sh
#
# Build a Proxmox template VM from a qcow image based on the Github
# runner-images KVM image for ubuntu-24.04, with the forgejo-runner added.
#
set -e
builder_host=forgejo-runner-builder
builder_script=build-github-runner-kvm-ubuntu-latest-qcow.sh
runner_image=github-runner-image-ubuntu-24.04.qcow2
forgejo_runner_url=https://code.forgejo.org/forgejo/runner/releases/download/v3.5.0/forgejo-runner-3.5.0-linux-amd64
vm_id=9042
vm_name=template-forgejo-runner
vm_bridge=vmbr4
vm_storage="local-zfs"
ssh ${builder_host} sudo sh <${builder_script}
scp ${builder_host}:${runner_image} .
wget --output-document=forgejo-runner ${forgejo_runner_url}
wget -N https://git.hamburg.ccc.de/CCCHH/infrastructure-authorized-keys/raw/branch/trunk/authorized_keys
virt-customize -a ${runner_image} \
--update \
--run-command 'apt dist-upgrade -y' \
--install qemu-guest-agent \
--run-command 'systemctl enable fstrim.timer' \
--edit '/etc/passwd:$_ = "" if /^forgejo:/' \
--edit '/etc/group:$_ = "" if /^forgejo:/' \
--run-command 'useradd --groups docker --create-home --shell /bin/bash --uid 2000 --user-group forgejo-runner' \
--copy-in forgejo-runner:/usr/local/bin \
--run-command 'chown root:bin /usr/local/bin/forgejo-runner' \
--run-command 'chmod 0555 /usr/local/bin/forgejo-runner' \
--copy-in forgejo-runner.service:/etc/systemd/system \
--copy-in register-forgejo-runner.sh:/usr/local/bin \
--run-command "mv /usr/local/bin/register-forgejo-runner.sh /usr/local/bin/register-forgejo-runner" \
--run-command "chown root:bin /usr/local/bin/register-forgejo-runner" \
--run-command "chmod +x /usr/local/bin/register-forgejo-runner" \
qm destroy ${vm_id} || true
qm create ${vm_id} --name "${vm_name}" --memory 2048 --net0 virtio,bridge=${vm_bridge}
qm importdisk ${vm_id} ${runner_image} ${vm_storage}
qm set ${vm_id} --scsihw virtio-scsi-pci --scsi0 ${vm_storage}:vm-${vm_id}-disk-0,ssd=1,discard=on
qm set ${vm_id} --ide2 ${vm_storage}:cloudinit
qm set ${vm_id} --boot c --bootdisk scsi0
qm set ${vm_id} --machine q35
qm set ${vm_id} --ostype l26
qm set ${vm_id} --cpu cputype=host
qm set ${vm_id} --cores 2
qm set ${vm_id} --serial0 socket --vga serial0
qm set ${vm_id} --agent 1,fstrim_cloned_disks=1
qm set ${vm_id} --ciuser chaos
qm set ${vm_id} --sshkeys ./authorized_keys
qm set ${vm_id} --ipconfig0 ip=dhcp
qm set ${vm_id} --tags ubuntu24.04
qm cloudinit update ${vm_id}
qm template ${vm_id}
echo "*** Done ***"