Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit 26bfea2

Browse files
author
Shimon Ohayon
committed
refactor to enable multirepository runners
1 parent a9842f1 commit 26bfea2

File tree

12 files changed

+304
-180
lines changed

12 files changed

+304
-180
lines changed

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ Automatic configuration for running GitHub Actions on Debian hosts as a service
1212

1313
This module will setup all of the files and configuration needed for GitHub Actions runner to work on any Debian 9 hosts.
1414

15-
1615
### hiera configuration
1716

1817
This module supports configuration through hiera. The following example
19-
creates repository level Actions runners.
18+
creates repository level Actions runners.
19+
2020
```yaml
2121
github_actions_runner::ensure: present
2222
github_actions_runner::base_dir_name: '/data/actions-runner'
@@ -27,10 +27,38 @@ github_actions_runner::org_name: 'github_org'
2727
github_actions_runner::personal_access_token: 'PAT'
2828
github_actions_runner::user: 'root'
2929
github_actions_runner::group: 'root'
30-
github_actions_runner::labels:
31-
- self-hosted-custom
30+
github_actions_runner::instances:
31+
first_instance:
32+
labels:
33+
- self-hosted-custom
3234
```
3335
36+
You can also override some of the keys on the instance level
37+
```yaml
38+
github_actions_runner::ensure: present
39+
github_actions_runner::base_dir_name: '/data/actions-runner'
40+
github_actions_runner::package_name: 'actions-runner-linux-x64'
41+
github_actions_runner::package_ensure: '2.272.0'
42+
github_actions_runner::repository_url: 'https://github.com/actions/runner/releases/download'
43+
github_actions_runner::org_name: 'github_org'
44+
github_actions_runner::personal_access_token: 'PAT'
45+
github_actions_runner::user: 'root'
46+
github_actions_runner::group: 'root'
47+
github_actions_runner::instances:
48+
first_instance:
49+
labels:
50+
- self-hosted-custom1
51+
second_instance:
52+
ensure: absent
53+
third_instance:
54+
labels:
55+
- self-hosted-custom3
56+
repo_name: myrepo
57+
org_name: other_org
58+
personal_access_token: other_secret
59+
```
60+
61+
3462
## Limitations
3563
3664
Tested on Debian 9 stretch hosts only.

REFERENCE.md

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55
**Classes**
66

