Skip to content

Commit

Permalink
Remove deprecated hiera functions - replace stdlib validation functio…
Browse files Browse the repository at this point in the history
…ns with puppet data types
  • Loading branch information
jkroepke committed Mar 8, 2018
1 parent e9d8d28 commit 81d7cc2
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 358 deletions.
2 changes: 1 addition & 1 deletion .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ fixtures:
repositories:
stdlib:
repo: "https://github.com/puppetlabs/puppetlabs-stdlib.git"
ref: "4.12.0"
ref: "4.14.0"
apt:
repo: "https://github.com/puppetlabs/puppetlabs-apt.git"
ref: "2.2.0"
Expand Down
16 changes: 2 additions & 14 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,14 +1,2 @@
FROM ruby:2.1-alpine
MAINTAINER Tobias Brunner <[email protected]>

ENV PUPPET_VERSION "~> 3.8.0"
RUN apk add --no-cache git bash alpine-sdk && \
adduser -S puppet && \
mkdir /home/puppet/gitlab && \
chown -R puppet /home/puppet

WORKDIR /home/puppet/gitlab
COPY Gemfile /home/puppet/gitlab

#USER puppet
RUN bundle install --without development system_tests
FROM sonarsource/local-travis
ADD . /home/travis
18 changes: 0 additions & 18 deletions lib/facter/gitlab_systemd.rb

This file was deleted.

52 changes: 19 additions & 33 deletions manifests/cirunner.pp
Original file line number Diff line number Diff line change
Expand Up @@ -34,27 +34,19 @@
# Copyright 2015 Tobias Brunner, VSHN AG
#
class gitlab::cirunner (
$concurrent = undef,
$metrics_server = undef,
$hiera_default_config_key = 'gitlab_ci_runners_defaults',
$hiera_runners_key = 'gitlab_ci_runners',
$manage_docker = true,
$manage_repo = true,
$xz_package_name = 'xz-utils',
$package_ensure = installed,
$package_name = 'gitlab-runner',
Optional[Integer] $concurrent = undef,
Optional[Pattern[/.*:.+/]] $metrics_server = undef,
String $hiera_default_config_key = 'gitlab_ci_runners_defaults',
String $hiera_runners_key = 'gitlab_ci_runners',
Boolean $manage_docker = true,
Boolean $manage_repo = true,
String $xz_package_name = 'xz-utils',
String $package_ensure = installed,
String $package_name = 'gitlab-runner',
) {

validate_string($hiera_default_config_key)
validate_string($hiera_runners_key)
validate_bool($manage_docker)
validate_bool($manage_repo)
validate_string($xz_package_name)
validate_string($package_ensure)
validate_string($package_name)

unless ($::osfamily == 'Debian' or $::osfamily == 'RedHat') {
fail ("OS family ${::osfamily} is not supported. Only Debian and Redhat is suppported.")
fail ("OS family ${::osfamily} is not supported. Only Debian and Redhat is supported.")
}

if $manage_docker {
Expand Down Expand Up @@ -82,12 +74,9 @@
include apt
ensure_packages('apt-transport-https')

$distid = downcase($::lsbdistid)

::apt::source { 'apt_gitlabci':
apt::source { 'apt_gitlabci':
comment => 'GitlabCI Runner Repo',
location => "${repo_base_url}/runner/${package_name}/${distid}/",
release => $::lsbdistcodename,
location => "${repo_base_url}/runner/${package_name}/${::lsbdistid.downcase}/",
repos => 'main',
key => {
'id' => '1A4C919DB987D435939638B914219A96E15E78F4',
Expand All @@ -104,7 +93,7 @@
'RedHat': {
yumrepo { "runner_${package_name}":
ensure => 'present',
baseurl => "${repo_base_url}/runner/${package_name}/el/${::operatingsystemmajrelease}/\$basearch",
baseurl => "${repo_base_url}/runner/${package_name}/el/\$releasever/\$basearch",
descr => "runner_${package_name}",
enabled => '1',
gpgcheck => '0',
Expand All @@ -116,7 +105,7 @@

yumrepo { "runner_${package_name}-source":
ensure => 'present',
baseurl => "${repo_base_url}/runner/${package_name}/el/${::operatingsystemmajrelease}/SRPMS",
baseurl => "${repo_base_url}/runner/${package_name}/el/\$releasever/SRPMS",
descr => "runner_${package_name}-source",
enabled => '1',
gpgcheck => '0',
Expand All @@ -136,9 +125,7 @@
ensure => $package_ensure,
}

if $concurrent {
validate_integer($concurrent, undef, 1)

if $concurrent != undef {
file_line { 'gitlab-runner-concurrent':
path => '/etc/gitlab-runner/config.toml',
line => "concurrent = ${concurrent}",
Expand All @@ -149,8 +136,6 @@
}

if $metrics_server {
validate_re($metrics_server, '.*:.+', 'metrics_server must be in the format [host]:<port>')

file_line { 'gitlab-runner-metrics-server':
path => '/etc/gitlab-runner/config.toml',
line => "metrics_server = \"${metrics_server}\"",
Expand All @@ -166,9 +151,10 @@
require => Package[$package_name],
}

$runners_hash = hiera_hash($hiera_runners_key, {})
$runners = keys($runners_hash)
$default_config = hiera_hash($hiera_default_config_key, {})
$runners_hash = lookup({'name' => $hiera_runners_key, 'value_type' => Hash, 'default_value' => {}})
$runners = $runners_hash.keys
$default_config = lookup({'name' => $hiera_default_config_key, 'value_type' => Hash, 'default_value' => {}})

gitlab::runner { $runners:
binary => $package_name,
default_config => $default_config,
Expand Down
27 changes: 9 additions & 18 deletions manifests/custom_hook.pp
Original file line number Diff line number Diff line change
Expand Up @@ -58,36 +58,27 @@
# Copyright 2014 Spencer Owen, unless otherwise noted.
#
define gitlab::custom_hook(
$namespace = undef,
$project = undef,
$type = undef,
$content = undef,
$source = undef,
$repos_path = undef,
String $namespace,
String $project,
Enum['update', 'post-receive', 'pre-receive'] $type,
Optional[String] $content = undef,
Optional[String] $source = undef,
Optional[Stdlib::Absolutepath] $repos_path = undef,
) {
validate_string($namespace)
validate_string($project)
validate_re($type, '^(post-receive|pre-receive|update)$')

if $repos_path {
$_repos_path = $repos_path
} elsif $::gitlab::git_data_dir {
$_repos_path = "${::gitlab::git_data_dir}/repositories"
} else {
$_repos_path = '/var/opt/gitlab/git-data/repositories'
}
validate_absolute_path($_repos_path)

if ! ($content) and ! ($source) {
fail('gitlab::custom_hook resource must specify either content or source')
fail("gitlab::custom_hook[${name}]: Must specify either content or source")
}

if ($content) and ($source) {
fail('gitlab::custom_hook resource must specify either content or source, but not both')
}

if $source {
validate_re($source, '^puppet:')
fail("gitlab::custom_hook[${name}]: Must specify either content or source, but not both")
}

$hook_path = "${_repos_path}/${namespace}/${project}.git/custom_hooks"
Expand All @@ -106,7 +97,7 @@
}

file { "${hook_path}/${type}":
ensure => 'present',
ensure => file,
content => $content,
source => $source,
}
Expand Down
Loading

0 comments on commit 81d7cc2

Please sign in to comment.