Skip to content

Instantly share code, notes, and snippets.

@sycobuny
Created February 16, 2012 03:15
Show Gist options
  • Select an option

  • Save sycobuny/1841425 to your computer and use it in GitHub Desktop.

Select an option

Save sycobuny/1841425 to your computer and use it in GitHub Desktop.

Revisions

  1. sycobuny revised this gist Feb 16, 2012. 1 changed file with 2 additions and 6 deletions.
    8 changes: 2 additions & 6 deletions git.pp
    Original file line number Diff line number Diff line change
    @@ -27,11 +27,7 @@
    default => "${basedir}/${project}",
    }

    git::repository { $project:
    cwd => $basedir,
    repo => "githost:/repo/${project}.git",
    no_ensure => 1,
    }
    git::repository { $project: }

    exec { "git-web-reset-${name}":
    logoutput => on_failure,
    @@ -72,7 +68,7 @@
    require => Exec["git-web-tag-${name}"],
    ensure => link,
    path => "/etc/httpd/conf.d/${project}.conf",
    target => "$mydir/${project}.conf",
    target => "$mydir/conf/${project}.conf",
    }
    }
    }
  2. sycobuny revised this gist Feb 16, 2012. 1 changed file with 38 additions and 23 deletions.
    61 changes: 38 additions & 23 deletions git.pp
    Original file line number Diff line number Diff line change
    @@ -1,15 +1,17 @@
    class git {
    package { 'git-core':
    package { 'git':
    ensure => installed,
    }

    define repository($project = $name, $cwd, $dir = "$cwd/${project}",
    $repo = "git@githost:${project}.git", $no_ensure => 0) {
    $repo = "githost:${project}.git", $no_ensure = 0) {
    $require = $no_ensure ? {
    1 => [Package['git-core']],
    default => [Package['git-core'], File[$cwd]],
    1 => [Package['git']],
    default => [Package['git'], File[$cwd]],
    }

    include git

    exec { "git-clone-${name}":
    require => $require,
    command => "git clone ${repo} ${dir}",
    @@ -19,35 +21,48 @@
    }
    }

    define web_project($project = $name, $basedir = "/var/www", $dir = "$basedir/${project}") {
    git::repository { $project: cwd => $basedir }
    define web_project($project = $name, $basedir = "/var/www", $dir = undef) {
    $mydir = "$dir" ? {
    /./ => $dir,
    default => "${basedir}/${project}",
    }

    git::repository { $project:
    cwd => $basedir,
    repo => "githost:/repo/${project}.git",
    no_ensure => 1,
    }

    exec { "git-web-reset-${name}":
    require => Git::Repository[$project],
    command => "git reset --hard HEAD",
    cwd => $dir,
    user => root,
    logoutput => on_failure,
    require => Git::Repository[$project],
    command => "git reset --hard HEAD",
    cwd => $mydir,
    user => root,
    }

    exec { "git-web-clean-${name}":
    require => Exec["git-web-reset-${name}"],
    command => "git clean -f",
    cwd => $dir,
    user => root,
    logoutput => on_failure,
    require => Exec["git-web-reset-${name}"],
    command => "git clean -f",
    cwd => $mydir,
    user => root,
    }

    exec { "git-web-fetch-${name}":
    require => Exec["git-web-clean-${name}"],
    command => "git fetch origin",
    cwd => $dir,
    user => root,
    logoutput => on_failure,
    require => Exec["git-web-clean-${name}"],
    command => "git fetch origin",
    cwd => $mydir,
    user => root,
    }

    exec { "git-web-tag-${name}":
    require => Exec["git-web-fetch-${name}"],
    command => "git checkout \"release-\$(git tag | cut -d\\- -f2 | sort -rn | head -n1)\"",
    cwd => $dir,
    user => root,
    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}":
    @@ -57,7 +72,7 @@
    require => Exec["git-web-tag-${name}"],
    ensure => link,
    path => "/etc/httpd/conf.d/${project}.conf",
    target => "$dir/${project}.conf",
    target => "$mydir/${project}.conf",
    }
    }
    }
  3. sycobuny revised this gist Feb 16, 2012. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion git.pp
    Original file line number Diff line number Diff line change
    @@ -19,7 +19,9 @@
    }
    }

    define web_project($project = $name, $dir = "/var/www/${project}") {
    define web_project($project = $name, $basedir = "/var/www", $dir = "$basedir/${project}") {
    git::repository { $project: cwd => $basedir }

    exec { "git-web-reset-${name}":
    require => Git::Repository[$project],
    command => "git reset --hard HEAD",
  4. sycobuny revised this gist Feb 16, 2012. 1 changed file with 8 additions and 0 deletions.
    8 changes: 8 additions & 0 deletions git.pp
    Original file line number Diff line number Diff line change
    @@ -14,6 +14,7 @@
    require => $require,
    command => "git clone ${repo} ${dir}",
    cwd => $cwd,
    user => root,
    creates => $dir,
    }
    }
    @@ -23,27 +24,34 @@
    require => Git::Repository[$project],
    command => "git reset --hard HEAD",
    cwd => $dir,
    user => root,
    }

    exec { "git-web-clean-${name}":
    require => Exec["git-web-reset-${name}"],
    command => "git clean -f",
    cwd => $dir,
    user => root,
    }

    exec { "git-web-fetch-${name}":
    require => Exec["git-web-clean-${name}"],
    command => "git fetch origin",
    cwd => $dir,
    user => root,
    }

    exec { "git-web-tag-${name}":
    require => Exec["git-web-fetch-${name}"],
    command => "git checkout \"release-\$(git tag | cut -d\\- -f2 | sort -rn | head -n1)\"",
    cwd => $dir,
    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",
  5. sycobuny revised this gist Feb 16, 2012. 1 changed file with 15 additions and 8 deletions.
    23 changes: 15 additions & 8 deletions git.pp
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@
    default => [Package['git-core'], File[$cwd]],
    }

    exec { "web-git-clone-${name}":
    exec { "git-clone-${name}":
    require => $require,
    command => "git clone ${repo} ${dir}",
    cwd => $cwd,
    @@ -19,28 +19,35 @@
    }

    define web_project($project = $name, $dir = "/var/www/${project}") {
    exec { "web-git-reset-${name}":
    exec { "git-web-reset-${name}":
    require => Git::Repository[$project],
    command => "git reset --hard HEAD",
    cwd => $dir,
    }

    exec { "web-git-clean-${name}":
    require => Exec["web-git-reset-${name}"],
    exec { "git-web-clean-${name}":
    require => Exec["git-web-reset-${name}"],
    command => "git clean -f",
    cwd => $dir,
    }

    exec { "web-git-fetch-${name}":
    require => Exec["web-git-clean-${name}"],
    exec { "git-web-fetch-${name}":
    require => Exec["git-web-clean-${name}"],
    command => "git fetch origin",
    cwd => $dir,
    }

    exec { "web-git-checkout-${name}":
    require => Exec["web-git-fetch-${name}"],
    exec { "git-web-tag-${name}":
    require => Exec["git-web-fetch-${name}"],
    command => "git checkout \"release-\$(git tag | cut -d\\- -f2 | sort -rn | head -n1)\"",
    cwd => $dir,
    }

    file { "git-web-conf-${name}":
    require => Exec["git-web-tag-${name}"],
    ensure => link,
    path => "/etc/httpd/conf.d/${project}.conf",
    target => "$dir/${project}.conf",
    }
    }
    }
  6. sycobuny revised this gist Feb 16, 2012. 1 changed file with 16 additions and 1 deletion.
    17 changes: 16 additions & 1 deletion git.pp
    Original file line number Diff line number Diff line change
    @@ -3,9 +3,24 @@
    ensure => installed,
    }

    define repository($project = $name, $cwd, $dir = "$cwd/${project}",
    $repo = "git@githost:${project}.git", $no_ensure => 0) {
    $require = $no_ensure ? {
    1 => [Package['git-core']],
    default => [Package['git-core'], File[$cwd]],
    }

    exec { "web-git-clone-${name}":
    require => $require,
    command => "git clone ${repo} ${dir}",
    cwd => $cwd,
    creates => $dir,
    }
    }

    define web_project($project = $name, $dir = "/var/www/${project}") {
    exec { "web-git-reset-${name}":
    require => Package['git-core'],
    require => Git::Repository[$project],
    command => "git reset --hard HEAD",
    cwd => $dir,
    }
  7. sycobuny renamed this gist Feb 16, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  8. sycobuny renamed this gist Feb 16, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  9. sycobuny renamed this gist Feb 16, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. sycobuny renamed this gist Feb 16, 2012. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  11. sycobuny created this gist Feb 16, 2012.
    31 changes: 31 additions & 0 deletions git.pp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,31 @@
    class git {
    package { 'git-core':
    ensure => installed,
    }

    define web_project($project = $name, $dir = "/var/www/${project}") {
    exec { "web-git-reset-${name}":
    require => Package['git-core'],
    command => "git reset --hard HEAD",
    cwd => $dir,
    }

    exec { "web-git-clean-${name}":
    require => Exec["web-git-reset-${name}"],
    command => "git clean -f",
    cwd => $dir,
    }

    exec { "web-git-fetch-${name}":
    require => Exec["web-git-clean-${name}"],
    command => "git fetch origin",
    cwd => $dir,
    }

    exec { "web-git-checkout-${name}":
    require => Exec["web-git-fetch-${name}"],
    command => "git checkout \"release-\$(git tag | cut -d\\- -f2 | sort -rn | head -n1)\"",
    cwd => $dir,
    }
    }
    }
    6 changes: 6 additions & 0 deletions site.pp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    node webserver {
    # various setup for web server

    $git_web_projects = ['blog', 'analytics', 'main_site']
    git::web_project { $git_web_projects: }
    }