77
* [`github_actions_runner`](#github_actions_runner)
8-
* [`github_actions_runner::install`](#github_actions_runner_install)
9-
* [`github_actions_runner::config`](#github_actions_runner_config)
10-
* [`github_actions_runner::service`](#github_actions_runner_service)
8+
9+
**Defines**
10+
11+
* [`github_actions_runner::instance`](#github_actions_runner_instance)
1112

1213
## Classes
1314

@@ -31,27 +32,12 @@ Enum, Determine if to add or remove the resource.
3132
Data type: `Absolutepath`
3233
Location of the base directory for actions runner to be installed.
3334

34-
##### `repo_name`
35-
36-
Data type: `Optional[String]`
37-
38-
actions runner github repository name to serve.
39-
Default value: `undef`
40-
4135
##### `org_name`
4236

4337
Data type: `String`
4438

4539
actions runner github organization name.
4640

47-
##### `labels`
48-
49-
Data type: `Optional[Array[String]]`
50-
51-
A list of costum lables to add to a actions runner host.
52-
53-
Default value: `undef`
54-
5541
##### `hostname`
5642

5743
Data type: `String`
@@ -118,14 +104,61 @@ Data type: `String`
118104

119105
Group to be used in Service and directories.
120106

121-
### github_actions_runner::install
107+
### github_actions_runner::instance
108+
109+
#### Parameters
110+
111+
##### `ensure`
112+
113+
Data type: `Enum`
114+
115+
Determine if to add or remove the resource
116+
Default value: `undef`
117+
118+
##### `org_name`
119+
120+
Data type: `String`
121+
122+
actions runner github organization name.
122123

123-
Install the files and packages for the module.
124+
Default value: `github_actions_runner::org_name`
124125

125-
### github_actions_runner::config
126+
##### `personal_access_token`
126127

127-
Main path configuration of the module installation.
128+
Data type: `String`
128129

129-
### github_actions_runner::service
130+
GitHub Personal Access Token with admin permission on the repositories or the organization.
131+
132+
Default value: `github_actions_runner::personal_access_token`
133+
134+
##### `user`
135+
136+
Data type: `String`
137+
138+
User to be used in Service and directories.
139+
140+
Default value: `github_actions_runner::user`
141+
142+
##### `group`
143+
144+
Data type: `String`
145+
146+
Group to be used in Service and directories.
147+
148+
Default value: `github_actions_runner::group`
149+
150+
##### `repo_name`
151+
152+
Data type: `Optional[String]`
153+
154+
actions runner github repository name to serve.
155+
Default value: `undef`
156+
157+
##### `labels`
158+
159+
Data type: `Optional[Array[String]]`
160+
161+
A list of costum lables to add to a actions runner host.
162+
163+
Default value: `undef`
130164

131-
The service setup for this module.

data/common.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ github_actions_runner::org_name: 'github_org'
88
github_actions_runner::personal_access_token: 'PAT'
99
github_actions_runner::user: 'root'
1010
github_actions_runner::group: 'root'
11-
github_actions_runner::labels:
12-
- self-hosted-custom
11+
github_actions_runner::instances: {}
12+

manifests/config.pp

Lines changed: 0 additions & 21 deletions
This file was deleted.

manifests/init.pp

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
# * labels
2323
# Optional[Array[String]], A list of costum lables to add to a runner.
2424
#
25-
# * hostname
26-
# String, actions runner name.
27-
#
2825
# * personal_access_token
2926
# String, GitHub PAT with admin permission on the repositories or the origanization.
3027
#
@@ -54,33 +51,24 @@
5451
String $repository_url,
5552
String $user,
5653
String $group,
57-
String $hostname = $::facts['hostname'],
58-
Optional[Array[String]] $labels = undef,
59-
Optional[String] $repo_name = undef,
60-
54+
Hash[String, Hash] $instances,
6155
) {
6256

6357
$root_dir = "${github_actions_runner::base_dir_name}-${github_actions_runner::package_ensure}"
6458

65-
if $github_actions_runner::labels {
66-
$flattend_labels_list=join($github_actions_runner::labels, ',')
67-
$assured_labels="--labels ${flattend_labels_list}"
68-
} else {
69-
$assured_labels = undef
70-
}
71-
72-
$url = $github_actions_runner::repo_name ? {
73-
undef => "https://github.com/${github_actions_runner::org_name}",
74-
default => "https://github.com/${github_actions_runner::org_name}/${github_actions_runner::repo_name}",
59+
$ensure_directory = $github_actions_runner::ensure ? {
60+
'present' => directory,
61+
'absent' => absent,
7562
}
7663

77-
$token_url = $github_actions_runner::repo_name ? {
78-
undef => "https://api.github.com/repos/${github_actions_runner::org_name}/actions/runners/registration-token",
79-
default => "https://api.github.com/repos/${github_actions_runner::org_name}/${github_actions_runner::repo_name}/actions/runners/registration-token",
64+
file { $github_actions_runner::root_dir:
65+
ensure => $ensure_directory,
66+
mode => '0644',
67+
owner => $github_actions_runner::user,
68+
group => $github_actions_runner::group,
69+
force => true,
8070
}
8171

82-
class { '::github_actions_runner::config': }
83-
-> class { '::github_actions_runner::install': }
84-
~> class { '::github_actions_runner::service': }
72+
create_resources(github_actions_runner::instance, $github_actions_runner::instances)
8573

8674
}

manifests/install.pp

Lines changed: 0 additions & 43 deletions
This file was deleted.

0 commit comments

Comments
 (0)