From a89c460e0f630d778513a3b07a33f150b79d2aae Mon Sep 17 00:00:00 2001 From: Jeoffrey Bauvin Date: Tue, 27 Oct 2015 09:27:30 +0100 Subject: Add runner --- manifests/config.pp | 14 ++++- manifests/init.pp | 1 + manifests/install.pp | 1 + manifests/params.pp | 1 + manifests/repo/apt.pp | 2 + manifests/runner.pp | 47 +++++++++++++++ templates/fragment_header_config.toml.erb | 3 + templates/fragment_runner_config.toml.erb | 95 +++++++++++++++++++++++++++++++ 8 files changed, 161 insertions(+), 3 deletions(-) create mode 100644 manifests/runner.pp create mode 100644 templates/fragment_header_config.toml.erb create mode 100644 templates/fragment_runner_config.toml.erb diff --git a/manifests/config.pp b/manifests/config.pp index 65b0932..5cf7525 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -4,14 +4,22 @@ # class gitlab_ci_multi_runner::config ( $concurrent = $gitlab_ci_multi_runner::concurrent, + $runners = $gitlab_ci_multi_runner::runners, ) { - - file { $::gitlab_ci_multi_runner::config_file: + + concat { $::gitlab_ci_multi_runner::config_file: ensure => present, owner => $::gitlab_ci_multi_runner::user, group => $::gitlab_ci_multi_runner::group, - content => template('gitlab_ci_multi_runner/config.toml.erb'), require => Package[$gitlab_ci_multi_runner::package_name], notify => Service[$gitlab_ci_multi_runner::service_name], } + + concat::fragment { "header_$::gitlab_ci_multi_runner::config_file": + target => $::gitlab_ci_multi_runner::config_file, + content => template('gitlab_ci_multi_runner/fragment_header_config.toml.erb'), + order => '01', + } + + create_resources(gitlab_ci_multi_runner::runner, $runners) } diff --git a/manifests/init.pp b/manifests/init.pp index 9842027..77dcf73 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -23,6 +23,7 @@ class gitlab_ci_multi_runner ( $user = $gitlab_ci_multi_runner::params::user, $group = $gitlab_ci_multi_runner::params::group, $concurrent = $gitlab_ci_multi_runner::params::concurrent, + $runners = $gitlab_ci_multi_runner::params::runners, ) inherits gitlab_ci_multi_runner::params { # validate parameters here diff --git a/manifests/install.pp b/manifests/install.pp index 998f7fb..128b5a1 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -11,5 +11,6 @@ class gitlab_ci_multi_runner::install { package { $gitlab_ci_multi_runner::package_name: ensure => present, + tag => 'gitlab-ci-multi-runner', } } diff --git a/manifests/params.pp b/manifests/params.pp index 4f25f62..8913977 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -11,6 +11,7 @@ class gitlab_ci_multi_runner::params { $group = 'gitlab-runner' $concurrent = 1 + $runnners = undef case $::osfamily { 'Debian': { diff --git a/manifests/repo/apt.pp b/manifests/repo/apt.pp index 123d06d..af7b073 100644 --- a/manifests/repo/apt.pp +++ b/manifests/repo/apt.pp @@ -19,4 +19,6 @@ class gitlab_ci_multi_runner::repo::apt { 'deb' => true, }, } + + Apt::Source['gitlab-ci-multi-runner']->Package<|tag == 'gitlab-ci-multi-runner'|> } \ No newline at end of file diff --git a/manifests/runner.pp b/manifests/runner.pp new file mode 100644 index 0000000..f14cd06 --- /dev/null +++ b/manifests/runner.pp @@ -0,0 +1,47 @@ +# == Class gitlab_ci_multi_runner::runner +# +# Class for creating runners in multi-runner's config file. +# +# [*url*] - CI URL +# Defaults to http://gitlab.example.com +# [*token*] - runner token +# Defaults to 'XXXX' +# [*limit*] - limit how many jobs can be handled concurrently by this token. 0 simply means don't limit +# Defaults to undef +# [*shell*] - the name of shell to generate the script (default value is platform dependent) (bash, cmd, powershell) +# Defaults to undef +# [*executor*] - select how a project should be built (shell, docker, docker-ssh, ssh, parallels) +# Defaults to shell +# [*builds_dir*] - directory where builds will be stored in context of selected executor (Locally, Docker, SSH) +# Defaults to undef +# [*environment*] - append or overwrite environment variables +# Defaults to undef +# [*disable_verbose*] - don't print run commands +# Defaults to undef +# [*output_limit*] - set maximum build log size in kilobytes, by default set to 4096 (4MB) +# Defaults to undef +# [*docker_params*] - Docker params (image, allowed_images, allowed_services, volumes, ...). Need executor_docker to true. +# Defaults to undef +# [*config_file*] - Path for Gitlab Multi Runner config file +# Default value in params. +define gitlab_ci_multi_runner::runner ( + $url = 'http://gitlab.example.com', + $token = 'XXXX', + $limit = undef, + $shell = undef, + $executor = 'shell', + $builds_dir = undef, + $environment = undef, + $disable_verbose = undef, + $output_limit = undef, + $docker_params = undef, + $parallels_params = undef, + $config_file = $gitlab_ci_multi_runner::params::config_file, +){ + + concat::fragment { "${name}_$::gitlab_ci_multi_runner::config_file": + target => $::gitlab_ci_multi_runner::config_file, + content => template('gitlab_ci_multi_runner/fragment_runner_config.toml.erb'), + } + +} \ No newline at end of file diff --git a/templates/fragment_header_config.toml.erb b/templates/fragment_header_config.toml.erb new file mode 100644 index 0000000..73309a9 --- /dev/null +++ b/templates/fragment_header_config.toml.erb @@ -0,0 +1,3 @@ +# This file is managed by Puppet + +concurrent = <%= @concurrent %> diff --git a/templates/fragment_runner_config.toml.erb b/templates/fragment_runner_config.toml.erb new file mode 100644 index 0000000..a9c3ca3 --- /dev/null +++ b/templates/fragment_runner_config.toml.erb @@ -0,0 +1,95 @@ + +[[runners]] + name = "<%= @name %>" + executor = "<%= @executor %>" +<% if @url -%> + url = "<%= @url %>" +<% end -%> +<% if @token -%> + token = "<%= @token %>" +<% end -%> +<% if @limit -%> + limit = <%= @limit %> +<% end -%> +<% if @shell -%> + shell = "<%= @shell %>" +<% end -%> +<% if @builds_dir -%> + builds_dir = "<%= @builds_dir %>" +<% end -%> +<% if @environment -%> + environment = <%= @environment %> +<% end -%> +<% if @disable_verbose -%> + disable_verbose = <%= @disable_verbose %> +<% end -%> +<% if @output_limit -%> + output_limit = <%= @output_limit %> +<% end -%> +<% if executor == 'docker' -%> + [runners.docker] + <%- if @docker_params['host'] -%> + host = "<%= @docker_params['host'] %>" + <%- end -%> + <%- if @docker_params['hostname'] -%> + hostname = "<%= @docker_params['hostname'] %>" + <%- end -%> + <%- if @docker_params['tls_cert_path'] -%> + tls_cert_path = "<%= @docker_params['tls_cert_path'] %>" + <%- end -%> + <%- if @docker_params['disable_cache'] -%> + disable_cache = <%= @disable_cache %> + <%- end -%> + <%- if @docker_params['wait_for_services_timeout'] -%> + wait_for_services_timeout = <%= @wait_for_services_timeout %> + <%- end -%> + <%- if @docker_params['cache_dir'] -%> + cache_dir = "<%= @cache_dir %>" + <%- end -%> + <%- if @docker_params['extra_hosts'] -%> + extra_hosts = <%= @extra_hosts %> + <%- end -%> + <%- if @docker_params['links'] -%> + links = <%= @links %> + <%- end -%> + <%- if @docker_params['services'] -%> + services = <%= @services %> + <%- end -%> + <%- if @docker_params['image'] -%> + image = "<%= @docker_params['image'] %>" + <%- end -%> + allowed_images = <%= @docker_params['allowed_images'] %> + allowed_services = <%= @docker_params['allowed_services'] %> + privileged = <%= @docker_params['privileged'] %> + volumes = <%= @docker_params['volumes'] %> +<% end -%> +<% if executor == 'parallels' -%> + [runners.parallels] + <%- if @parallels_params['base_name'] -%> + base_name = "<%= @docker_params['base_name'] %>" + <%- end -%> + <%- if @parallels_params['template_name'] -%> + template_name = "<%= @parallels_params['template_name'] %>" + <%- end -%> + <%- if @parallels_params['disable_snapshots'] -%> + disable_snapshots = <%= @parallels_params['disable_snapshots'] %> + <%- end -%> +<%- end -%> +<% if executor == 'ssh' -%> + [runners.ssh] + <%- if @ssh_params['host'] -%> + host = "<%= @ssh_params['host'] %>" + <%- end -%> + <%- if @ssh_params['port'] -%> + port = "<%= @ssh_params['port'] %>" + <%- end -%> + <%- if @ssh_params['user'] -%> + user = "<%= @ssh_params['user'] %>" + <%- end -%> + <%- if @ssh_params['password'] -%> + password = "<%= @ssh_params['password'] %>" + <%- end -%> + <%- if @ssh_params['identity_file'] -%> + identity_file = "<%= @ssh_params['identity_file'] %>" + <%- end -%> +<% end -%> \ No newline at end of file -- cgit v1.2.3