1 |
class git { |
class git { |
|
class common { |
|
|
package { 'git-core': } |
|
|
} |
|
|
|
|
|
class server inherits common { |
|
|
# http://www.kernel.org/pub/software/scm/git/docs/everyday.html#Repository%20Administration |
|
|
$git_base_path = '/git/' |
|
|
|
|
|
xinetd::service { "git": |
|
|
content => template('git/xinetd') |
|
|
} |
|
|
|
|
|
file { "$git_base_path": |
|
|
ensure => directory |
|
|
} |
|
|
|
|
|
file { "/usr/local/bin/create_git_repo.sh": |
|
|
mode => 755, |
|
|
source => 'puppet:///modules/git/create_git_repo.sh', |
|
|
} |
|
|
|
|
|
file { "/usr/local/bin/apply_git_puppet_config.sh": |
|
|
mode => 755, |
|
|
source => 'puppet:///modules/git/apply_git_puppet_config.sh', |
|
|
} |
|
|
|
|
|
|
|
|
# TODO |
|
|
# define common syntax check, see svn |
|
|
# http://stackoverflow.com/questions/3719883/git-hook-syntax-check |
|
|
# proper policy : fast-forward-only |
|
|
# ( http://progit.org/book/ch7-4.html ) |
|
|
# no branch ? |
|
|
# no binary |
|
|
# no big file |
|
|
# no empty commit message |
|
|
# no commit from root |
|
|
# see http://www.itk.org/Wiki/Git/Hooks |
|
|
# automated push to another git repo ( see http://noone.org/blog/English/Computer/VCS/Thoughts%20on%20Gitorious%20and%20GitHub%20plus%20a%20useful%20git%20hook.futile |
|
|
# |
|
|
# how do we handle commit permission ? |
|
|
# mail sending |
|
|
# |
|
|
} |
|
|
|
|
|
define repository($description = '', |
|
|
$group ) { |
|
|
|
|
|
include git::server |
|
|
# http://eagleas.livejournal.com/18907.html |
|
|
# TODO group permission should be handled here too |
|
|
exec { "/usr/local/bin/create_git_repo.sh $name": |
|
|
user => root, |
|
|
group => $group, |
|
|
creates => $name, |
|
|
} |
|
|
|
|
|
file { "$name/git-daemon-export-ok": |
|
|
require => Exec["/usr/local/bin/create_git_repo.sh $name"] |
|
|
} |
|
|
|
|
|
file { "$name/description": |
|
|
content => $description, |
|
|
require => File["$name/git-daemon-export-ok"] |
|
|
} |
|
|
|
|
|
file { "$name/hooks/post-receive": |
|
|
mode => 755, |
|
|
content => template('git/post-receive'), |
|
|
require => File["$name/git-daemon-export-ok"] |
|
|
} |
|
|
|
|
|
file { "$name/config.puppet": |
|
|
require => File["$name/git-daemon-export-ok"], |
|
|
notify => Exec["/usr/local/bin/apply_git_puppet_config.sh $name"], |
|
|
content => template('git/config.puppet'), |
|
|
} |
|
|
|
|
|
# $name is not really used, but this prevent duplicate declaration error |
|
|
exec { "/usr/local/bin/apply_git_puppet_config.sh $name": |
|
|
cwd => $name, |
|
|
user => "root", |
|
|
refreshonly => true |
|
|
} |
|
|
} |
|
|
|
|
2 |
define mirror($source, |
define mirror($source, |
3 |
$description, |
$description, |
4 |
$refresh = '*/5') { |
$refresh = '*/5') { |
5 |
|
|
6 |
exec { "/usr/bin/git clone --bare $source $name": |
exec { "/usr/bin/git clone --bare $source $name": |
7 |
alias => "git mirror $name", |
alias => "git mirror $name", |
8 |
creates => $name, |
creates => $name, |
9 |
before => File["$name/description"], |
before => File["$name/description"], |
10 |
} |
} |
11 |
|
|
12 |
file { "$name/description": |
file { "$name/description": |
13 |
content => $description, |
content => $description, |
14 |
} |
} |
15 |
|
|
16 |
cron { "update $name": |
cron { "update $name": |
17 |
command => "cd $name ; /usr/bin/git fetch -q", |
command => "cd $name ; /usr/bin/git fetch -q", |
18 |
minute => $refresh |
minute => $refresh |
19 |
} |
} |
20 |
} |
} |
21 |
|
|
27 |
# a cron job |
# a cron job |
28 |
# a exec |
# a exec |
29 |
if $std_layout { |
if $std_layout { |
30 |
$options = "-s" |
$options = '-s' |
31 |
} else { |
} else { |
32 |
$options = " " |
$options = '' |
33 |
} |
} |
34 |
|
|
35 |
exec { "/usr/bin/git svn init $options $source $name": |
exec { "/usr/bin/git svn init $options $source $name": |
36 |
alias => "git svn $name", |
alias => "git svn $name", |
37 |
creates => $name, |
creates => $name, |
38 |
} |
} |
39 |
|
|
40 |
file { "/usr/local/bin/update_git_svn.sh": |
file { '/usr/local/bin/update_git_svn.sh': |
41 |
mode => 755, |
mode => '0755', |
42 |
source => 'puppet:///modules/git/update_git_svn.sh', |
source => 'puppet:///modules/git/update_git_svn.sh', |
43 |
} |
} |
44 |
|
|
45 |
cron { "update $name": |
cron { "update $name": |
46 |
# done in 2 times, so fetch can fill the repo after init |
# done in 2 times, so fetch can fill the repo after init |
47 |
command => "/usr/local/bin/update_git_svn.sh $name" , |
command => "/usr/local/bin/update_git_svn.sh $name" , |
48 |
minute => $refresh |
minute => $refresh |
49 |
} |
} |
50 |
|
|
51 |
file { "$name/.git/hooks/pre-receive": |
file { "$name/.git/hooks/pre-receive": |
52 |
mode => 755, |
mode => '0755', |
53 |
content => template('git/pre-receive'), |
content => template('git/pre-receive'), |
54 |
require => Exec["git svn $name"] |
require => Exec["git svn $name"] |
55 |
} |
} |
56 |
} |
} |
61 |
} |
} |
62 |
|
|
63 |
class svn inherits client { |
class svn inherits client { |
64 |
package { "git-svn": } |
package { 'git-svn': } |
65 |
} |
} |
66 |
|
|
67 |
define snapshot($source, $refresh ='*/5', $user = 'root') { |
define snapshot($source, $refresh ='*/5', $user = 'root') { |
68 |
include git::client |
include git::client |
69 |
#TODO |
#TODO |
70 |
# should handle branch -> clone -n + branch + checkout |
# should handle branch -> clone -n + branch + checkout |
71 |
# create a script |
# create a script |
72 |
# Idealy, should be handled by vcsrepo https://github.com/bruce/puppet-vcsrepo |
# Idealy, should be handled by vcsrepo https://github.com/bruce/puppet-vcsrepo |
73 |
# once it is merged in puppet |
# once it is merged in puppet |
74 |
exec { "/usr/bin/git clone $source $name": |
exec { "/usr/bin/git clone $source $name": |
75 |
creates => $name, |
creates => $name, |
76 |
user => $user |
user => $user |
77 |
} |
} |
78 |
|
|
79 |
cron { "update $name": |
cron { "update $name": |
80 |
# FIXME no -q ? |
# FIXME no -q ? |
81 |
command => "cd $name && /usr/bin/git pull", |
command => "cd $name && /usr/bin/git pull", |
82 |
user => $user, |
user => $user, |
83 |
minute => $refresh |
minute => $refresh |
84 |
} |
} |
85 |
} |
} |
86 |
} |
} |