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

Commit 1792de2

Browse files
committed
Add proxy support in github runner instance
Proxy settings can be defined per instance and also globally for all instances through the class parameters in init.pp Added tests about proxy settings in systemd unit
1 parent a127851 commit 1792de2

File tree

5 files changed

+147
-1
lines changed

5 files changed

+147
-1
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,26 @@ github_actions_runner::instances:
6060
personal_access_token: other_secret
6161
```
6262
63+
In case you need to set proxy in one instance:
64+
```yaml
65+
github_actions_runner::ensure: present
66+
github_actions_runner::base_dir_name: '/data/actions-runner'
67+
github_actions_runner::package_name: 'actions-runner-linux-x64'
68+
github_actions_runner::package_ensure: '2.272.0'
69+
github_actions_runner::repository_url: 'https://github.com/actions/runner/releases/download'
70+
github_actions_runner::org_name: 'github_org'
71+
github_actions_runner::personal_access_token: 'PAT'
72+
github_actions_runner::user: 'root'
73+
github_actions_runner::group: 'root'
74+
github_actions_runner::instances:
75+
first_instance:
76+
use_proxy: true
77+
http_proxy: http://proxy.local
78+
https_proxy: http://proxy.local
79+
no_proxy: example.com
80+
labels:
81+
- self-hosted-custom1
82+
```
6383
6484
## Limitations
6585

manifests/init.pp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@
3434
# * group
3535
# String, Group to be used in Service and directories.
3636
#
37+
# * instances
38+
# Hash[String, Hash], Github Runner Instances to be managed.
39+
#
40+
# * http_proxy
41+
# Optional[String], Proxy URL for HTTP traffic. More information at https://docs.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners.
42+
#
43+
# * https_proxy
44+
# Optional[String], Proxy URL for HTTPS traffic. More information at https://docs.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners
45+
#
46+
# * no_proxy
47+
# Optional[String], Comma separated list of hosts that shoudl 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
48+
#
3749

3850
class github_actions_runner (
3951
Enum['present', 'absent'] $ensure,
@@ -46,6 +58,9 @@
4658
String $user,
4759
String $group,
4860
Hash[String, Hash] $instances,
61+
Optional[String] $http_proxy = undef,
62+
Optional[String] $https_proxy = undef,
63+
Optional[String] $no_proxy = undef,
4964
) {
5065

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

manifests/instance.pp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@
2323
# * instance_name
2424
# String, The instance name as part of the instances Hash.
2525
#
26+
# * http_proxy
27+
# Optional[String], Proxy URL for HTTP traffic. More information at https://docs.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners.
28+
#
29+
# * https_proxy
30+
# Optional[String], Proxy URL for HTTPS traffic. More information at https://docs.github.com/en/actions/hosting-your-own-runners/using-a-proxy-server-with-self-hosted-runners
31+
#
32+
# * no_proxy
33+
# Optional[String], Comma separated list of hosts that shoudl 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
34+
#
2635
# * repo_name
2736
# Optional[String], actions runner repository name.
2837
#
@@ -38,6 +47,9 @@
3847
String $group = $github_actions_runner::group,
3948
String $hostname = $::facts['hostname'],
4049
String $instance_name = $title,
50+
Optional[String] $http_proxy = $github_actions_runner::http_proxy,
51+
Optional[String] $https_proxy = $github_actions_runner::https_proxy,
52+
Optional[String] $no_proxy = $github_actions_runner::no_proxy,
4153
Optional[Array[String]] $labels = undef,
4254
Optional[String] $repo_name = undef,
4355

@@ -110,7 +122,7 @@
110122

111123
exec { "${instance_name}-ownership":
112124
user => $user,
113-
cwd => "${github_actions_runner::root_dir}",
125+
cwd => $github_actions_runner::root_dir,
114126
command => "/bin/chown -R ${user}:${group} ${github_actions_runner::root_dir}/${instance_name}",
115127
refreshonly => true,
116128
path => "/tmp/${instance_name}-${archive_name}",
@@ -131,6 +143,9 @@
131143
root_dir => $github_actions_runner::root_dir,
132144
user => $user,
133145
group => $group,
146+
http_proxy => $http_proxy,
147+
https_proxy => $https_proxy,
148+
no_proxy => $no_proxy,
134149
}),
135150
require => [File["${github_actions_runner::root_dir}/${instance_name}/configure_install_runner.sh"],
136151
Exec["${instance_name}-run_configure_install_runner.sh"]],

spec/classes/github_actions_runner_spec.rb

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,90 @@
194194
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(/authorization: token test_PAT/)
195195
end
196196
end
197+
198+
context 'is expected to create a github_actions_runner installation with proxy settings in systemd globally in init.pp' do
199+
let(:params) do
200+
super().merge(
201+
'http_proxy' => 'http://proxy.local',
202+
'https_proxy' => 'http://proxy.local',
203+
'no_proxy' => 'example.com',
204+
'instances' => {
205+
'first_runner' => {
206+
'labels' => ['test_label1'],
207+
'repo_name' => 'test_repo',
208+
},
209+
},
210+
)
211+
end
212+
213+
it do
214+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="http_proxy=http://proxy.local"})
215+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="https_proxy=http://proxy.local"})
216+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="no_proxy=example.com"})
217+
end
218+
end
219+
220+
context 'is expected to create a github_actions_runner installation with proxy settings in systemd globally in init.pp overwriting in a instance' do
221+
let(:params) do
222+
super().merge(
223+
'http_proxy' => 'http://proxy.local',
224+
'https_proxy' => 'http://proxy.local',
225+
'no_proxy' => 'example.com',
226+
'instances' => {
227+
'first_runner' => {
228+
'labels' => ['test_label1'],
229+
'repo_name' => 'test_repo',
230+
'http_proxy' => 'http://newproxy.local',
231+
},
232+
},
233+
)
234+
end
235+
236+
it do
237+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="http_proxy=http://newproxy.local"})
238+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="https_proxy=http://proxy.local"})
239+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="no_proxy=example.com"})
240+
end
241+
end
242+
243+
context 'is expected to create a github_actions_runner installation with proxy settings in systemd' do
244+
let(:params) do
245+
super().merge(
246+
'instances' => {
247+
'first_runner' => {
248+
'labels' => ['test_label1'],
249+
'repo_name' => 'test_repo',
250+
'http_proxy' => 'http://proxy.local',
251+
'https_proxy' => 'http://proxy.local',
252+
'no_proxy' => 'example.com'},
253+
},
254+
)
255+
end
256+
257+
it do
258+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="http_proxy=http://proxy.local"})
259+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="https_proxy=http://proxy.local"})
260+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').with_content(%r{Environment="no_proxy=example.com"})
261+
end
262+
end
263+
264+
context 'is expected to create a github_actions_runner installation without proxy settings in systemd' do
265+
let(:params) do
266+
super().merge(
267+
'instances' => {
268+
'first_runner' => {
269+
'labels' => ['test_label1'],
270+
'repo_name' => 'test_repo'},
271+
},
272+
)
273+
end
274+
275+
it do
276+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').without_content(%r{Environment="http_proxy=http://proxy.local"})
277+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').without_content(%r{Environment="https_proxy=http://proxy.local"})
278+
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').without_content(%r{Environment="no_proxy=example.com"})
279+
end
280+
end
197281
end
198282
end
199283
end

templates/github-actions-runner.service.epp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,24 @@
22
Stdlib::Absolutepath $root_dir,
33
String $user,
44
String $group,
5+
Optional[String] $http_proxy = undef,
6+
Optional[String] $https_proxy = undef,
7+
Optional[String] $no_proxy = undef
58
| -%>
69
[Unit]
710
Description=github-actions-runner-<%= $instance_name %>
811
After=network.target
912

1013
[Service]
14+
<% if $http_proxy { -%>
15+
Environment="http_proxy=<%= $http_proxy %>"
16+
<% } -%>
17+
<% if $https_proxy { -%>
18+
Environment="https_proxy=<%= $https_proxy %>"
19+
<% } -%>
20+
<% if $no_proxy { -%>
21+
Environment="no_proxy=<%= $no_proxy %>"
22+
<% } -%>
1123
ExecStart=<%= $root_dir %>/<%= $instance_name %>/runsvc.sh
1224
WorkingDirectory=<%= $root_dir %>/<%= $instance_name %>
1325
KillMode=process

0 commit comments

Comments
 (0)