Skip to content

Commit

Permalink
Fixes #35943 - Switch to puppetlabs vcsrepo for gitrepo tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
jcpunk committed Jan 13, 2023
1 parent 36da0e1 commit 0cf1850
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 26 deletions.
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ fixtures:
puppetserver_foreman: 'https://github.com/theforeman/puppet-puppetserver_foreman.git'
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
systemd: 'https://github.com/voxpupuli/puppet-systemd.git'
vcsrepo: 'https://github.com/puppetlabs/puppetlabs-vcsrepo.git'
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,10 @@ sets up `/var/lib/puppet/puppet.git` where each branch maps to one environment.
Avoid using 'master' as this name isn't permitted. On each push to the repo, a
hook updates `/etc/puppet/environments` with the contents of the branch.

Requires [theforeman/git](https://forge.puppetlabs.com/theforeman/git).
Permissions can be controlled via the `git_repo_{user,group,hook_mode,umask}`
parameters.

Requires [puppetlabs/vcsrepo](https://forge.puppetlabs.com/puppetlabs/vcsrepo).

## Foreman integration

Expand Down
9 changes: 6 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,11 @@
#
# $server_common_modules_path:: Common modules paths
#
# $server_git_repo_path:: Git repository path
# $server_git_repo_path:: Git repository path on disk
#
# $server_git_repo_mode:: Git repository mode
# $server_git_repo_umask:: Umask used during git operations
#
# $server_git_repo_hook_mode:: Git repository hook mode
#
# $server_git_repo_group:: Git repository group
#
Expand Down Expand Up @@ -674,8 +676,9 @@
Array[Stdlib::Absolutepath, 1] $server_envs_dir = $puppet::params::server_envs_dir,
Optional[Stdlib::Absolutepath] $server_envs_target = $puppet::params::server_envs_target,
Variant[Undef, String[0], Array[Stdlib::Absolutepath]] $server_common_modules_path = $puppet::params::server_common_modules_path,
Pattern[/^[0-9]{3,4}$/] $server_git_repo_mode = $puppet::params::server_git_repo_mode,
Pattern[/^[0-9]{3,4}$/] $server_git_repo_hook_mode = $puppet::params::server_git_repo_hook_mode,
Stdlib::Absolutepath $server_git_repo_path = $puppet::params::server_git_repo_path,
Pattern[/^[0-9]{3,4}$/] $server_git_repo_umask = $puppet::params::server_git_repo_umask,
String $server_git_repo_group = $puppet::params::server_git_repo_group,
String $server_git_repo_user = $puppet::params::server_git_repo_user,
Hash[String, String] $server_git_branch_map = $puppet::params::server_git_branch_map,
Expand Down
8 changes: 5 additions & 3 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,12 @@
$server_common_modules_path = unique(["${server_envs_dir[0]}/common", "${codedir}/modules", "${sharedir}/modules", '/usr/share/puppet/modules'])

# Dynamic environments config, ignore if the git_repo is 'false'
# Path to the repository
# Path to the repository on disk
$server_git_repo_path = "${vardir}/puppet.git"
# mode of the repository
$server_git_repo_mode = '0755'
# Umask for vcsrepo operations
$server_git_repo_umask = '0022'
# mode of the repository hooks
$server_git_repo_hook_mode = '0755'
# user of the repository
$server_git_repo_user = $user
# group of the repository
Expand Down
9 changes: 6 additions & 3 deletions manifests/server.pp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,11 @@
#
# $common_modules_path:: Common modules paths
#
# $git_repo_path:: Git repository path
# $git_repo_path:: Git repository path on disk
#
# $git_repo_mode:: Git repository mode
# $git_repo_umask:: Umask used during git operations
#
# $git_repo_hook_mode:: Git repository hook mode
#
# $git_repo_group:: Git repository group
#
Expand Down Expand Up @@ -384,8 +386,9 @@
Array[Stdlib::Absolutepath, 1] $envs_dir = $puppet::server_envs_dir,
Optional[Stdlib::Absolutepath] $envs_target = $puppet::server_envs_target,
Variant[Undef, String[0], Array[Stdlib::Absolutepath]] $common_modules_path = $puppet::server_common_modules_path,
Pattern[/^[0-9]{3,4}$/] $git_repo_mode = $puppet::server_git_repo_mode,
Pattern[/^[0-9]{3,4}$/] $git_repo_hook_mode = $puppet::server_git_repo_hook_mode,
Stdlib::Absolutepath $git_repo_path = $puppet::server_git_repo_path,
Pattern[/^[0-9]{3,4}$/] $git_repo_umask = $puppet::server_git_repo_umask,
String $git_repo_group = $puppet::server_git_repo_group,
String $git_repo_user = $puppet::server_git_repo_user,
Hash[String, String] $git_branch_map = $puppet::server_git_branch_map,
Expand Down
23 changes: 12 additions & 11 deletions manifests/server/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,10 @@
}

if $puppet::server::git_repo {
include git
ensure_packages(['git'])

if $puppet::server::manage_user {
Class['git'] -> User[$puppet::server::user]
Package['git'] -> User[$puppet::server::user]
}

file { $puppet::vardir:
Expand All @@ -253,13 +253,14 @@
group => 'root',
}

git::repo { 'puppet_repo':
bare => true,
target => $puppet::server::git_repo_path,
mode => $puppet::server::git_repo_mode,
user => $puppet::server::git_repo_user,
group => $puppet::server::git_repo_group,
require => File[$puppet::vardir, $primary_envs_dir],
vcsrepo { 'puppet_repo':
ensure => 'bare',
provider => 'git',
path => $puppet::server::git_repo_path,
user => $puppet::server::git_repo_user,
group => $puppet::server::git_repo_group,
umask => $puppet::server::git_repo_umask,
require => File[$puppet::vardir, $primary_envs_dir],
}

$git_branch_map = $puppet::server::git_branch_map
Expand All @@ -268,8 +269,8 @@
content => template($puppet::server::post_hook_content),
owner => $puppet::server::git_repo_user,
group => $puppet::server::git_repo_group,
mode => $puppet::server::git_repo_mode,
require => Git::Repo['puppet_repo'],
mode => $puppet::server::git_repo_hook_mode,
require => Vcsrepo['puppet_repo'],
}
}

Expand Down
10 changes: 5 additions & 5 deletions spec/classes/puppet_server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@
end
should contain_user('puppet')
.with_shell(shell)
.that_requires('Class[git]')
.that_requires('Package[git]')
end

it do
Expand All @@ -373,9 +373,9 @@
end

it do
should contain_git__repo('puppet_repo')
.with_bare(true)
.with_target("#{vardir}/puppet.git")
should contain_vcsrepo('puppet_repo')
.with_ensure('bare')
.with_path("#{vardir}/puppet.git")
.with_user('puppet')
.that_requires("File[#{environments_dir}]")
end
Expand All @@ -384,7 +384,7 @@
should contain_file("#{vardir}/puppet.git/hooks/post-receive")
.with_owner('puppet') \
.with_mode('0755') \
.that_requires('Git::Repo[puppet_repo]') \
.that_requires('Vcsrepo[puppet_repo]') \
.with_content(/BRANCH_MAP = \{[^a-zA-Z=>]\}/)
end

Expand Down

0 comments on commit 0cf1850

Please sign in to comment.