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

Commit 2ec1195

Browse files
committed
Manage PATH in instance runner
Notify changes to Systemd::Unit_file so the service is restarted to take the values of the new PATH
1 parent 1466c20 commit 2ec1195

File tree

5 files changed

+102
-0
lines changed

5 files changed

+102
-0
lines changed

data/common.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ github_actions_runner::group: 'root'
1010
github_actions_runner::instances: {}
1111
github_actions_runner::github_domain: "https://github.com"
1212
github_actions_runner::github_api: "https://api.github.com"
13+
github_actions_runner::path:
14+
- '/usr/local/bin'
15+
- '/usr/bin'
16+
- '/bin'

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.
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,
7579
) {
7680

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

manifests/instance.pp

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
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.
46+
#
4447
define github_actions_runner::instance (
4548
Enum['present', 'absent'] $ensure = 'present',
4649
String[1] $personal_access_token = $github_actions_runner::personal_access_token,
@@ -57,6 +60,7 @@
5760
Optional[String[1]] $enterprise_name = $github_actions_runner::enterprise_name,
5861
Optional[String[1]] $org_name = $github_actions_runner::org_name,
5962
Optional[String[1]] $repo_name = undef,
63+
Optional[Array[String]] $path = $github_actions_runner::path,
6064
) {
6165

6266
if $labels {
@@ -159,6 +163,20 @@
159163
onlyif => "test -d ${github_actions_runner::root_dir}/${instance_name}"
160164
}
161165

166+
file { "${github_actions_runner::root_dir}/${name}/.path":
167+
ensure => $ensure,
168+
mode => '0644',
169+
owner => $user,
170+
group => $group,
171+
content => epp('github_actions_runner/path.epp', {
172+
paths => $path,
173+
}),
174+
require => [Archive["${instance_name}-${archive_name}"],
175+
Exec["${instance_name}-run_configure_install_runner.sh"],
176+
],
177+
notify => Systemd::Unit_file["github-actions-runner.${instance_name}.service"]
178+
}
179+
162180
$active_service = $ensure ? {
163181
'present' => true,
164182
'absent' => false,
@@ -183,6 +201,7 @@
183201
no_proxy => $no_proxy,
184202
}),
185203
require => [File["${github_actions_runner::root_dir}/${instance_name}/configure_install_runner.sh"],
204+
File["${github_actions_runner::root_dir}/${instance_name}/.path"],
186205
Exec["${instance_name}-run_configure_install_runner.sh"]],
187206
}
188207

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' => '0755',
368+
'content' => "/usr/local/bin:/usr/bin:/bin\n",
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' => '0755',
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' => '0755',
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)