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

Commit 3d51c0f

Browse files
authored
Merge pull request #16 from Telefonica/mrodm_add_self_hosted_support
2 parents 04dad83 + dc1b86c commit 3d51c0f

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,12 @@ github_actions_runner::instances:
8080
- self-hosted-custom1
8181
```
8282
83+
In case you are using Github Enterprise Server , you can define these two parameters to specify the correct urls:
84+
```yaml
85+
github_actions_runner::github_domain: "https://git.example.com"
86+
github_actions_runner::github_api: "https://git.example.com/api/v3"
87+
```
88+
8389
## Limitations
8490
8591
Tested on Debian 9 stretch hosts only.

data/common.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ github_actions_runner::personal_access_token: 'PAT'
99
github_actions_runner::user: 'root'
1010
github_actions_runner::group: 'root'
1111
github_actions_runner::instances: {}
12-
12+
github_actions_runner::github_domain: "https://github.com"
13+
github_actions_runner::github_api: "https://api.github.com"

manifests/init.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
# * instances
3838
# Hash[String, Hash], Github Runner Instances to be managed.
3939
#
40+
# * github_domain
41+
# String, Base URL for Github Domain.
42+
#
43+
# * github_api
44+
# String, Base URL for Github API.
45+
#
4046
# * http_proxy
4147
# 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.
4248
#
@@ -58,6 +64,8 @@
5864
String $user,
5965
String $group,
6066
Hash[String, Hash] $instances,
67+
String $github_domain,
68+
String $github_api,
6169
Optional[String] $http_proxy = undef,
6270
Optional[String] $https_proxy = undef,
6371
Optional[String] $no_proxy = undef,

manifests/instance.pp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,8 @@
5252
Optional[String] $no_proxy = $github_actions_runner::no_proxy,
5353
Optional[Array[String]] $labels = undef,
5454
Optional[String] $repo_name = undef,
55-
55+
String $github_domain = $github_actions_runner::github_domain,
56+
String $github_api = $github_actions_runner::github_api,
5657
) {
5758

5859
if $labels {
@@ -63,13 +64,17 @@
6364
}
6465

6566
$url = $repo_name ? {
66-
undef => "https://github.com/${org_name}",
67-
default => "https://github.com/${org_name}/${repo_name}",
67+
undef => "${github_domain}/${org_name}",
68+
default => "${github_domain}/${org_name}/${repo_name}",
6869
}
6970

70-
$token_url = $repo_name ? {
71-
undef => "https://api.github.com/repos/${org_name}/actions/runners/registration-token",
72-
default => "https://api.github.com/repos/${org_name}/${repo_name}/actions/runners/registration-token",
71+
if $repo_name {
72+
$token_url = "${github_api}/repos/${org_name}/${repo_name}/actions/runners/registration-token"
73+
} else {
74+
$token_url = $github_api ? {
75+
'https://api.github.com' => "${github_api}/repos/${org_name}/actions/runners/registration-token",
76+
default => "${github_api}/orgs/${org_name}/actions/runners/registration-token",
77+
}
7378
}
7479

7580
$archive_name = "${github_actions_runner::package_name}-${github_actions_runner::package_ensure}.tar.gz"

spec/classes/github_actions_runner_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,52 @@
293293
is_expected.to contain_systemd__unit_file('github-actions-runner.first_runner.service').without_content(%r{Environment="no_proxy=example.com"})
294294
end
295295
end
296+
297+
context 'is expected to create a github_actions_runner installation with another URLs for domain and API' do
298+
let(:params) do
299+
super().merge(
300+
'github_domain' => 'https://git.example.com',
301+
'github_api' => 'https://git.example.com/api/v3',
302+
'instances' => {
303+
'first_runner' => {
304+
'labels' => ['test_label1'],
305+
'repo_name' => 'test_repo',
306+
},
307+
},
308+
)
309+
end
310+
311+
it do
312+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--url https://git.example.com})
313+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{https://git.example.com/api/v3.* \| jq -r .token})
314+
end
315+
end
316+
317+
context 'is expected to create a github_actions_runner installation with another URLs for domain and API per instance' do
318+
let(:params) do
319+
super().merge(
320+
'instances' => {
321+
'first_runner' => {
322+
'labels' => ['test_label1'],
323+
'repo_name' => 'test_repo',
324+
},
325+
'second_runner' => {
326+
'labels' => ['test_label1'],
327+
'repo_name' => 'test_repo',
328+
'github_domain' => 'https://git.example.foo',
329+
'github_api' => 'https://git.example.foo/api/v2',
330+
},
331+
},
332+
)
333+
end
334+
335+
it do
336+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{--url https://github.com})
337+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/first_runner/configure_install_runner.sh').with_content(%r{https://api.github.com/.* \| jq -r .token})
338+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/second_runner/configure_install_runner.sh').with_content(%r{--url https://git.example.foo})
339+
is_expected.to contain_file('/some_dir/actions-runner-2.272.0/second_runner/configure_install_runner.sh').with_content(%r{https://git.example.foo/api/v2/.* \| jq -r .token})
340+
end
341+
end
296342
end
297343
end
298344
end

0 commit comments

Comments
 (0)