diff --git a/manifests/clean.pp b/manifests/clean.pp index a9de5d8..7c6fd35 100644 --- a/manifests/clean.pp +++ b/manifests/clean.pp @@ -1,27 +1,34 @@ -define git::clean($localtree = '/srv/git/', $real_name = false, $user = '') { +define git::clean ( + $localtree = '/srv/git/', + $real_name = false, + $user = '', + $schedule = undef) { + # + # Resource to clean out a working directory + # Useful for directories you want to pull from upstream, but might + # have added files. This resource is applied for all pull resources, + # by default. + # + if $schedule != undef { + Exec { + schedule => $schedule, } + } - # - # Resource to clean out a working directory - # Useful for directories you want to pull from upstream, but might - # have added files. This resource is applied for all pull resources, - # by default. - # - if $user == '' { - exec { "git_clean_exec_$name": - cwd => $real_name ? { - false => "$localtree/$name", - default => "$localtree/$real_name" - }, - command => 'git clean -d -f' - } + if $user == '' { + exec { "git_clean_exec_$name": + cwd => $real_name ? { + false => "$localtree/$name", + default => "$localtree/$real_name" + }, + command => 'git clean -d -f' } - else { - exec { "git_clean_exec_$name": - cwd => $real_name ? { - false => "$localtree/$name", - default => "$localtree/$real_name" - }, - command => "sudo -u $user git clean -d -f" - } + } else { + exec { "git_clean_exec_$name": + cwd => $real_name ? { + false => "$localtree/$name", + default => "$localtree/$real_name" + }, + command => "sudo -u $user git clean -d -f" } + } } diff --git a/manifests/client.pp b/manifests/client.pp index deaf4f1..c6e9313 100644 --- a/manifests/client.pp +++ b/manifests/client.pp @@ -1,22 +1,17 @@ class git::client { + # + # Documentation on this class + # + # This class causes the client to gain git capabilities. Boo! + # - # - # Documentation on this class - # - # This class causes the client to gain git capabilities. Boo! - # - - case $::lsbdistcodename { - etch: { - os::backported_package{'git-core': - ensure => installed - } - } + case $::lsbdistcodename { + etch : { + os::backported_package { 'git-core': ensure => installed } + } - default: { - package {'git-core': - ensure => installed - } - } + default : { + package { 'git-core': ensure => installed } } + } } diff --git a/manifests/clone.pp b/manifests/clone.pp index 01a088b..e7ad71d 100644 --- a/manifests/clone.pp +++ b/manifests/clone.pp @@ -1,52 +1,60 @@ -define git::clone( $source, - $localtree = '/srv/git/', - $real_name = false, - $branch = false, - $user = '') { - if $real_name { - $_name = $real_name - } - else { - $_name = $name +define git::clone ( + $source, + $localtree = '/srv/git/', + $real_name = false, + $branch = false, + $user = '', + $schedule = undef) { + if $real_name { + $_name = $real_name + } else { + $_name = $name + } + + if $schedule != undef { + Exec { + schedule => $schedule, } + } + + if $user == '' { + exec { "git_clone_exec_$localtree/$_name": + cwd => $localtree, + command => "git clone $source $_name", + creates => "$localtree/$_name/.git/", } - if $user == '' { - exec { "git_clone_exec_$localtree/$_name": - cwd => $localtree, - command => "git clone $source $_name", - creates => "$localtree/$_name/.git/", + case $branch { + false : { + } + default : { + exec { "git_clone_checkout_${branch}_${localtree}/${_name}": + cwd => "$localtree/$_name", + command => "git checkout --track -b $branch origin/$branch", + creates => "$localtree/$_name/.git/refs/heads/$branch" + } } + } + } else { + exec { "git_clone_exec_$localtree/$_name": + cwd => $localtree, + command => "sudo -u $user git clone $source $_name", + creates => "$localtree/$_name/.git/", + timeout => 0 + } - case $branch { - false: {} - default: { - exec { "git_clone_checkout_${branch}_${localtree}/${_name}": - cwd => "$localtree/$_name", - command => "git checkout --track -b $branch origin/$branch", - creates => "$localtree/$_name/.git/refs/heads/$branch" - } - } + case $branch { + false : { } - } else { - exec { "git_clone_exec_$localtree/$_name": - cwd => $localtree, - command => "sudo -u $user git clone $source $_name", - creates => "$localtree/$_name/.git/", + default : { + exec { "git_clone_checkout_${branch}_${localtree}/${_name}": + cwd => "$localtree/$_name", + command => "git checkout --track -b $branch origin/$branch", + creates => "$localtree/$_name/.git/refs/heads/$branch", + user => $user, + require => User[$user], timeout => 0 - } - - case $branch { - false: {} - default: { - exec { "git_clone_checkout_${branch}_${localtree}/${_name}": - cwd => "$localtree/$_name", - command => "git checkout --track -b $branch origin/$branch", - creates => "$localtree/$_name/.git/refs/heads/$branch", - user => $user, - require => User[$user], - timeout => 0 - } - } + } } } + } } diff --git a/manifests/pull.pp b/manifests/pull.pp index e600362..1287dee 100644 --- a/manifests/pull.pp +++ b/manifests/pull.pp @@ -1,95 +1,100 @@ -define git::pull($localtree = '/srv/git/', $real_name = false, - $reset = true, $clean = true, $branch = false, - $git_tag = false, $user = '') { +define git::pull ( + $localtree = '/srv/git/', + $real_name = false, + $reset = true, + $clean = true, + $branch = false, + $git_tag = false, + $schedule = undef, + $user = '') { + if $real_name { + $_name = $real_name + } else { + $_name = $name + } - if $real_name { - $_name = $real_name - } - else { - $_name = $name - } - - # - # This resource enables one to update a working directory - # from an upstream GIT source repository. Note that by default, - # the working directory is reset (undo any changes to tracked - # files), and clean (remove untracked files) - # - # Note that to prevent a reset to be executed, you can set $reset to - # false when calling this resource. - # - # Note that to prevent a clean to be executed as part of the reset, you - # can set $clean to false - # + # + # This resource enables one to update a working directory + # from an upstream GIT source repository. Note that by default, + # the working directory is reset (undo any changes to tracked + # files), and clean (remove untracked files) + # + # Note that to prevent a reset to be executed, you can set $reset to + # false when calling this resource. + # + # Note that to prevent a clean to be executed as part of the reset, you + # can set $clean to false + # - if $reset { - git::reset { $name: - localtree => $localtree, - real_name => $real_name, - clean => $clean, - user => $user - } + if $reset { + git::reset { $name: + localtree => $localtree, + real_name => $real_name, + clean => $clean, + user => $user } + } - if $git_tag { - - if $git_tag == 'latest' { - $git_checkout_tag = '`git describe --tags $(git rev-list --tags --max-count=1)`' - } else { - $git_checkout_tag = $git_tag - } - - @exec { "git_pull_exec_$name": - cwd => "$localtree/$_name", - command => "sudo -u $user git fetch --tags", - onlyif => "test -d $localtree/$_name/.git/info" - } + if $schedule != undef { + Exec { + schedule => $schedule, } + } - exec { "git_checkout_tag_${name}_${git_tag}": - cwd => "$localtree/$_name", - command => "sudo -u $user git checkout $git_checkout_tag", - creates => "$localtree/$_name/git/refs/tags/$git_checkout_tag", - } + if $git_tag { + if $git_tag == 'latest' { + $git_checkout_tag = '`git describe --tags $(git rev-list --tags --max-count=1)`' } else { + $git_checkout_tag = $git_tag + } - if $user == '' { - @exec { "git_pull_exec_$name": - cwd => "$localtree/$_name", - command => 'git pull', - onlyif => "test -d $localtree/$_name/.git/info" - } - } - else { - @exec { "git_pull_exec_$name": - cwd => "$localtree/$_name", - command => "sudo -u $user git pull", - onlyif => "test -d $localtree/$_name/.git/info" - } - } - - case $branch { - false: {} - default: { - exec { "git_pull_checkout_${branch}_${localtree}/${name}": - cwd => "$localtree/$_name", - command => "git checkout --track -b $branch origin/$branch", - creates => "$localtree/$_name/.git/refs/heads/$branch" - } - } - } + @exec { "git_pull_exec_$name": + cwd => "$localtree/$_name", + command => "sudo -u $user git fetch --tags", + onlyif => "test -d $localtree/$_name/.git/info" } - if defined(Git::Reset[$name]) { - Exec["git_pull_exec_$name"] { - require +> Git::Reset[$name] - } + exec { "git_checkout_tag_${name}_${git_tag}": + cwd => "$localtree/$_name", + command => "sudo -u $user git checkout $git_checkout_tag", + creates => "$localtree/$_name/git/refs/tags/$git_checkout_tag", + } + } else { + if $user == '' { + @exec { "git_pull_exec_$name": + cwd => "$localtree/$_name", + command => 'git pull', + onlyif => "test -d $localtree/$_name/.git/info" + } + } else { + @exec { "git_pull_exec_$name": + cwd => "$localtree/$_name", + command => "sudo -u $user git pull", + onlyif => "test -d $localtree/$_name/.git/info" + } } - if defined(Git::Clean[$name]) { - Exec["git_pull_exec_$name"] { - require +> Git::Clean[$name] + case $branch { + false : { + } + default : { + exec { "git_pull_checkout_${branch}_${localtree}/${name}": + cwd => "$localtree/$_name", + command => "git checkout --track -b $branch origin/$branch", + creates => "$localtree/$_name/.git/refs/heads/$branch" } + } } + } + + if defined(Git::Reset[$name]) { + Exec["git_pull_exec_$name"] { + require +> Git::Reset[$name] } + } + + if defined(Git::Clean[$name]) { + Exec["git_pull_exec_$name"] { + require +> Git::Clean[$name] } + } - realize(Exec["git_pull_exec_$name"]) + realize(Exec["git_pull_exec_$name"]) } diff --git a/manifests/repository.pp b/manifests/repository.pp index 32fdfe9..4706523 100644 --- a/manifests/repository.pp +++ b/manifests/repository.pp @@ -1,149 +1,143 @@ -define git::repository( $public = false, $shared = false, - $localtree = '/srv/git/', $owner = 'root', - $group = 'root', $symlink_prefix = false, - $prefix = false, $recipients = false, - $description = false) { - # FIXME - # Why does this include server? One can run repositories without a - # git daemon..!! - # - # - The defined File["git_init_script"] resource will need to move to - # this class - # - # Documentation on this resource - # - # Set $public to true when calling this resource to make the repository - # readable to others - # - # Set $shared to true to allow the group owner (set with $group) to - # write to the repository - # - # Set $localtree to the base directory of where you would like to have - # the git repository located. - # - # The actual git repository would end up in $localtree/$name, where - # $name is the title you gave to the resource. - # - # Set $owner to the user that is the owner of the entire git repository - # - # Set $group to the group that is the owner of the entire git repository - # - # Set $init to false to prevent the initial commit to be made - # +define git::repository ( + $public = false, + $shared = false, + $localtree = '/srv/git/', + $owner = 'root', + $group = 'root', + $symlink_prefix = false, + $prefix = false, + $recipients = false, + $description = false) { + # FIXME + # Why does this include server? One can run repositories without a + # git daemon..!! + # + # - The defined File["git_init_script"] resource will need to move to + # this class + # + # Documentation on this resource + # + # Set $public to true when calling this resource to make the repository + # readable to others + # + # Set $shared to true to allow the group owner (set with $group) to + # write to the repository + # + # Set $localtree to the base directory of where you would like to have + # the git repository located. + # + # The actual git repository would end up in $localtree/$name, where + # $name is the title you gave to the resource. + # + # Set $owner to the user that is the owner of the entire git repository + # + # Set $group to the group that is the owner of the entire git repository + # + # Set $init to false to prevent the initial commit to be made + # - include git::server + include git::server - file { "git_repository_$name": - path => $prefix ? { - false => "$localtree/$name", - default => "$localtree/${prefix}-${name}" - }, - ensure => directory, - owner => $owner, - group => $group, - mode => $public ? { - true => $shared ? { - true => '2775', - default => '0755' - }, - default => $shared ? { - true => '2770', - default => '0750' - } - } - } + file { "git_repository_$name": + path => $prefix ? { + false => "$localtree/$name", + default => "$localtree/${prefix}-${name}" + }, + ensure => directory, + owner => $owner, + group => $group, + mode => $public ? { + true => $shared ? { + true => '2775', + default => '0755' + }, + default => $shared ? { + true => '2770', + default => '0750' + } } + } - # Set the hook for this repository - file { "git_repository_hook_post-commit_$name": - path => $prefix ? { - false => "$localtree/$name/hooks/post-commit", - default => "$localtree/${prefix}-${name}/hooks/post-commit" - }, - source => "puppet://$::server/git/post-commit", - mode => 755, - require => [ - File["git_repository_$name"], - Exec["git_init_script_$name"] - ] - } + # Set the hook for this repository + file { "git_repository_hook_post-commit_$name": + path => $prefix ? { + false => "$localtree/$name/hooks/post-commit", + default => "$localtree/${prefix}-${name}/hooks/post-commit" + }, + source => "puppet://$::server/git/post-commit", + mode => 755, + require => [File["git_repository_$name"], Exec["git_init_script_$name"]] + } + + file { "git_repository_hook_update_$name": + path => $prefix ? { + false => "$localtree/$name/hooks/update", + default => "$localtree/${prefix}-${name}/hooks/update" + }, + ensure => "$localtree/$name/hooks/post-commit", + require => [File["git_repository_$name"], Exec["git_init_script_$name"]] + } - file { "git_repository_hook_update_$name": + file { "git_repository_hook_post-update_$name": + path => $prefix ? { + false => "$localtree/$name/hooks/post-update", + default => "$localtree/${prefix}-${name}/hooks/post-update" + }, + mode => 755, + owner => $owner, + group => $group, + require => [File["git_repository_$name"], Exec["git_init_script_$name"]] + } + + # In case there are recipients defined, get in the commit-list + case $recipients { + false : { + } + default : { + file { "git_repository_commit_list_$name": path => $prefix ? { - false => "$localtree/$name/hooks/update", - default => "$localtree/${prefix}-${name}/hooks/update" + false => "$localtree/$name/commit-list", + default => "$localtree/${prefix}-${name}/commit-list" }, - ensure => "$localtree/$name/hooks/post-commit", + content => template('git/commit-list.erb'), require => [ - File["git_repository_$name"], - Exec["git_init_script_$name"] - ] + File["git_repository_$name"], + Exec["git_init_script_$name"]] + } } + } - file { "git_repository_hook_post-update_$name": + case $description { + false : { + } + default : { + file { "git_repository_description_$name": path => $prefix ? { - false => "$localtree/$name/hooks/post-update", - default => "$localtree/${prefix}-${name}/hooks/post-update" + false => "$localtree/$name/description", + default => "$localtree/${prefix}-${name}/description" }, - mode => 755, - owner => $owner, - group => $group, + content => $description, require => [ - File["git_repository_$name"], - Exec["git_init_script_$name"] - ] - } - - # In case there are recipients defined, get in the commit-list - case $recipients { - false: {} - default: { - file { "git_repository_commit_list_$name": - path => $prefix ? { - false => "$localtree/$name/commit-list", - default => "$localtree/${prefix}-${name}/commit-list" - }, - content => template('git/commit-list.erb'), - require => [ - File["git_repository_$name"], - Exec["git_init_script_$name"] - ] - } - } - } - - case $description { - false: {} - default: { - file { "git_repository_description_$name": - path => $prefix ? { - false => "$localtree/$name/description", - default => "$localtree/${prefix}-${name}/description" - }, - content => $description, - require => [ - File["git_repository_$name"], - Exec["git_init_script_$name"] - ] - } - } + File["git_repository_$name"], + Exec["git_init_script_$name"]] + } } + } - exec { "git_init_script_$name": - command => $prefix ? { - false => "git_init_script --localtree $localtree + exec { "git_init_script_$name": + command => $prefix ? { + false => "git_init_script --localtree $localtree --name $name --shared $shared --public $public --owner $owner --group $group", - default => "git_init_script --localtree $localtree + default => "git_init_script --localtree $localtree --name ${prefix}-${name} --shared $shared --public $public --owner $owner --group $group" - }, - creates => $prefix ? { - false => "$localtree/$name/info", - default => "$localtree/${prefix}-${name}" - }, - require => [ - File["git_repository_$name"], - File['/usr/local/bin/git_init_script'] - ] - } + }, + creates => $prefix ? { + false => "$localtree/$name/info", + default => "$localtree/${prefix}-${name}" + }, + require => [ + File["git_repository_$name"], + File['/usr/local/bin/git_init_script']] + } } diff --git a/manifests/repository/domain.pp b/manifests/repository/domain.pp index e6d78b6..81069a5 100644 --- a/manifests/repository/domain.pp +++ b/manifests/repository/domain.pp @@ -1,32 +1,31 @@ -define git::repository::domain($public = false, - $shared = false, - $localtree = '/srv/git/', - $owner = 'root', - $group = 'root', - $symlink_prefix = false, - $recipients = false, - $description = false) { - git::repository { $name: - public => $public, - shared => $shared, - localtree => "$localtree/", - owner => $owner, - group => "git-$name", - prefix => 'domain', - symlink_prefix => $symlink_prefix, - recipients => $recipients, - description => $description, - require => Group["git-$name"] - } +define git::repository::domain ( + $public = false, + $shared = false, + $localtree = '/srv/git/', + $owner = 'root', + $group = 'root', + $symlink_prefix = false, + $recipients = false, + $description = false) { + git::repository { $name: + public => $public, + shared => $shared, + localtree => "$localtree/", + owner => $owner, + group => "git-$name", + prefix => 'domain', + symlink_prefix => $symlink_prefix, + recipients => $recipients, + description => $description, + require => Group["git-$name"] + } - group { "git-$name": - ensure => present - } + group { "git-$name": ensure => present } - user { "satellite-$name": - ensure => present, - comment => "Satellite user for domain $name", - groups => "git-$name", - shell => '/usr/bin/git-shell' - } + user { "satellite-$name": + ensure => present, + comment => "Satellite user for domain $name", + groups => "git-$name", + shell => '/usr/bin/git-shell' + } } diff --git a/manifests/reset.pp b/manifests/reset.pp index a55ef88..535ca2e 100644 --- a/manifests/reset.pp +++ b/manifests/reset.pp @@ -1,40 +1,46 @@ -define git::reset($localtree = '/srv/git/', $real_name = false, $clean = true, - $user='') { +define git::reset ( + $localtree = '/srv/git/', + $real_name = false, + $clean = true, + $user = '', + $schedule = undef) { + # + # Resource to reset changes in a working directory + # Useful to undo any changes that might have occured in directories + # that you want to pull for. This resource is automatically called + # with every pull by default. + # + # You can set $clean to false to prevent a clean (removing untracked + # files) + # + if $schedule != undef { + Exec { + schedule => $schedule, } + } - # - # Resource to reset changes in a working directory - # Useful to undo any changes that might have occured in directories - # that you want to pull for. This resource is automatically called - # with every pull by default. - # - # You can set $clean to false to prevent a clean (removing untracked - # files) - # - - if $user == '' { - exec { "git_reset_exec_$name": - cwd => $real_name ? { - false => "$localtree/$name", - default => "$localtree/$real_name" - }, - command => 'git reset --hard HEAD' - } + if $user == '' { + exec { "git_reset_exec_$name": + cwd => $real_name ? { + false => "$localtree/$name", + default => "$localtree/$real_name" + }, + command => 'git reset --hard HEAD' } - else { - exec { "git_reset_exec_$name": - cwd => $real_name ? { - false => "$localtree/$name", - default => "$localtree/$real_name" - }, - command => "sudo -u $user git reset --hard HEAD" - } + } else { + exec { "git_reset_exec_$name": + cwd => $real_name ? { + false => "$localtree/$name", + default => "$localtree/$real_name" + }, + command => "sudo -u $user git reset --hard HEAD" } + } - if $clean { - git::clean { $name: - localtree => $localtree, - real_name => $real_name, - user => $user - } + if $clean { + git::clean { $name: + localtree => $localtree, + real_name => $real_name, + user => $user } + } } diff --git a/manifests/server.pp b/manifests/server.pp index fb550f1..8488adf 100644 --- a/manifests/server.pp +++ b/manifests/server.pp @@ -1,41 +1,37 @@ class git::server inherits git::client { + # + # Documentation on this class + # + # Including this class will install git, the git-daemon, ensure the + # service is running + # - # - # Documentation on this class - # - # Including this class will install git, the git-daemon, ensure the - # service is running - # + package { 'git-daemon-run': ensure => installed } - package { 'git-daemon-run': - ensure => installed - } + # service { "git": + # enable => true, + # ensure => running, + # require => Package["git-daemon-run"], + # notify => Service["xinetd"] + #} - #service { "git": - # enable => true, - # ensure => running, - # require => Package["git-daemon-run"], - # notify => Service["xinetd"] - #} + # service { "xinetd": + # enable => true, + # ensure => running + #} - #service { "xinetd": - # enable => true, - # ensure => running - #} + file { '/srv/git/': + ensure => directory, + mode => '0755' + } - file { '/srv/git/': - ensure => directory, - mode => '0755' - } - - file { '/usr/local/bin/git_init_script': - owner => 'root', - group => 'root', - mode => '0750', - source => [ - #"puppet://$server/private/$domain/git/git_init_script", - #"puppet://$server/files/git/git_init_script", - "puppet://$::server/git/git_init_script" - ] - } + file { '/usr/local/bin/git_init_script': + owner => 'root', + group => 'root', + mode => '0750', + source => [ + # "puppet://$server/private/$domain/git/git_init_script", + # "puppet://$server/files/git/git_init_script", + "puppet://$::server/git/git_init_script"] + } }