aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/manifests/init.pp
blob: 6c0b1553332f55c9f94a792d0d638a0dde382402 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
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":
            ensure => present,
            owner => root,
            group => root,
            mode => 755,
            source => 'puppet:///modules/git/create_git_repo.sh',
        }

        file { "/usr/local/bin/apply_git_puppet_config.sh":
            ensure => present,
            owner => root,
            group => root,
            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":
            ensure => present,
            require => Exec["/usr/local/bin/create_git_repo.sh $name"]
        }
        
        file { "$name/description":
            ensure => present,
            content => $description,
            require => File["$name/git-daemon-export-ok"]
        }

        file { "$name/hooks/post-receive":
            ensure => present,
            owner => root,
            group => root,
            mode => 755,
            content => template('git/post-receive'), 
            require => File["$name/git-daemon-export-ok"]
        }

        file { "$name/config.puppet":
            ensure => present,
            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 
        }
    }

    define mirror($source,
                  $refresh = '*/5') {

        exec { "/usr/bin/git clone $source $name":
            alias => "git mirror $name",
            creates => $name,
        }

        cron { "update $name":
            command => "/usr/bin/git pull $name" ,
            minute => $refresh
        }
    }

    define svn_repository($source,
                          $std_layout = true,
                          $refresh = '*/5') {
        include git::svn
        include git::server
        # a cron job
        # a exec
        if $std_layout {
            $options = "-s"
        } else {
            $options = " "
        }

        exec { "/usr/bin/git svn init $options $source $name":
            alias => "git svn $name",
            creates => $name,
        }
        
        file { "/usr/local/bin/update_git_svn.sh":
             ensure => present,
             owner => root,
             group => root,
             mode => 755,
             source => 'puppet:///modules/git/update_git_svn.sh',
        }

        cron { "update $name":
            # done in 2 times, so fetch can fill the repo after init
            command => "/usr/local/bin/update_git_svn.sh $name" ,
            minute => $refresh
        }

        file { "$name/.git/hooks/pre-receive":
            ensure => present,
            owner => root,
            group => root,
            mode => 755,
            content => template('git/pre-receive'), 
            require => Exec["git svn $name"]
        }
    }

    class client inherits common {


    }

    class svn inherits client {
        package { "git-svn":
            ensure => installed
        }
    }

    define snapshot($source, $refresh ='*/5', $user = 'root') {
        include git::client
        #TODO
        # should handle branch -> clone -n + branch + checkout 
        # create a script 
        # Idealy, should be handled by vcsrepo https://github.com/bruce/puppet-vcsrepo   
        # once it is merged in puppet 
        exec { "/usr/bin/git clone $source $name":
            creates => $name,
            user => $user
        }
        
        cron { "update $name":
            # FIXME no -q ?
            command => "cd $name && /usr/bin/git pull",
            user => $user,
            minute => $refresh
        }
    }
}