Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Created August 14, 2012 18:39
Show Gist options
  • Save sycobuny/3351564 to your computer and use it in GitHub Desktop.
Save sycobuny/3351564 to your computer and use it in GitHub Desktop.
Puppet Management of Git Repos - Testing Methods of Cleaning it Up
# commands that are too long to reasonably be represented
$_gwt = "git tag | grep -e '^release-[0-9]\\{1,\\}\$'"
$_gwl = "${_gwt} | cut -d\\- -f2 | sort -rn | head -n1"
# figure out how to deploy this project
case "$mode" {
# ...
# prod box, make sure the latest code is loaded
'production': {
# ensure the repo is cloned
git::repository { $title: cwd => $basedir }
# ensure the configuration file is present
file { "/opt/www/conf/${title}.conf":
ensure => present,
content => template('git/project.php.httpd.conf.erb'),
notify => Service['httpd'],
}
# reset the repo (clear any changes)
git::web::exec { "reset-${title}":
require => Git::Repository[$title],
command => "git reset --hard HEAD",
}
# clean the repo (remove untracked files)
git::web::exec { "clean-${title}":
require => Git::Web::Exec["reset-${title}"],
command => "git clean -f",
}
# remove release-# tags from local repo
git::web::exec { "cleantags-${title}":
require => Git::Web::Exec["clean-${title}"],
command => "${_gwt} | xargs git tag -d",
}
# fetch the latest updates (includes tags)
git::web::exec { "fetch-${title}":
require => Git::Web::Exec["cleantags-${title}"],
command => "git fetch origin",
}
# check out the latest tag
git::web::exec { "tag-${title}":
require => Git::Web::Exec["fetch-${title}"],
command => "git checkout \"release-\$(${_gwl})\"",
}
}
}
# commands that are too long to reasonably be represented
$_gwt = "git tag | grep -e '^release-[0-9]\\{1,\\}\$'"
$_gwl = "${_gwt} | cut -d\\- -f2 | sort -rn | head -n1"
# figure out how to deploy this project
case "$mode" {
# ...
# prod box, make sure the latest code is loaded
'production': {
# ensure the repo is cloned
git::repository { $title: cwd => $basedir }
# ensure the configuration file is present
file { "/opt/www/conf/${title}.conf":
ensure => present,
content => template('git/project.php.httpd.conf.erb'),
notify => Service['httpd'],
}
# reset the repo (clear any changes)
git::web::exec { "reset-${title}": command => "git reset --hard HEAD" }
# clean the repo (remove untracked files)
git::web::exec { "clean-${title}": command => "git clean -f" }
# remove release-# tags from local repo
git::web::exec { "cleantags-${title}": command => "${_gwt} | xargs git tag -d" }
# fetch the latest updates (includes tags)
git::web::exec { "fetch-${title}": command => "git fetch origin" }
# check out the latest tag
git::web::exec { "tag-${title}": command => "git checkout \"release-\$(${_gwl})\"" }
# ensure proper order of operations
Git::Repository[$title] ->
Git::Web::Exec["reset-${title}"] ->
Git::Web::Exec["clean-${title}"] ->
Git::Web::Exec["cleantags-${title}"] ->
Git::Web::Exec["fetch-${title}"] ->
Git::Web::Exec["tag-${title}"]
}
}
# commands that are too long to reasonably be represented
$_gwt = "git tag | grep -e '^release-[0-9]\\{1,\\}\$'"
$_gwl = "${_gwt} | cut -d\\- -f2 | sort -rn | head -n1"
# figure out how to deploy this project
case "$mode" {
# ...
# prod box, make sure the latest code is loaded
'production': {
# ensure the configuration file is present
file { "/opt/www/conf/${title}.conf":
ensure => present,
content => template('git/project.php.httpd.conf.erb'),
notify => Service['httpd'],
}
# ensure the repo is cloned
git::repository { $title: cwd => $basedir } ->
# reset the repo (clear any changes)
git::web::exec { "reset-${title}":
command => "git reset --hard HEAD",
} ->
# clean the repo (remove untracked files)
git::web::exec { "clean-${title}":
command => "git clean -f",
} ->
# remove release-# tags from local repo
git::web::exec { "cleantags-${title}":
command => "${_gwt} | xargs git tag -d",
} ->
# fetch the latest updates (includes tags)
git::web::exec { "fetch-${title}":
command => "git fetch origin",
} ->
# check out the latest tag
git::web::exec { "tag-${title}":
command => "git checkout \"release-\$(${_gwl})\""
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment