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

Commit 08fa592

Browse files
authored
Merge pull request #37 from Telefonica/manage_path_var_instance
Manage environment PATH in instances
2 parents 1466c20 + 7bf249c commit 08fa592

File tree

5 files changed

+136
-3
lines changed

5 files changed

+136
-3
lines changed

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ This module will setup all of the files and configuration needed for GitHub Acti
1818

1919
### hiera configuration examples
2020

21-
This module supports configuration through hiera.
21+
This module supports configuration through hiera.
2222

2323
#### Creating an organization level Actions runner
2424

@@ -53,7 +53,7 @@ github_actions_runner::instances:
5353
```
5454

5555
Note, your `personal_access_token` has to contain the `repo` permission.
56-
56+
5757
#### Instance level overwrites
5858
```yaml
5959
github_actions_runner::instances:
@@ -88,7 +88,7 @@ github_actions_runner::github_domain: "https://git.example.com"
8888
github_actions_runner::github_api: "https://git.example.com/api/v3"
8989
```
9090

91-
In addition to the runner configuration examples above, you can also configure runners
91+
In addition to the runner configuration examples above, you can also configure runners
9292
on the enterprise level by setting a value for `enterprise_name`, for example:
9393
```yaml
9494
github_actions_runner::ensure: present
@@ -105,6 +105,35 @@ github_actions_runner::instances:
105105

106106
Note, your `personal_access_token` has to contain the `admin:enterprise` permission.
107107

108+
### Update PATH used by Github Runners
109+
110+
By default, puppet will not modify the values that the runner scripts create when
111+
the runner is set.
112+
113+
In case you need to use another value of paths in the environment variable PATH,
114+
you can define through hiera. For example:
115+
116+
- For all runners defined:
117+
```yaml
118+
github_actions_runner::path:
119+
- /usr/local/bin
120+
- /usr/bin
121+
- /bin
122+
- /my/own/path
123+
```
124+
- For just a specific runner:
125+
```yaml
126+
github_actions_runner::instances:
127+
example_org_instance:
128+
path:
129+
- /usr/local/bin
130+
- /usr/bin
131+
- /bin
132+
- /my/own/path
133+
labels:
134+
- self-hosted-custom
135+
```
136+
108137
## Limitations
109138

110139
Tested on Debian 9 (stretch), Debian 10 (buster) and CentOS7 hosts.

manifests/init.pp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,9 @@
5555
# * no_proxy
5656
# Optional[String], Comma separated list of hosts that should not use a proxy. More information at https://docs.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners
5757
#
58+
# * path
59+
# Optional[Array[String]], List of paths to be used as PATH env in the instance runner. If not defined, this file will be kept as created by the runner scripts. Default value: undef
60+
#
5861
class github_actions_runner (
5962
Enum['present', 'absent'] $ensure,
6063
Stdlib::Absolutepath $base_dir_name,
@@ -72,6 +75,7 @@
7275
Optional[String[1]] $http_proxy = undef,
7376
Optional[String[1]] $https_proxy = undef,
7477
Optional[String[1]] $no_proxy = undef,
78+
Optional[Array[String]] $path = undef,
7579
) {
7680

7781
$root_dir = "${github_actions_runner::base_dir_name}-${github_actions_runner::package_ensure}"

manifests/instance.pp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@
4141
# * labels
4242
# Optional[Array[String]], A list of costum lables to add to a runner.
4343
#
44+
# * path
45+
# Optional[Array[String]], List of paths to be used as PATH env in the instance runner. If not defined, this file will be kept as created
46+
# by the runner scripts. (Default: Value set by github_actions_runner Class)
47+
#
4448
define github_actions_runner::instance (
4549
Enum['present', 'absent'] $ensure = 'present',
4650
String[1] $personal_access_token = $github_actions_runner::personal_access_token,
@@ -57,6 +61,7 @@
5761
Optional[String[1]] $enterprise_name = $github_actions_runner::enterprise_name,
5862
Optional[String[1]] $org_name = $github_actions_runner::org_name,
5963
Optional[String[1]] $repo_name = undef,
64+
Optional[Array[String]] $path = $github_actions_runner::path,
6065
) {
6166

6267
if $labels {
@@ -159,6 +164,25 @@
159164
onlyif => "test -d ${github_actions_runner::root_dir}/${instance_name}"
160165
}
161166

167+
$content_path = $path ? {
168+
undef => undef,
169+
default => epp('github_actions_runner/path.epp', {
170+
paths => $path,
171+
})
172+
}
173+
174+
file { "${github_actions_runner::root_dir}/${name}/.path":
175+
ensure => $ensure,
176+
mode => '0644',
177+
owner => $user,
178+
group => $group,
179+
content => $content_path,
180+
require => [Archive["${instance_name}-${archive_name}"],
181+
Exec["${instance_name}-run_configure_install_runner.sh"],
182+
],
183+
notify => Systemd::Unit_file["github-actions-runner.${instance_name}.service"]
184+
}
185+
162186
$active_service = $ensure ? {
163187
'present' => true,
164188
'absent' => false,
@@ -183,6 +207,7 @@
183207
no_proxy => $no_proxy,
184208
}),
185209
require => [File["${github_actions_runner::root_dir}/${instance_name}/configure_install_runner.sh"],
210+
File["${github_actions_runner::root_dir}/${instance_name}/.path"],
186211
Exec["${instance_name}-run_configure_install_runner.sh"]],
187212
}
188213

