|
1 | | -### Github runner ansible deployment |
2 | | -TODO |
| 1 | +# Github runner ansible deployment |
3 | 2 |
|
4 | | -#### What do I need to use it ? |
5 | | -TODO |
| 3 | +This ansible deployment allows you to deploy self-hosted github runner used by the [meshtastic firmware project](https://github.com/meshtastic/firmware). |
| 4 | +Those runners are building firmware for meshtastic devices. |
6 | 5 |
|
7 | | -#### What does it do ? |
8 | | -TODO |
| 6 | +## What do I need to use it ? |
9 | 7 |
|
10 | | -#### What to change before deployment ? |
11 | | -TODO |
| 8 | +### On your local machine |
12 | 9 |
|
13 | | -#### How to trigger the deployment ? |
| 10 | +To be able to use this playbook you need have [Ansible installed](https://docs.ansible.com/ansible/latest/installation_guide/intro_installation.html) on your local machine. |
| 11 | +A github token provided by the meshtastic crew is also required. |
14 | 12 |
|
15 | | -Visualize the changes without applying: |
| 13 | +### On your runner's remote machine |
| 14 | + |
| 15 | +Currently only a debian or fedora based system is supported. |
| 16 | +You need to have a SSH remote access user able to escalate using sudo. |
| 17 | +This is required as this playbook will install [required tools](./roles/basic-os/tasks/basic-os.yml#L1-L22) and configure your system to be able to run podman containers (the actual github runner containers). |
| 18 | + |
| 19 | +## What does it do ? |
| 20 | + |
| 21 | +* create an unprivileged `github` user: [here](./roles/basic-os/tasks/basic-os.yml#L24-L29) |
| 22 | +* configure podman: [here](./roles/basic-os/tasks/basic-os.yml#L31-L47) |
| 23 | +* create a podman container for each runner: [here](./roles/runner/tasks/github-runner.yml#L20-34) |
| 24 | +* create a systemd service for each runner container: [here](./roles/runner/tasks/github-runner.yml#L36-55) |
| 25 | +* create a secret file for each runner container: [here](./roles/runner/tasks/github-runner.yml#L1-18) |
| 26 | + |
| 27 | +In your newly created `github` user's home, you will find 2 files per runners: |
| 28 | +``` |
| 29 | +github@runner-meshtastic:~$ ls -la |
| 30 | +.<your-runners-name>-meshtastic.env # current running job secrets |
| 31 | +.<your-runners-name>-meshtastic.make_env.sh # script generating the "curent running job secrets" file |
| 32 | +``` |
| 33 | + |
| 34 | +Secrets are generated for each runner container by the `.<your-runners-name>-meshtastic.make_env.sh` script triggered by the [systemd service](./roles/runner/files/github-runner-meshtastic.service.j2#L10) and are written in `.<your-runners-name>-meshtastic.env`. |
| 35 | + |
| 36 | +##### Typical operation |
| 37 | +1. Before a container is started, the file `.<your-runners-name>-meshtastic.make_env.sh` is executed and write token values in `.<your-runners-name>-meshtastic.env` |
| 38 | +2. The container starts, the file `.<your-runners-name>-meshtastic.env` is picked up inside the container [as a volume](./roles/runner/tasks/github-runner.yml#L30) |
| 39 | +3. The container authenticate on github using the secrets stored in `.<your-runners-name>-meshtastic.env` |
| 40 | +4. The meshtastic firmware job is executed |
| 41 | +5. The container terminates |
| 42 | +6. If the container [terminated smoothly](./roles/runner/files/github-runner-meshtastic.service.j2#L16), back to step `1.` |
| 43 | + |
| 44 | +## What do I need to adjust before deployment ? |
| 45 | + |
| 46 | +* In the [host.ini](./hosts.ini) file add the hostname FQDN on which you wish to install runners. |
| 47 | +* Adjust the [the runner.yml vars](./vars/runner.yml) accordingly: |
| 48 | +``` |
| 49 | +github_token: meshtastic-github-token # Provided by the meshtastic crew |
| 50 | +user_nickname: github-username # Your github nickname |
| 51 | +runner_servers: |
| 52 | + your-first-system-fqdn.tld: # Your host as written in the host.ini file |
| 53 | + runners: |
| 54 | + - name: runner-1 # The name of your runner |
| 55 | + runner_location: datacenter-alpha # The location of your runner |
| 56 | + - name: runner-2 |
| 57 | + runner_location: datacenter-bravo |
| 58 | + your-second-system-fqdn.tld: |
| 59 | + runners: |
| 60 | + - name: runner-3 |
| 61 | + runner_location: datacenter-charlie |
| 62 | + - name: runner-4 |
| 63 | + runner_location: datacenter-delta |
| 64 | +``` |
| 65 | + |
| 66 | +## How to trigger the deployment ? |
| 67 | + |
| 68 | +You're now ready to deploy your runners ! |
| 69 | + |
| 70 | +You can trigger a "dry-run" and visualize the changes without applying them like this: |
16 | 71 | ``` |
17 | | -ansible-playbook -i hosts.ini runner-meshtastic.yml -DCK |
| 72 | +ansible-playbook -i hosts.ini runner-meshtastic.yml -DKC |
18 | 73 | ``` |
19 | 74 |
|
20 | | -Applying the changes: |
| 75 | +If you're happy with the result, trigger and apply changes as follow: |
21 | 76 | ``` |
22 | 77 | ansible-playbook -i hosts.ini runner-meshtastic.yml -DK |
23 | | -``` |
| 78 | +``` |
| 79 | + |
| 80 | +## And then ? |
| 81 | + |
| 82 | +Do a little review of the system once again to ensure that files and services are populated properly. |
| 83 | +Once confident, you can start your runners for the first time like this: |
| 84 | + |
| 85 | +``` |
| 86 | +sudo systemctl start github-<your-runner-1-name>-meshtastic.service |
| 87 | +sudo systemctl start github-<your-runner-2-name>-meshtastic.service |
| 88 | +... |
| 89 | +``` |
| 90 | + |
| 91 | +If you need to debug something you can check your runner logs like that: |
| 92 | +``` |
| 93 | +sudo -u github podman logs --tail=40 -f <your-runner-name>-meshtastic |
| 94 | +``` |
0 commit comments