1 |
class git { |
2 |
class common { |
3 |
package { 'git-core': } |
4 |
} |
5 |
|
6 |
class server inherits common { |
7 |
# http://www.kernel.org/pub/software/scm/git/docs/everyday.html#Repository%20Administration |
8 |
$git_base_path = '/git/' |
9 |
|
10 |
xinetd::service { "git": |
11 |
content => template('git/xinetd') |
12 |
} |
13 |
|
14 |
file { "$git_base_path": |
15 |
ensure => directory |
16 |
} |
17 |
|
18 |
file { "/usr/local/bin/create_git_repo.sh": |
19 |
mode => 755, |
20 |
source => 'puppet:///modules/git/create_git_repo.sh', |
21 |
} |
22 |
|
23 |
file { "/usr/local/bin/apply_git_puppet_config.sh": |
24 |
mode => 755, |
25 |
source => 'puppet:///modules/git/apply_git_puppet_config.sh', |
26 |
} |
27 |
|
28 |
|
29 |
# TODO |
30 |
# define common syntax check, see svn |
31 |
# http://stackoverflow.com/questions/3719883/git-hook-syntax-check |
32 |
# proper policy : fast-forward-only |
33 |
# ( http://progit.org/book/ch7-4.html ) |
34 |
# no branch ? |
35 |
# no binary |
36 |
# no big file |
37 |
# no empty commit message |
38 |
# no commit from root |
39 |
# see http://www.itk.org/Wiki/Git/Hooks |
40 |
# 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 |
41 |
# |
42 |
# how do we handle commit permission ? |
43 |
# mail sending |
44 |
# |
45 |
} |
46 |
|
47 |
define repository($description = '', |
48 |
$group ) { |
49 |
|
50 |
include git::server |
51 |
# http://eagleas.livejournal.com/18907.html |
52 |
# TODO group permission should be handled here too |
53 |
exec { "/usr/local/bin/create_git_repo.sh $name": |
54 |
user => root, |
55 |
group => $group, |
56 |
creates => $name, |
57 |
} |
58 |
|
59 |
file { "$name/git-daemon-export-ok": |
60 |
require => Exec["/usr/local/bin/create_git_repo.sh $name"] |
61 |
} |
62 |
|
63 |
file { "$name/description": |
64 |
content => $description, |
65 |
require => File["$name/git-daemon-export-ok"] |
66 |
} |
67 |
|
68 |
file { "$name/hooks/post-receive": |
69 |
mode => 755, |
70 |
content => template('git/post-receive'), |
71 |
require => File["$name/git-daemon-export-ok"] |
72 |
} |
73 |
|
74 |
file { "$name/config.puppet": |
75 |
require => File["$name/git-daemon-export-ok"], |
76 |
notify => Exec["/usr/local/bin/apply_git_puppet_config.sh $name"], |
77 |
content => template('git/config.puppet'), |
78 |
} |
79 |
|
80 |
# $name is not really used, but this prevent duplicate declaration error |
81 |
exec { "/usr/local/bin/apply_git_puppet_config.sh $name": |
82 |
cwd => $name, |
83 |
user => "root", |
84 |
refreshonly => true |
85 |
} |
86 |
} |
87 |
|
88 |
define mirror($source, |
89 |
$description, |
90 |
$refresh = '*/5') { |
91 |
|
92 |
exec { "/usr/bin/git clone --bare $source $name": |
93 |
alias => "git mirror $name", |
94 |
creates => $name, |
95 |
before => File["$name/description"], |
96 |
} |
97 |
|
98 |
file { "$name/description": |
99 |
content => $description, |
100 |
} |
101 |
|
102 |
cron { "update $name": |
103 |
command => "cd $name ; /usr/bin/git fetch -q", |
104 |
minute => $refresh |
105 |
} |
106 |
} |
107 |
|
108 |
define svn_repository($source, |
109 |
$std_layout = true, |
110 |
$refresh = '*/5') { |
111 |
include git::svn |
112 |
include git::server |
113 |
# a cron job |
114 |
# a exec |
115 |
if $std_layout { |
116 |
$options = "-s" |
117 |
} else { |
118 |
$options = " " |
119 |
} |
120 |
|
121 |
exec { "/usr/bin/git svn init $options $source $name": |
122 |
alias => "git svn $name", |
123 |
creates => $name, |
124 |
} |
125 |
|
126 |
file { "/usr/local/bin/update_git_svn.sh": |
127 |
mode => 755, |
128 |
source => 'puppet:///modules/git/update_git_svn.sh', |
129 |
} |
130 |
|
131 |
cron { "update $name": |
132 |
# done in 2 times, so fetch can fill the repo after init |
133 |
command => "/usr/local/bin/update_git_svn.sh $name" , |
134 |
minute => $refresh |
135 |
} |
136 |
|
137 |
file { "$name/.git/hooks/pre-receive": |
138 |
mode => 755, |
139 |
content => template('git/pre-receive'), |
140 |
require => Exec["git svn $name"] |
141 |
} |
142 |
} |
143 |
|
144 |
class client inherits common { |
145 |
|
146 |
|
147 |
} |
148 |
|
149 |
class svn inherits client { |
150 |
package { "git-svn": } |
151 |
} |
152 |
|
153 |
define snapshot($source, $refresh ='*/5', $user = 'root') { |
154 |
include git::client |
155 |
#TODO |
156 |
# should handle branch -> clone -n + branch + checkout |
157 |
# create a script |
158 |
# Idealy, should be handled by vcsrepo https://github.com/bruce/puppet-vcsrepo |
159 |
# once it is merged in puppet |
160 |
exec { "/usr/bin/git clone $source $name": |
161 |
creates => $name, |
162 |
user => $user |
163 |
} |
164 |
|
165 |
cron { "update $name": |
166 |
# FIXME no -q ? |
167 |
command => "cd $name && /usr/bin/git pull", |
168 |
user => $user, |
169 |
minute => $refresh |
170 |
} |
171 |
} |
172 |
} |