commit 12cf09da3ba25ffb5aac1cfd5432ecac9daa6a9c Author: stb Date: Fri Jul 26 19:12:07 2024 +0200 WIP diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..7b01ac9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.qcow2 +.#* +forgejo_runner +*~ diff --git a/build-forgejorunner-template.sh b/build-forgejorunner-template.sh new file mode 100755 index 0000000..049abc7 --- /dev/null +++ b/build-forgejorunner-template.sh @@ -0,0 +1,55 @@ +#!/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} + +virt-customize -a ${runner_image} \ + --update \ + --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' \ + --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 \ + +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} --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 ubuntu2404 +qm cloudinit update ${vm_id} +qm template ${vm_id} +echo "*** Done ***" diff --git a/build-github-runner-kvm-ubuntu-latest-qcow.sh b/build-github-runner-kvm-ubuntu-latest-qcow.sh new file mode 100755 index 0000000..ef5dce9 --- /dev/null +++ b/build-github-runner-kvm-ubuntu-latest-qcow.sh @@ -0,0 +1,35 @@ +#!/bin/sh + +# +# Prepare a (Debian/Ubuntu) host to build a KVM qcow image from Githubs +# runner-images repo patched for KVM. Run this as root. +# Depending on the resources of your host and download speed, this will take +# between 30 and 120 minutes. +# + +HERE="$(pwd)" + +# install prerequiste pacakges +apt install cloud-init git qemu-utils qemu-system-x86 tmux unzip + +# install packer, 1.9.5 is the latest release still under MPL +if which packer >/dev/null; then + echo "Packer already installed" +else + wget https://releases.hashicorp.com/packer/1.9.5/packer_1.9.5_linux_amd64.zip + unzip packer_1.9.5_linux_amd64.zip + cp packer /usr/local/bin + chmod +x /usr/local/bin/packer + rm packer packer_*_linux_amd64.zip +fi + +# clone repo +git clone -b ubuntu24/20240714.1 https://github.com/fffonion/runner-images-kvm + +# run build +cd runner-images-kvm/images/ubuntu/templates +packer init ubuntu-24.04.pkr.hcl +packer build ubuntu-24.04.pkr.hcl +cd ${HERE} +mv runner-images-kvm/images/ubuntu/templates/output-custom_image/ubuntu-24.04 github-runner-image-ubuntu-24.04.qcow +rm -r runner-images-kvm diff --git a/forgejo-runner-3.5.0-linux-amd64 b/forgejo-runner-3.5.0-linux-amd64 new file mode 100644 index 0000000..470763c Binary files /dev/null and b/forgejo-runner-3.5.0-linux-amd64 differ diff --git a/forgejo-runner.service b/forgejo-runner.service new file mode 100644 index 0000000..8f6d083 --- /dev/null +++ b/forgejo-runner.service @@ -0,0 +1,12 @@ +[Unit] +Description=Forgejo Runner + +[Service] +Type=simple +ExecStart=/usr/local/bin/forgejo-runner daemon +Restart=on-failure +User=forgejo-runner +Group=forgejo-runner +WorkingDirectory=/home/forgejo-runner + +[Install]