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