Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Created February 16, 2012 03:15
Show Gist options
  • Save sycobuny/1841425 to your computer and use it in GitHub Desktop.
Save sycobuny/1841425 to your computer and use it in GitHub Desktop.
A simple example of a puppet config with git automatic deployment based on "release-#" tags
class git {
package { 'git':
ensure => installed,
}
define repository($project = $name, $cwd, $dir = "$cwd/${project}",
$repo = "githost:${project}.git", $no_ensure = 0) {
$require = $no_ensure ? {
1 => [Package['git']],
default => [Package['git'], File[$cwd]],
}
include git
exec { "git-clone-${name}":
require => $require,
command => "git clone ${repo} ${dir}",
cwd => $cwd,
user => root,
creates => $dir,
}
}
define web_project($project = $name, $basedir = "/var/www", $dir = undef) {
$mydir = "$dir" ? {
/./ => $dir,
default => "${basedir}/${project}",
}
git::repository { $project: }
exec { "git-web-reset-${name}":
logoutput => on_failure,
require => Git::Repository[$project],
command => "git reset --hard HEAD",
cwd => $mydir,
user => root,
}
exec { "git-web-clean-${name}":
logoutput => on_failure,
require => Exec["git-web-reset-${name}"],
command => "git clean -f",
cwd => $mydir,
user => root,
}
exec { "git-web-fetch-${name}":
logoutput => on_failure,
require => Exec["git-web-clean-${name}"],
command => "git fetch origin",
cwd => $mydir,
user => root,
}
exec { "git-web-tag-${name}":
logoutput => on_failure,
require => Exec["git-web-fetch-${name}"],
command => "git checkout \"release-\$(git tag | cut -d\\- -f2 | sort -rn | head -n1)\"",
cwd => $mydir,
user => root,
}
file { "git-web-conf-${name}":
owner => root,
group => root,
mode => 0644,
require => Exec["git-web-tag-${name}"],
ensure => link,
path => "/etc/httpd/conf.d/${project}.conf",
target => "$mydir/conf/${project}.conf",
}
}
}
node webserver {
# various setup for web server
$git_web_projects = ['blog', 'analytics', 'main_site']
git::web_project { $git_web_projects: }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment