Skip to content

Commit 568e230

Browse files
authored
Add runner start method configuration (#21)
1 parent 79f3ffb commit 568e230

4 files changed

Lines changed: 50 additions & 26 deletions

File tree

README.md

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,31 @@ jobs:
151151
> Use an SSH key ID (`ssh_key`) to disable root password generation and Hetzner Cloud email notifications.
152152

153153
| Name | Required | Description | Default |
154-
|---------------------|----------|-------------|---------|
155-
| `create_wait` | | Wait up to `create_wait` retries (10 sec each) to create the Server resource via the Hetzner Cloud API. Retry if: Resource is not available ([Limited availability of Cloud plans](https://status.hetzner.com/incident/aa5ce33b-faa5-4fd0-9782-fde43cd270cf)). | `360` (1 hour) |
156-
| `delete_wait` | | Wait up to `delete_wait` retries (10 sec each) to delete the Server resource via the Hetzner Cloud API. Retry if: Temporary outage of the API ([Fault report on Cloud API and Cloud Console](https://status.hetzner.com/incident/440e6b5f-249c-45fd-8074-e5d79cc4e2a6)). | `360` (1 hour) |
157-
| `enable_ipv4` | | Attach an IPv4 on the public NIC (true/false). If false, no IPv4 address will be attached. Warning: The GitHub API requires IPv4. Disabling it will result in connection failures. | `true` |
158-
| `enable_ipv6` | | Attach an IPv6 on the public NIC (true/false). If false, no IPv6 address will be attached. | `true` |
159-
| `github_token` | ✓ (always) | Fine-grained GitHub Personal Access Token (PAT) with 'Read and write' access to 'Administration' assigned. | |
160-
| `hcloud_token` | ✓ (always) | Hetzner Cloud API token with 'Read & Write' permissions assigned. | |
161-
| `image` | | Name or ID (integer) of the Image the Server is created from. | `ubuntu-24.04` (Ubuntu 24.04) |
162-
| `location` | | Name of Location to create Server in. | `nbg1` (Nürnberg 1) |
163-
| `mode` | ✓ (always) | Choose either `create` to create a new GitHub Actions Runner or `delete` to delete a previously created one. | |
164-
| `name` | ✓ (mode `delete`, optional for mode `create`) | The name for the server and label for the GitHub Actions Runner (must be unique within the project and conform to hostname rules: `^[a-zA-Z0-9_-]{1,64}`). | `gh-runner-[RANDOM-INT]` |
165-
| `network` | | Comma separated Network IDs (integer) which should be attached to the Server private network interface at the creation time. | `null` |
166-
| `pre_runner_script` | | Specifies bash commands to run before the GitHub Actions Runner starts. It's useful for installing dependencies with apt-get, dnf, zypper etc. | |
167-
| `primary_ipv4` | | ID (integer) of the IPv4 Primary IP to use. If omitted and `enable_ipv4` is true, a new IPv4 Primary IP will automatically be created. | `null` |
168-
| `primary_ipv6` | | ID (integer) of the IPv6 Primary IP to use. If omitted and `enable_ipv6` is true, a new IPv6 Primary IP will automatically be created. | `null` |
169-
| `runner_dir` | | GitHub Actions Runner installation directory (created automatically; no trailing slash). | `/actions-runner` |
170-
| `runner_version` | | GitHub Actions Runner version (omit "v"; e.g., "2.321.0"). "latest" will install the latest version. "skip" will skip the installation. A working installation is expected in the `runner_dir`. | `latest` |
171-
| `runner_wait` | | Wait up to `runner_wait` retries (10 sec each) for runner registration. | `60` (10 min) |
172-
| `server_id` | ✓ (mode `stop`) | ID (integer) of Hetzner Cloud Server to delete. | |
173-
| `server_type` | | Name of the Server type this Server should be created with. | `cx23` (Intel x86, 2 vCPU, 4GB RAM, 40GB SSD) |
174-
| `server_wait` | | Wait up to `server_wait` retries (10 sec each) for the Hetzner Cloud Server to start. | `30` (5 min) |
175-
| `ssh_key` | | Comma separated SSH key IDs (integer) which should be injected into the Server at creation time. | `null` |
176-
| `volume` | | Comma separated Volume IDs (integer) to attach and mount to the Server during creation. Volumes will be automatically mounted at `/mnt/HC_Volume_[VOLUME-ID]`. Volumes must be in the same location as the Server. More details in [Volumes section](#Volumes). | `null` |
177-
| `runner_scope` | | Select scope for this runner. 'org' creates a org-wide runner, while 'repo' creates a repo-only runner. | `repo` |
154+
|-----------------------|----------|-------------|---------|
155+
| `create_wait` | | Wait up to `create_wait` retries (10 sec each) to create the Server resource via the Hetzner Cloud API. Retry if: Resource is not available ([Limited availability of Cloud plans](https://status.hetzner.com/incident/aa5ce33b-faa5-4fd0-9782-fde43cd270cf)). | `360` (1 hour) |
156+
| `delete_wait` | | Wait up to `delete_wait` retries (10 sec each) to delete the Server resource via the Hetzner Cloud API. Retry if: Temporary outage of the API ([Fault report on Cloud API and Cloud Console](https://status.hetzner.com/incident/440e6b5f-249c-45fd-8074-e5d79cc4e2a6)). | `360` (1 hour) |
157+
| `enable_ipv4` | | Attach an IPv4 on the public NIC (true/false). If false, no IPv4 address will be attached. Warning: The GitHub API requires IPv4. Disabling it will result in connection failures. | `true` |
158+
| `enable_ipv6` | | Attach an IPv6 on the public NIC (true/false). If false, no IPv6 address will be attached. | `true` |
159+
| `github_token` | ✓ (always) | Fine-grained GitHub Personal Access Token (PAT) with 'Read and write' access to 'Administration' assigned. | |
160+
| `hcloud_token` | ✓ (always) | Hetzner Cloud API token with 'Read & Write' permissions assigned. | |
161+
| `image` | | Name or ID (integer) of the Image the Server is created from. | `ubuntu-24.04` (Ubuntu 24.04) |
162+
| `location` | | Name of Location to create Server in. | `nbg1` (Nürnberg 1) |
163+
| `mode` | ✓ (always) | Choose either `create` to create a new GitHub Actions Runner or `delete` to delete a previously created one. | |
164+
| `name` | ✓ (mode `delete`, optional for mode `create`) | The name for the server and label for the GitHub Actions Runner (must be unique within the project and conform to hostname rules: `^[a-zA-Z0-9_-]{1,64}`). | `gh-runner-[RANDOM-INT]` |
165+
| `network` | | Comma separated Network IDs (integer) which should be attached to the Server private network interface at the creation time. | `null` |
166+
| `pre_runner_script` | | Specifies bash commands to run before the GitHub Actions Runner starts. It's useful for installing dependencies with apt-get, dnf, zypper etc. | |
167+
| `primary_ipv4` | | ID (integer) of the IPv4 Primary IP to use. If omitted and `enable_ipv4` is true, a new IPv4 Primary IP will automatically be created. | `null` |
168+
| `primary_ipv6` | | ID (integer) of the IPv6 Primary IP to use. If omitted and `enable_ipv6` is true, a new IPv6 Primary IP will automatically be created. | `null` |
169+
| `runner_dir` | | GitHub Actions Runner installation directory (created automatically; no trailing slash). | `/actions-runner` |
170+
| `runner_version` | | GitHub Actions Runner version (omit "v"; e.g., "2.321.0"). "latest" will install the latest version. "skip" will skip the installation. A working installation is expected in the `runner_dir`. | `latest` |
171+
| `runner_wait` | | Wait up to `runner_wait` retries (10 sec each) for runner registration. | `60` (10 min) |
172+
| `server_id` | ✓ (mode `stop`) | ID (integer) of Hetzner Cloud Server to delete. | |
173+
| `server_type` | | Name of the Server type this Server should be created with. | `cx23` (Intel x86, 2 vCPU, 4GB RAM, 40GB SSD) |
174+
| `server_wait` | | Wait up to `server_wait` retries (10 sec each) for the Hetzner Cloud Server to start. | `30` (5 min) |
175+
| `ssh_key` | | Comma separated SSH key IDs (integer) which should be injected into the Server at creation time. | `null` |
176+
| `volume` | | Comma separated Volume IDs (integer) to attach and mount to the Server during creation. Volumes will be automatically mounted at `/mnt/HC_Volume_[VOLUME-ID]`. Volumes must be in the same location as the Server. More details in [Volumes section](#Volumes). | `null` |
177+
| `runner_scope` | | Select scope for this runner. 'org' creates a org-wide runner, while 'repo' creates a repo-only runner. | `repo` |
178+
| `runner_start_method` | | Defines how the GitHub runner process is started. Supported values are `standalone` and `systemd`. | `standalone` |
178179

179180
## Outputs
180181

action.sh

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,19 @@ export MY_RUNNER_DIR
373373
export MY_RUNNER_VERSION
374374
export MY_RUNNER_TARGET
375375

376+
# Setup runner start method.
377+
# https://docs.github.com/en/actions/how-tos/manage-runners/self-hosted-runners/configure-the-application
378+
if [[ "$INPUT_RUNNER_START_METHOD" == "standalone" ]]; then
379+
# shellcheck disable=SC2016
380+
yq -i '.runcmd += ["$MY_RUNNER_DIR/run.sh"]' cloud-init.template.yml && \
381+
echo "Set run method 'standalone' to cloud-init.template.yml."
382+
elif [[ "$INPUT_RUNNER_START_METHOD" == "systemd" ]]; then
383+
#https://docs.github.com/en/actions/how-tos/manage-runners/self-hosted-runners/configure-the-application
384+
# shellcheck disable=SC2016
385+
yq -i '.runcmd += ["$MY_RUNNER_DIR/svc.sh install $(id -nu)", "$MY_RUNNER_DIR/svc.sh start"]' cloud-init.template.yml && \
386+
echo "Set run method 'systemd' to cloud-init.template.yml."
387+
fi
388+
376389
# Substitute environment variables in the cloud-init template and create the final cloud-init configuration
377390
if [[ ! -f "cloud-init.template.yml" ]]; then
378391
exit_with_failure "cloud-init.template.yml not found!"
@@ -433,7 +446,7 @@ fi
433446
MAX_RETRIES=$MY_CREATE_WAIT
434447
RETRY_COUNT=0
435448
while [[ $RETRY_COUNT -lt $MAX_RETRIES ]]; do
436-
echo "Create Server..."
449+
echo "Create Server $MY_NAME..."
437450
if curl \
438451
-X POST \
439452
--fail-with-body \

action.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,15 @@ inputs:
103103
- repo
104104
- org
105105
default: 'repo'
106+
runner_start_method:
107+
description: >-
108+
How to start the runner: 'standalone' (default run.sh script) or 'systemd'
109+
required: false
110+
type: 'choice'
111+
options:
112+
- standalone
113+
- systemd
114+
default: 'standalone'
106115
server_id:
107116
description: >-
108117
ID (integer) of Hetzner Cloud Server to delete.
@@ -166,6 +175,7 @@ runs:
166175
INPUT_RUNNER_VERSION: ${{ inputs.runner_version }}
167176
INPUT_RUNNER_WAIT: ${{ inputs.runner_wait }}
168177
INPUT_RUNNER_SCOPE: ${{ inputs.runner_scope }}
178+
INPUT_RUNNER_START_METHOD: ${{ inputs.runner_start_method }}
169179
INPUT_SERVER_ID: ${{ inputs.server_id }}
170180
INPUT_SERVER_TYPE: ${{ inputs.server_type }}
171181
INPUT_SERVER_WAIT: ${{ inputs.server_wait }}

cloud-init.template.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ runcmd:
1111
- udevadm trigger -c add -s block -p ID_VENDOR=HC -p ID_MODEL=Volume
1212
- export RUNNER_ALLOW_RUNASROOT=1
1313
- bash $MY_RUNNER_DIR/pre_runner_script.sh
14+
- cd $MY_RUNNER_DIR
1415
- bash $MY_RUNNER_DIR/install.sh -v "$MY_RUNNER_VERSION" -d "$MY_RUNNER_DIR"
1516
- $MY_RUNNER_DIR/config.sh --url "https://github.com/${MY_RUNNER_TARGET}" --token "${MY_GITHUB_RUNNER_REGISTRATION_TOKEN}" --name "${MY_NAME}" --labels "${MY_NAME},hetzner" --no-default-labels --disableupdate
16-
- $MY_RUNNER_DIR/run.sh
1717
write_files:
1818
- path: $MY_RUNNER_DIR/pre_runner_script.sh
1919
encoding: b64

0 commit comments

Comments
 (0)