Skip to content

Instantly share code, notes, and snippets.

@beautyfree
Last active March 24, 2026 17:42
Show Gist options
  • Select an option

  • Save beautyfree/beb34ecd33100d610fd9d8c87f5276ac to your computer and use it in GitHub Desktop.

Select an option

Save beautyfree/beb34ecd33100d610fd9d8c87f5276ac to your computer and use it in GitHub Desktop.
Proxmox VM Create Github Actions Runner
#!/usr/bin/env bash
set -e
# --- VM settings ---
VM_NAME="github-runner"
VM_ID=$(pvesh get /cluster/nextid)
ISO_PATH="ubuntu-22.04.5-live-server-amd64.iso"
ISO_URL="https://releases.ubuntu.com/22.04/ubuntu-22.04.5-live-server-amd64.iso"
ISO_FULL_PATH="/var/lib/vz/template/iso/$ISO_PATH"
STORAGE="local" # directory storage, avoids LVM issues
DISK_SIZE="20G"
CPU=2
MEMORY=4096
# --- GitHub settings ---
if [ -z "$GITHUB_TOKEN" ]; then
read -rp "Enter GitHub PAT with repo/admin rights: " GITHUB_TOKEN
fi
if [ -z "$OWNERREPO" ]; then
read -rp "Enter GitHub owner/repo (e.g. user/repo): " OWNERREPO
fi
# --- Network ---
DEFAULT_IP="192.168.1.200/24"
DEFAULT_GW="192.168.1.1"
DEFAULT_BRIDGE="vmbr0"
read -rp "VM IP [$DEFAULT_IP]: " IP_ADDR
IP_ADDR=${IP_ADDR:-$DEFAULT_IP}
read -rp "Gateway [$DEFAULT_GW]: " GATEWAY
GATEWAY=${GATEWAY:-$DEFAULT_GW}
read -rp "Network bridge [$DEFAULT_BRIDGE]: " BRIDGE
BRIDGE=${BRIDGE:-$DEFAULT_BRIDGE}
# --- Download Ubuntu ISO if missing ---
if [ ! -f "$ISO_FULL_PATH" ]; then
echo "Ubuntu ISO not found. Downloading..."
wget -O "$ISO_FULL_PATH" "$ISO_URL"
else
echo "Ubuntu ISO already exists, skipping download."
fi
# --- Create VM ---
echo "Creating VM $VM_NAME with ID $VM_ID..."
qm create $VM_ID \
--name $VM_NAME \
--memory $MEMORY \
--cores $CPU \
--net0 virtio,bridge=$BRIDGE \
--scsihw virtio-scsi-pci \
--scsi0 $STORAGE:vm-$VM_ID-disk-0,size=$DISK_SIZE \
--serial0 socket
# Attach ISO
qm set $VM_ID --ide2 $ISO_FULL_PATH,media=cdrom
# Set boot order
qm set $VM_ID --boot order=ide2,scsi0
echo "VM created. Boot it and install Ubuntu manually or via cloud-init."
# --- SSH instructions ---
read -rp "Press Enter once VM is up and SSH is ready (user=ubuntu, password=your_choice)..."
SSH="ssh ubuntu@$IP_ADDR"
echo "Installing Docker inside VM..."
$SSH "sudo apt update && sudo apt install -y curl git apt-transport-https ca-certificates software-properties-common"
$SSH "curl -fsSL https://get.docker.com | sh"
$SSH "sudo usermod -aG docker \$USER"
echo "Setting up Docker Buildx..."
$SSH "docker buildx create --use || true"
$SSH "docker buildx inspect --bootstrap"
echo "Setting up GitHub self-hosted runner..."
$SSH "mkdir -p ~/actions-runner && cd ~/actions-runner && \
curl -O -L https://github.com/actions/runner/releases/download/v2.333.0/actions-runner-linux-x64-2.333.0.tar.gz && \
tar xzf actions-runner-linux-x64-2.333.0.tar.gz && \
RUNNER_TOKEN=\$(curl -s -X POST -H \"Accept: application/vnd.github+json\" \
-H \"Authorization: Bearer $GITHUB_TOKEN\" \
https://api.github.com/repos/$OWNERREPO/actions/runners/registration-token | \
grep -o '\"token\": \"[^\"]*' | grep -o '[^"]*\$') && \
./config.sh --unattended --url https://github.com/$OWNERREPO --token \$RUNNER_TOKEN && \
sudo ./svc.sh install && sudo ./svc.sh start"
echo "GitHub Actions runner setup complete!"
@beautyfree
Copy link
Copy Markdown
Author

beautyfree commented Mar 24, 2026

Instructions
Download the script

curl -O https://gist.github.com/beautyfree/beb34ecd33100d610fd9d8c87f5276ac/raw/vm_create_github_actions_runner.sh

Inspect script, customize variables
Run the script

GITHUB_TOKEN=token OWNERREPO=owner/project bash lxc_create_github_actions_runner.sh

Warning: make sure you read and understand the code you are running before executing it on your machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment