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

Commit bbc1f4c

Browse files
authored
Merge pull request #40 from Telefonica/add_env_support
2 parents af60a05 + de74c03 commit bbc1f4c

File tree

4 files changed

+145
-37
lines changed

4 files changed

+145
-37
lines changed

manifests/init.pp

Lines changed: 25 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,26 +56,33 @@
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
#
5858
# * 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
59+
# Optional[Array[String]], List of paths to be used as PATH env in the instance runner.
60+
# If not defined, file ".path" will be kept as created by the runner scripts. Default value: undef
61+
#
62+
# * env
63+
# Optional[Hash[String, String]], List of variables to be used as env variables in the instance runner.
64+
# If not defined, file ".env" will be kept as created
65+
# by the runner scripts. (Default: Value set by github_actions_runner Class)
6066
#
6167
class github_actions_runner (
62-
Enum['present', 'absent'] $ensure,
63-
Stdlib::Absolutepath $base_dir_name,
64-
String[1] $personal_access_token,
65-
String[1] $package_name,
66-
String[1] $package_ensure,
67-
String[1] $repository_url,
68-
String[1] $user,
69-
String[1] $group,
70-
Hash[String[1], Hash] $instances,
71-
String[1] $github_domain,
72-
String[1] $github_api,
73-
Optional[String[1]] $enterprise_name = undef,
74-
Optional[String[1]] $org_name = undef,
75-
Optional[String[1]] $http_proxy = undef,
76-
Optional[String[1]] $https_proxy = undef,
77-
Optional[String[1]] $no_proxy = undef,
78-
Optional[Array[String]] $path = undef,
68+
Enum['present', 'absent'] $ensure,
69+
Stdlib::Absolutepath $base_dir_name,
70+
String[1] $personal_access_token,
71+
String[1] $package_name,
72+
String[1] $package_ensure,
73+
String[1] $repository_url,
74+
String[1] $user,
75+
String[1] $group,
76+
Hash[String[1], Hash] $instances,
77+
String[1] $github_domain,
78+
String[1] $github_api,
79+
Optional[String[1]] $enterprise_name = undef,
80+
Optional[String[1]] $org_name = undef,
81+
Optional[String[1]] $http_proxy = undef,
82+
Optional[String[1]] $https_proxy = undef,
83+
Optional[String[1]] $no_proxy = undef,
84+
Optional[Array[String]] $path = undef,
85+
Optional[Hash[String, String]] $env = undef,
7986
) {
8087

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

manifests/instance.pp

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,26 +42,32 @@
4242
# Optional[Array[String]], A list of costum lables to add to a runner.
4343
#
4444
# * 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
45+
# Optional[Array[String]], List of paths to be used as PATH env in the instance runner. If not defined, file ".path" will be kept as created
4646
# by the runner scripts. (Default: Value set by github_actions_runner Class)
4747
#
48+
# * env
49+
# Optional[Hash[String, String]], List of variables to be used as env variables in the instance runner.
50+
# If not defined, file ".env" will be kept as created
51+
# by the runner scripts. (Default: Value set by github_actions_runner Class)
52+
#
4853
define github_actions_runner::instance (
49-
Enum['present', 'absent'] $ensure = 'present',
50-
String[1] $personal_access_token = $github_actions_runner::personal_access_token,
51-
String[1] $user = $github_actions_runner::user,
52-
String[1] $group = $github_actions_runner::group,
53-
String[1] $hostname = $::facts['hostname'],
54-
String[1] $instance_name = $title,
55-
String[1] $github_domain = $github_actions_runner::github_domain,
56-
String[1] $github_api = $github_actions_runner::github_api,
57-
Optional[String[1]] $http_proxy = $github_actions_runner::http_proxy,
58-
Optional[String[1]] $https_proxy = $github_actions_runner::https_proxy,
59-
Optional[String[1]] $no_proxy = $github_actions_runner::no_proxy,
60-
Optional[Array[String[1]]] $labels = undef,
61-
Optional[String[1]] $enterprise_name = $github_actions_runner::enterprise_name,
62-
Optional[String[1]] $org_name = $github_actions_runner::org_name,
63-
Optional[String[1]] $repo_name = undef,
64-
Optional[Array[String]] $path = $github_actions_runner::path,
54+
Enum['present', 'absent'] $ensure = 'present',
55+
String[1] $personal_access_token = $github_actions_runner::personal_access_token,
56+
String[1] $user = $github_actions_runner::user,
57+
String[1] $group = $github_actions_runner::group,
58+
String[1] $hostname = $::facts['hostname'],
59+
String[1] $instance_name = $title,
60+
String[1] $github_domain = $github_actions_runner::github_domain,
61+
String[1] $github_api = $github_actions_runner::github_api,
62+
Optional[String[1]] $http_proxy = $github_actions_runner::http_proxy,
63+
Optional[String[1]] $https_proxy = $github_actions_runner::https_proxy,
64+
Optional[String[1]] $no_proxy = $github_actions_runner::no_proxy,
65+
Optional[Array[String[1]]] $labels = undef,
66+
Optional[String[1]] $enterprise_name = $github_actions_runner::enterprise_name,
67+
Optional[String[1]] $org_name = $github_actions_runner::org_name,
68+
Optional[String[1]] $repo_name = undef,
69+
Optional[Array[String]] $path = $github_actions_runner::path,
70+
Optional[Hash[String, String]] $env = $github_actions_runner::env,
6571
) {
6672

6773
if $labels {
@@ -183,6 +189,25 @@
183189
notify => Systemd::Unit_file["github-actions-runner.${instance_name}.service"]
184190
}
185191

192+
$content_env = $env ? {
193+
undef => undef,
194+
default => epp('github_actions_runner/env.epp', {
195+
envs => $env,
196+
})
197+
}
198+
199+
file { "${github_actions_runner::root_dir}/${name}/.env":
200+
ensure => $ensure,
201+
mode => '0644',
202+
owner => $user,
203+
group => $group,
204+
content => $content_env,
205+
require => [Archive["${instance_name}-${archive_name}"],
206+
Exec["${instance_name}-run_configure_install_runner.sh"],
207+
],
208+
notify => Systemd::Unit_file["github-actions-runner.${instance_name}.service"]
209+
}
210+
186211
$active_service = $ensure ? {
187212
'present' => true,
188213
'absent' => false,

spec/classes/github_actions_runner_spec.rb

Lines changed: 73 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@
370370
end
371371
end
372372

373-
context 'is expected to create a .path file in an instance setting path at global level' do
373+
context 'is expected to create a .path file in an instance, setting path at global level' do
374374
let(:params) do
375375
super().merge(
376376
'path' => [
@@ -391,7 +391,7 @@
391391
end
392392
end
393393

394-
context 'is expected to create a .path file in an instance setting the path at instance level' do
394+
context 'is expected to create a .path file in an instance, setting the path at instance level' do
395395
let(:params) do
396396
super().merge(
397397
'path' => [
@@ -420,6 +420,77 @@
420420
end
421421
end
422422

423+
# .env
424+
context 'is expected to create a .env file with a specific requires and notifies' do
425+
it do
426+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.env')
427+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.env').that_requires(['Archive[first_runner-actions-runner-linux-x64-2.272.0.tar.gz]',
428+
'Exec[first_runner-run_configure_install_runner.sh]'])
429+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.env').that_notifies('Systemd::Unit_file[github-actions-runner.first_runner.service]')
430+
end
431+
end
432+
433+
context 'is expected to create a .env file in an instance with default env hash (nil content)' do
434+
it do
435+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.env').with(
436+
'ensure' => 'present',
437+
'owner' => 'root',
438+
'group' => 'root',
439+
'mode' => '0644',
440+
'content' => nil,
441+
)
442+
end
443+
end
444+
445+
context 'is expected to create a .env file in an instance, setting env at global level' do
446+
let(:params) do
447+
super().merge(
448+
'env' => {
449+
'foo' => 'bar',
450+
'key' => 'value',
451+
},
452+
)
453+
end
454+
455+
it do
456+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.env').with(
457+
'ensure' => 'present',
458+
'owner' => 'root',
459+
'group' => 'root',
460+
'mode' => '0644',
461+
'content' => "foo=bar\nkey=value\n",
462+
)
463+
end
464+
end
465+
466+
context 'is expected to create a .env file in an instance, setting the env at instance level' do
467+
let(:params) do
468+
super().merge(
469+
'env' => {
470+
'foo' => 'bar',
471+
'key' => 'value',
472+
},
473+
'instances' => {
474+
'first_runner' => {
475+
'env' => {
476+
'other' => 'value',
477+
}
478+
},
479+
},
480+
)
481+
end
482+
483+
it do
484+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/.env').with(
485+
'ensure' => 'present',
486+
'owner' => 'root',
487+
'group' => 'root',
488+
'mode' => '0644',
489+
'content' => "other=value\n",
490+
)
491+
end
492+
end
493+
423494
context 'is expected to remove github_actions_runner unit_file and other resources' do
424495
let(:params) do
425496
super().merge(

templates/env.epp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%- | Hash[String, String] $envs,
2+
| -%>
3+
<%- $envs.each |$key, $value| { -%>
4+
<%= $key %>=<%= $value %>
5+
<%- } -%>

0 commit comments

Comments
 (0)