|
1 # == Define puppi::project::git |
|
2 # |
|
3 # This is a shortcut define to build a puppi project for the deploy of |
|
4 # file from a git repo. |
|
5 # It uses different "core" defines (puppi::project, puppi:deploy (many), |
|
6 # puppi::rollback (many)) to build a full featured template project for |
|
7 # automatic deployments. |
|
8 # If you need to customize it, either change the template defined here or |
|
9 # build up your own custom ones. |
|
10 # |
|
11 # == Variables: |
|
12 # |
|
13 # [*source*] |
|
14 # The full URL of the git repo to retrieve. |
|
15 # Format should be in git friendly standard (http:// git:// ssh:// ..). |
|
16 # |
|
17 # [*deploy_root*] |
|
18 # The destination directory where the retrieved file(s) are deployed. |
|
19 # |
|
20 # [*install_git*] |
|
21 # If the git package hs to be installed. Default true. |
|
22 # Set to false if you install git via other modules and have resource |
|
23 # conflicts. |
|
24 # |
|
25 # [*git_subdir*] |
|
26 # (Optional) - If you want to copy to the deploy_root only a subdir |
|
27 # of the specified git repo, specify here the path of the directory |
|
28 # relative to the repo root. Default undefined |
|
29 # |
|
30 # [*tag*] |
|
31 # (Optional) - A specific tag you may want to deploy. Default undefined |
|
32 # You can override the default value via command-line with: |
|
33 # puppi deploy myapp -o "tag=release" |
|
34 # |
|
35 # [*branch*] |
|
36 # (Optional) - A specific branch you may want to deploy. Default: master |
|
37 # You can override the default value via command-line with: |
|
38 # puppi deploy myapp -o "branch=devel" |
|
39 # |
|
40 # [*commit*] |
|
41 # (Optional) - A specific commit you may want to use. Default undefined |
|
42 # You can override the default value via command-line with: |
|
43 # puppi deploy myapp -o "commit=1061cb731bc75a1188b58b889b74ce1505ccb412" |
|
44 # |
|
45 # [*keep_gitdata*] |
|
46 # (Optional) - Define if you want to keep git metadata directory (.git) |
|
47 # in the deploy root. According to this value backup and rollback |
|
48 # operations change (with keep_gitdata set to true no real backups are done |
|
49 # and operations are made on the git tree, if set to false, file are copied |
|
50 # and the $backup_* options used. Default is true |
|
51 # |
|
52 # [*verbose*] |
|
53 # (Optional) - If you want to see verbose git utput (file names) during |
|
54 # the deploy. Default is true. |
|
55 # |
|
56 # [*user*] |
|
57 # (Optional) - The user to be used for deploy operations. |
|
58 # If different from root (default) it must have write permissions on |
|
59 # the $deploy_root dir. |
|
60 # |
|
61 # [*predeploy_customcommand*] |
|
62 # (Optional) - Full path with arguments of an eventual custom command to |
|
63 # execute before the deploy. The command is executed as $predeploy_user. |
|
64 # |
|
65 # [*predeploy_user*] |
|
66 # (Optional) - The user to be used to execute the $predeploy_customcommand. |
|
67 # By default is the same of $user. |
|
68 # |
|
69 # [*predeploy_priority*] |
|
70 # (Optional) - The priority (execution sequence number) that defines when, |
|
71 # during the deploy procedure, the $predeploy_customcommand is executed |
|
72 # Default: 39 (immediately before the copy of files on the deploy root). |
|
73 # |
|
74 # [*postdeploy_customcommand*] |
|
75 # (Optional) - Full path with arguments of an eventual custom command to |
|
76 # execute after the deploy. The command is executed as $postdeploy_user. |
|
77 # |
|
78 # [*postdeploy_user*] |
|
79 # (Optional) - The user to be used to execute the $postdeploy_customcommand. |
|
80 # By default is the same of $user. |
|
81 # |
|
82 # [*postdeploy_priority*] |
|
83 # (Optional) - The priority (execution sequence number) that defines when, |
|
84 # during the deploy procedure, the $postdeploy_customcommand is executed |
|
85 # Default: 41 (immediately after the copy of files on the deploy root). |
|
86 # |
|
87 # [*disable_services*] |
|
88 # (Optional) - The names (space separated) of the services you might want to |
|
89 # stop during deploy. By default is blank. Example: "apache puppet monit". |
|
90 # |
|
91 # [*firewall_src_ip*] |
|
92 # (Optional) - The IP address of a loadbalancer you might want to block out |
|
93 # during a deploy. |
|
94 # |
|
95 # [*firewall_dst_port*] |
|
96 # (Optional) - The local port to block from the loadbalancer during deploy |
|
97 # (Default all). |
|
98 # |
|
99 # [*firewall_delay*] |
|
100 # (Optional) - A delay time in seconds to wait after the block of |
|
101 # $firewall_src_ip. Should be at least as long as the loadbalancer check |
|
102 # interval for the services stopped during deploy (Default: 1). |
|
103 # |
|
104 # [*report_email*] |
|
105 # (Optional) - The (space separated) email(s) to notify of deploy/rollback |
|
106 # operations. If none is specified, no email is sent. |
|
107 # |
|
108 # [*backup_rsync_options*] |
|
109 # (Optional) - The extra options to pass to rsync for backup operations. Use |
|
110 # it, for example, to exclude directories that you don't want to archive. |
|
111 # IE: "--exclude .snapshot --exclude cache --exclude www/cache". |
|
112 # This option is used when $keep_gitmeta is set to false |
|
113 # |
|
114 # [*backup_retention*] |
|
115 # (Optional) - Number of backup archives to keep. (Default 5). |
|
116 # Lower the default value if your backups are too large and may fill up the |
|
117 # filesystem. |
|
118 # This option is used when $keep_gitmeta is set to false |
|
119 # |
|
120 # [*run_checks*] |
|
121 # (Optional) - If you want to run local puppi checks before and after the |
|
122 # deploy procedure. Default: "true". |
|
123 # |
|
124 # [*auto_deploy*] |
|
125 # (Optional) - If you want to automatically run this puppi deploy when |
|
126 # Puppet runs. Default: 'false' |
|
127 # |
|
128 define puppi::project::git ( |
|
129 $source, |
|
130 $deploy_root, |
|
131 $install_git = true, |
|
132 $git_subdir = 'undefined', |
|
133 $tag = 'undefined', |
|
134 $branch = 'master', |
|
135 $commit = 'undefined', |
|
136 $keep_gitdata = true, |
|
137 $verbose = true, |
|
138 $user = 'root', |
|
139 $predeploy_customcommand = '', |
|
140 $predeploy_user = '', |
|
141 $predeploy_priority = '39', |
|
142 $postdeploy_customcommand = '', |
|
143 $postdeploy_user = '', |
|
144 $postdeploy_priority = '41', |
|
145 $disable_services = '', |
|
146 $firewall_src_ip = '', |
|
147 $firewall_dst_port = '0', |
|
148 $firewall_delay = '1', |
|
149 $report_email = '', |
|
150 $backup_rsync_options = '--exclude .snapshot', |
|
151 $backup_retention = '5', |
|
152 $run_checks = true, |
|
153 $auto_deploy = false, |
|
154 $enable = true ) { |
|
155 |
|
156 require puppi |
|
157 require puppi::params |
|
158 |
|
159 # Set default values |
|
160 $predeploy_real_user = $predeploy_user ? { |
|
161 '' => $user, |
|
162 default => $predeploy_user, |
|
163 } |
|
164 |
|
165 $postdeploy_real_user = $postdeploy_user ? { |
|
166 '' => $user, |
|
167 default => $postdeploy_user, |
|
168 } |
|
169 |
|
170 $bool_install_git = any2bool($install_git) |
|
171 $bool_keep_gitdata = any2bool($keep_gitdata) |
|
172 $bool_verbose = any2bool($verbose) |
|
173 $bool_run_checks = any2bool($run_checks) |
|
174 $bool_auto_deploy = any2bool($auto_deploy) |
|
175 |
|
176 ### INSTALL GIT |
|
177 if ($bool_install_git == true) { |
|
178 if ! defined(Package['git']) { package { 'git': ensure => installed } } |
|
179 } |
|
180 |
|
181 ### CREATE PROJECT |
|
182 puppi::project { $name: |
|
183 enable => $enable , |
|
184 } |
|
185 |
|
186 |
|
187 ### DEPLOY SEQUENCE |
|
188 if ($bool_run_checks == true) { |
|
189 puppi::deploy { "${name}-Run_PRE-Checks": |
|
190 priority => '10' , |
|
191 command => 'check_project.sh' , |
|
192 arguments => $name , |
|
193 user => 'root' , |
|
194 project => $name , |
|
195 enable => $enable , |
|
196 } |
|
197 } |
|
198 |
|
199 if ($firewall_src_ip != '') { |
|
200 puppi::deploy { "${name}-Load_Balancer_Block": |
|
201 priority => '25' , |
|
202 command => 'firewall.sh' , |
|
203 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
204 user => 'root', |
|
205 project => $name , |
|
206 enable => $enable , |
|
207 } |
|
208 } |
|
209 |
|
210 if ($bool_keep_gitdata == true) { |
|
211 puppi::deploy { "${name}-Backup_existing_data": |
|
212 priority => '30' , |
|
213 command => 'archive.sh' , |
|
214 arguments => "-b ${deploy_root} -o '${backup_rsync_options}' -n ${backup_retention}" , |
|
215 user => 'root' , |
|
216 project => $name , |
|
217 enable => $enable , |
|
218 } |
|
219 } |
|
220 |
|
221 if ($disable_services != '') { |
|
222 puppi::deploy { "${name}-Disable_extra_services": |
|
223 priority => '36' , |
|
224 command => 'service.sh' , |
|
225 arguments => "stop ${disable_services}" , |
|
226 user => 'root', |
|
227 project => $name , |
|
228 enable => $enable , |
|
229 } |
|
230 } |
|
231 |
|
232 if ($predeploy_customcommand != '') { |
|
233 puppi::deploy { "${name}-Run_Custom_PreDeploy_Script": |
|
234 priority => $predeploy_priority , |
|
235 command => 'execute.sh' , |
|
236 arguments => $predeploy_customcommand , |
|
237 user => $predeploy_real_user , |
|
238 project => $name , |
|
239 enable => $enable , |
|
240 } |
|
241 } |
|
242 |
|
243 # Here is done the deploy on $deploy_root |
|
244 puppi::deploy { "${name}-Deploy_Files": |
|
245 priority => '40' , |
|
246 command => 'git.sh' , |
|
247 arguments => "-a deploy -s ${source} -d ${deploy_root} -u ${user} -gs ${git_subdir} -t ${tag} -b ${branch} -c ${commit} -v ${bool_verbose} -k ${bool_keep_gitdata}" , |
|
248 user => 'root' , |
|
249 project => $name , |
|
250 enable => $enable , |
|
251 } |
|
252 |
|
253 if ($postdeploy_customcommand != '') { |
|
254 puppi::deploy { "${name}-Run_Custom_PostDeploy_Script": |
|
255 priority => $postdeploy_priority , |
|
256 command => 'execute.sh' , |
|
257 arguments => $postdeploy_customcommand , |
|
258 user => $postdeploy_real_user , |
|
259 project => $name , |
|
260 enable => $enable , |
|
261 } |
|
262 } |
|
263 |
|
264 if ($disable_services != '') { |
|
265 puppi::deploy { "${name}-Enable_extra_services": |
|
266 priority => '44' , |
|
267 command => 'service.sh' , |
|
268 arguments => "start ${disable_services}" , |
|
269 user => 'root', |
|
270 project => $name , |
|
271 enable => $enable , |
|
272 } |
|
273 } |
|
274 |
|
275 if ($firewall_src_ip != '') { |
|
276 puppi::deploy { "${name}-Load_Balancer_Unblock": |
|
277 priority => '46' , |
|
278 command => 'firewall.sh' , |
|
279 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
280 user => 'root', |
|
281 project => $name , |
|
282 enable => $enable , |
|
283 } |
|
284 } |
|
285 |
|
286 if ($bool_run_checks == true) { |
|
287 puppi::deploy { "${name}-Run_POST-Checks": |
|
288 priority => '80' , |
|
289 command => 'check_project.sh' , |
|
290 arguments => $name , |
|
291 user => 'root' , |
|
292 project => $name , |
|
293 enable => $enable , |
|
294 } |
|
295 } |
|
296 |
|
297 |
|
298 ### ROLLBACK PROCEDURE |
|
299 |
|
300 if ($firewall_src_ip != '') { |
|
301 puppi::rollback { "${name}-Load_Balancer_Block": |
|
302 priority => '25' , |
|
303 command => 'firewall.sh' , |
|
304 arguments => "${firewall_src_ip} ${firewall_dst_port} on ${firewall_delay}" , |
|
305 user => 'root', |
|
306 project => $name , |
|
307 enable => $enable , |
|
308 } |
|
309 } |
|
310 |
|
311 if ($disable_services != '') { |
|
312 puppi::rollback { "${name}-Disable_extra_services": |
|
313 priority => '37' , |
|
314 command => 'service.sh' , |
|
315 arguments => "stop ${disable_services}" , |
|
316 user => 'root', |
|
317 project => $name , |
|
318 enable => $enable , |
|
319 } |
|
320 } |
|
321 |
|
322 if ($predeploy_customcommand != '') { |
|
323 puppi::rollback { "${name}-Run_Custom_PreDeploy_Script": |
|
324 priority => $predeploy_priority , |
|
325 command => 'execute.sh' , |
|
326 arguments => $predeploy_customcommand , |
|
327 user => $predeploy_real_user , |
|
328 project => $name , |
|
329 enable => $enable , |
|
330 } |
|
331 } |
|
332 |
|
333 if ($bool_keep_gitdata == true) { |
|
334 puppi::rollback { "${name}-Recover_Files_To_Deploy": |
|
335 priority => '40' , |
|
336 command => 'archive.sh' , |
|
337 arguments => "-r ${deploy_root} -o '${backup_rsync_options}'" , |
|
338 user => $user , |
|
339 project => $name , |
|
340 enable => $enable , |
|
341 } |
|
342 } |
|
343 |
|
344 if ($bool_keep_gitdata != true) { |
|
345 puppi::rollback { "${name}-Rollback_Files": |
|
346 priority => '40' , |
|
347 command => 'git.sh' , |
|
348 arguments => "-a rollback -s ${source} -d ${deploy_root} -gs ${git_subdir} -t ${tag} -b ${branch} -c ${commit} -v ${bool_verbose} -k ${bool_keep_gitdata}" , |
|
349 user => $user , |
|
350 project => $name , |
|
351 enable => $enable , |
|
352 } |
|
353 } |
|
354 |
|
355 if ($postdeploy_customcommand != '') { |
|
356 puppi::rollback { "${name}-Run_Custom_PostDeploy_Script": |
|
357 priority => $postdeploy_priority , |
|
358 command => 'execute.sh' , |
|
359 arguments => $postdeploy_customcommand , |
|
360 user => $postdeploy_real_user , |
|
361 project => $name , |
|
362 enable => $enable , |
|
363 } |
|
364 } |
|
365 |
|
366 if ($disable_services != '') { |
|
367 puppi::rollback { "${name}-Enable_extra_services": |
|
368 priority => '44' , |
|
369 command => 'service.sh' , |
|
370 arguments => "start ${disable_services}" , |
|
371 user => 'root', |
|
372 project => $name , |
|
373 enable => $enable , |
|
374 } |
|
375 } |
|
376 |
|
377 if ($firewall_src_ip != '') { |
|
378 puppi::rollback { "${name}-Load_Balancer_Unblock": |
|
379 priority => '46' , |
|
380 command => 'firewall.sh' , |
|
381 arguments => "${firewall_src_ip} ${firewall_dst_port} off 0" , |
|
382 user => 'root', |
|
383 project => $name , |
|
384 enable => $enable , |
|
385 } |
|
386 } |
|
387 |
|
388 if ($bool_run_checks == true) { |
|
389 puppi::rollback { "${name}-Run_POST-Checks": |
|
390 priority => '80' , |
|
391 command => 'check_project.sh' , |
|
392 arguments => $name , |
|
393 user => 'root' , |
|
394 project => $name , |
|
395 enable => $enable , |
|
396 } |
|
397 } |
|
398 |
|
399 |
|
400 ### REPORTING |
|
401 |
|
402 if ($report_email != '') { |
|
403 puppi::report { "${name}-Mail_Notification": |
|
404 priority => '20' , |
|
405 command => 'report_mail.sh' , |
|
406 arguments => $report_email , |
|
407 user => 'root', |
|
408 project => $name , |
|
409 enable => $enable , |
|
410 } |
|
411 } |
|
412 |
|
413 ### AUTO DEPLOY DURING PUPPET RUN |
|
414 if ($bool_auto_deploy == true) { |
|
415 puppi::run { $name: } |
|
416 } |
|
417 |
|
418 } |