spec/classes/github_actions_runner_spec.rb

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,10 +344,82 @@
344344
'active' => true,
345345
)
346346
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').that_requires(['File[/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh]',
347+
'File[/some_dir/actions-runner-2.272.0/first_runner/.path]',
347348
'Exec[first_runner-run_configure_install_runner.sh]'])
348349
end
349350
end
350351

352+
context 'is expected to create a .path file with a specific requires and notifies' do
353+
it do
354+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.path')
355+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.path').that_requires(['Archive[first_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
356+
'Exec[first_runner-run_configure_install_runner.sh]'])
357+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.path').that_notifies('Systemd::Unit_file[github-actions-runner.first_runner.service]')
358+
end
359+
end
360+
361+
context 'is expected to create a .path file in an instance with default path list' do
362+
it do
363+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.path').with(
364+
'ensure' => 'present',
365+
'owner' => 'root',
366+
'group' => 'root',
367+
'mode' => '0644',
368+
'content' => nil,
369+
)
370+
end
371+
end
372+
373+
context 'is expected to create a .path file in an instance setting path at global level' do
374+
let(:params) do
375+
super().merge(
376+
'path' => [
377+
'/usr/bin',
378+
'/bin',
379+
],
380+
)
381+
end
382+
383+
it do
384+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.path').with(
385+
'ensure' => 'present',
386+
'owner' => 'root',
387+
'group' => 'root',
388+
'mode' => '0644',
389+
'content' => "/usr/bin:/bin\n",
390+
)
391+
end
392+
end
393+
394+
context 'is expected to create a .path file in an instance setting the path at instance level' do
395+
let(:params) do
396+
super().merge(
397+
'path' => [
398+
'/usr/bin',
399+
'/bin',
400+
],
401+
'instances' => {
402+
'first_runner' => {
403+
'path' => [
404+
'/bin',
405+
'/other/path',
406+
]
407+
},
408+
},
409+
)
410+
end
411+
412+
it do
413+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.path').with(
414+
'ensure' => 'present',
415+
'owner' => 'root',
416+
'group' => 'root',
417+
'mode' => '0644',
418+
'content' => "/bin:/other/path\n",
419+
)
420+
end
421+
end
422+
351423
context 'is expected to remove github_actions_runner unit_file and other resources' do
352424
let(:params) do
353425
super().merge(

templates/path.epp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<%- | Array[String] $paths,
2+
| -%>
3+
<%= join($paths, ':') %>

0 commit comments

Comments
 (0)