Introduction #
This is a guide to document the creation of a Self-hosted Github runner in a homelab environment. The reason to set up a runner in your homelab is that the runner will enable Github workflows to run scripts and other automation software from the runner. This method demonstrates how to use Proxmox to create a VM and install and configure a Gitlab runner and is for testing purposes only. It is a basic project but I believe it makes you more familiar with Proxmox, setting up VMs and installing and configuring software using the command line.
Being comfortable with the command line using either a Linux shell and powershell is a great skill for performing a variety of tasks in different computing environments. A command line is also great as commands can be easily recorded to show how you achieved a task, and these commands can be thrown into a wiki for quick reference material in similar scenarios. Often I fondly remember well explained commands left by admins and developers in a wiki that have worked perfectly a few years after they were initially written.
The rough steps for this demonstration is as follows:
- Describe dependencies
- Create VM template and VM to use on Proxmox
- Setup new user in Proxmox
- Generate and save SSH key for that user to use
- Create the runner VM
- Install and configure a Github Runner
- Run a test workflow
Dependencies #
What components do we need to complete this project?
Proxmox -
For starters, I am assuming that you have Proxmox installed (version 8) on a machine somewhere in your homelab. If you don’t and would like to set Proxmox up there are a lot of good guides on this subject that will do a better job at running through the initial setup of the Proxmox[1]. I would like to start from a point where Proxmox is alive and kicking, available on a local area network at https://<your proxmox IP>:8006. I am using an old computer to run Proxmox, which has a CPU with 4 cores and 32 GB of RAM and a 1 TB SSD.
Github - Having a Github account and test repository is also required for running the Github Workflow and setting up the Github Runner. Github’s documentation is a great starting point for understanding Github Workflows and self-hosted runners[3].
Unix Shell - The only software I need on my local machine to complete this task is an SSH client to access Proxmox. I am going to use the SSH client that comes with Ubuntu on Windows Subsystem for Linux, for this task. Git, or a Git client, is also required for pushing code changes to your Github repository.
Proxmox #
Preliminary Configuration #
For this part I will SSH into the Proxmox host in order to create a VM template that can be used to create Virtual Machines on the Proxmox hypervisor. I find creating the template using the command line is quicker and repeatable than trying to use the Proxmox web interface.
First, I will need a non-root user for creating templates and virtual machines on Proxmox. You can use the root user but I think it is good to have some basic familiarity with how to create Linux users that integrate with the Proxmox service. This knowledge is also useful if you need to create a separate user account for running other automation using Terraform or Ansible. For this project I will create a Linux group called “homelabbers” and a Linux user called “homelab”. The Linux group will have Admin privileges on Proxmox and the Linux user will belong to this group, inheriting those permissions.
The commands to perform this are given below. To perform these commands you will need to SSH onto the Proxmox server using the root user’s credentials.
|
|
As an optional quality of life improvement, modify the sudoers file to grant passwordless access to superuser commands.
|
|
The next command creates an SSH key pair and copies the public SSH key to the Proxmox host so you can connect to the machine using the homelab user. The public key is copied to the homelab’s home directory using scp. For test environments I like to use separate key pairs so my important SSH keys are not mixed up in test environments.
|
|
VM Template Creation #
A VM template is required to make VM clones that are used as the foundation for new Virtual Machines that will run in the homelab Proxmox environment. The following script block installs some dependencies on the Proxmox host and then downloads and sets up a VM template.
There is a bit going on in the code block so I have broken it down into two chunks. First, we need to update the package lists on Proxmox to remove the Proxmox enterprise repositories (subscription required) and add debian repositories so we can install some packages.
|
|
Next, I download the Debian Cloud Image to the Proxmox host and use QEMU/KVM CLI tool (qm) to create a VM using ID of 9000, set up disks used by the VM and finally creating a template from the VM [2]. The virt-customize tool is used to install the guest agent software so Proxmox can receive information from the VM.
|
|
The created VM template should be listed on the Proxmox web interface.
Virtual Machine Creation #
After the VM Template is available on the Proxmox host a single VM is created with a static IP address and the SSH key of the homelab user for accessing the VM once it is created. The qm set commands configure the VM to use a specific IP address (please change this to suit your network requirements), network gateway, CPU and RAM, and public ssh key. Finally the root volume of the VM is resized to 50GB and the VM is started.
|
|
Self-hosted Runner Configuration #
For this example I will use the installation instructions provided by Github. These instructions are found by navigating to the Settings > Actions > Runner page in your repository and selecting “New self-hosted runner”.
On the following page grab the download and configuration commands and run those commands on the Proxmox VM runner.
|
|
If this has worked correctly the runner should be in an idle state.
Github - Create a Workflow #
Lastly, I want to create a Github Action to use on the newly configured runner. This will allow me to run some simple commands in a workflow.
Create the workflow template in your .github/workflows directory. The workflow template below runs every 5 minutes on the self-hosted runner labelled “homelab”. Every time the workflow is executed the self-hosted runner will run the commands ip addr; whoami and this will be displayed in the output section of the workflow on Github.
|
|
Commit and push the new workflow file up to your repository.
|
|
From the Github Action console the Workflow should have been successfully run and outputs from the commands are displayed.
Clean Up #
Proxmox - Remove Resources #
To remove the VM and VM template run the following commands from the homelab or root user on Proxmox.
|
|
Github - Remove Workflow #
|
|
Thank you for reading.