Skip to content

Commit

Permalink
Merge pull request #34 from slmagus/master
Browse files Browse the repository at this point in the history
allow build_dir and cache_dir to be managed
  • Loading branch information
LongLiveCHIEF committed Jan 26, 2019
2 parents 0192319 + 14a6d03 commit 3029b6e
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 1 deletion.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ gitlab_ci_runner::concurrent: 4

gitlab_ci_runner::metrics_server: "localhost:8888"

gitlab_ci_runner::manage_docker: true
gitlab_ci_runner::manage_docker: true

gitlab_ci_runner::runners:
test_runner1:{}
test_runner2:{}
Expand All @@ -41,6 +44,8 @@ gitlab_ci_runner::runner_defaults:
registration-token: "1234567890abcdef"
executor: "docker"
docker-image: "ubuntu:trusty"
builds_dir: "/tmp"
cache_dir: "/tmp"
```

To unregister a specific runner you may use `ensure` param:
Expand Down
20 changes: 20 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
Hash $runners,
Hash $runner_defaults,
Optional[Integer] $concurrent = undef,
Optional[String] $builds_dir = undef,
Optional[String] $cache_dir = undef,
Optional[Pattern[/.*:.+/]] $metrics_server = undef,
Boolean $manage_docker = true,
Boolean $manage_repo = true,
Expand Down Expand Up @@ -117,6 +119,24 @@
notify => Exec['gitlab-runner-restart'],
}
}
if $builds_dir {
file_line { 'gitlab-runner-builds_dir':
path => '/etc/gitlab-runner/config.toml',
line => "builds_dir = \"${builds_dir}\"",
match => '^builds_dir = .+',
require => Package[$package_name],
notify => Exec['gitlab-runner-restart'],
}
}
if $cache_dir {
file_line { 'gitlab-runner-cache_dir':
path => '/etc/gitlab-runner/config.toml',
line => "cache_dir = \"${cache_dir}\"",
match => '^cache_dir = .+',
require => Package[$package_name],
notify => Exec['gitlab-runner-restart'],
}
}

exec { 'gitlab-runner-restart':
command => "/usr/bin/${package_name} restart",
Expand Down
3 changes: 2 additions & 1 deletion manifests/runner.pp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@

# Convert configuration into a string
$parameters_array = join_keys_to_values($_config, '=')
$parameters_array_dashes = prefix($parameters_array, '--')
$parameters_array_no_underscores = regsubst($parameters_array, '_', '-', 'G')
$parameters_array_dashes = prefix($parameters_array_no_underscores, '--')
$parameters_string = join($parameters_array_dashes, ' ')

$runner_name = $_config['name']
Expand Down
36 changes: 36 additions & 0 deletions spec/classes/gitlab_ci_runner_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
it { is_expected.to contain_gitlab_ci_runner__runner('test_runner').that_requires('Exec[gitlab-runner-restart]') }
it { is_expected.not_to contain_file_line('gitlab-runner-concurrent') }
it { is_expected.not_to contain_file_line('gitlab-runner-metrics-server') }
it { is_expected.not_to contain_file_line('gitlab-runner-builds_dir') }
it { is_expected.not_to contain_file_line('gitlab-runner-cache_dir') }

context 'with concurrent => 10' do
let(:params) do
Expand Down Expand Up @@ -68,6 +70,40 @@
'match' => '^metrics_server = .+')
end
end
context 'with builds_dir => /tmp/builds_dir' do
let(:params) do
{
'runner_defaults' => {},
'runners' => {},
'builds_dir' => '/tmp/builds_dir'
}
end

it { is_expected.to contain_file_line('gitlab-runner-builds_dir').that_requires("Package[#{package_name}]") }
it { is_expected.to contain_file_line('gitlab-runner-builds_dir').that_notifies('Exec[gitlab-runner-restart]') }
it do
is_expected.to contain_file_line('gitlab-runner-builds_dir').with('path' => '/etc/gitlab-runner/config.toml',
'line' => 'builds_dir = "/tmp/builds_dir"',
'match' => '^builds_dir = .+')
end
end
context 'with cache_dir => /tmp/cache_dir' do
let(:params) do
{
'runner_defaults' => {},
'runners' => {},
'cache_dir' => '/tmp/cache_dir'
}
end

it { is_expected.to contain_file_line('gitlab-runner-cache_dir').that_requires("Package[#{package_name}]") }
it { is_expected.to contain_file_line('gitlab-runner-cache_dir').that_notifies('Exec[gitlab-runner-restart]') }
it do
is_expected.to contain_file_line('gitlab-runner-cache_dir').with('path' => '/etc/gitlab-runner/config.toml',
'line' => 'cache_dir = "/tmp/cache_dir"',
'match' => '^cache_dir = .+')
end
end
end
end
end

0 comments on commit 3029b6e

Please sign in to comment.