forgejo-runner-pve-ubuntu-l.../build-forgejorunner-template.sh

65 lines
2.4 KiB
Bash
Raw Permalink Normal View History

2024-07-26 19:12:07 +02:00
#!/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"
2024-07-27 10:18:41 +02:00
ssh ${builder_host} sudo sh <${builder_script}
scp ${builder_host}:${runner_image} .
2024-07-26 19:12:07 +02:00
2024-07-27 09:58:18 +02:00
wget --output-document=forgejo-runner ${forgejo_runner_url}
2024-07-26 19:34:21 +02:00
wget -N https://git.hamburg.ccc.de/CCCHH/infrastructure-authorized-keys/raw/branch/trunk/authorized_keys
2024-07-26 19:12:07 +02:00
virt-customize -a ${runner_image} \
--update \
2024-07-27 09:58:18 +02:00
--run-command 'apt dist-upgrade -y' \
2024-07-26 19:12:07 +02:00
--install qemu-guest-agent \
--run-command 'systemctl enable fstrim.timer' \
--edit '/etc/passwd:$_ = "" if /^forgejo:/' \
--edit '/etc/group:$_ = "" if /^forgejo:/' \
2024-07-27 09:58:18 +02:00
--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' \
2024-07-26 19:12:07 +02:00
--copy-in forgejo-runner.service:/etc/systemd/system \
2024-07-27 09:58:18 +02:00
--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" \
2024-07-26 19:12:07 +02:00
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}
2024-07-26 19:34:21 +02:00
qm set ${vm_id} --scsihw virtio-scsi-pci --scsi0 ${vm_storage}:vm-${vm_id}-disk-0,ssd=1,discard=on
2024-07-26 19:12:07 +02:00
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
2024-07-26 19:34:21 +02:00
qm set ${vm_id} --tags ubuntu24.04
2024-07-26 19:12:07 +02:00
qm cloudinit update ${vm_id}
qm template ${vm_id}
2024-07-26 19:34:21 +02:00
2024-07-26 19:12:07 +02:00
echo "*** Done ***"