Skip to content

Instantly share code, notes, and snippets.

@rchrd2
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rchrd2/45680a2360d6718e40b7 to your computer and use it in GitHub Desktop.
Save rchrd2/45680a2360d6718e40b7 to your computer and use it in GitHub Desktop.
Continuous integration with Puppet and Github.com
# Clones a repository from our github
# Info: https://github.com/puppetlabs/puppetlabs-vcsrepo/blob/master/README.GIT.markdown
class web::repo ($revision, $latest=false) {
# Git is used to install our repositories
ensure_resource('package', 'git', {'ensure' => 'present'})
class { 'ssh::client':
storeconfigs_enabled => false,
options => {
'Host *' => {
'IdentityFile' => '/etc/ssh/ssh_host_rsa_key',
},
'Host github.com' => {
'HostName' => 'github.com',
'HashKnownHosts' => 'yes',
'StrictHostKeyChecking' => 'no',
'IdentityFile' => '/etc/ssh/ssh_host_rsa_key',
'UserKnownHostsFile' => '/dev/null',
'User' => 'git',
},
},
}
-> vcsrepo { '/var/www/django/django':
# Source is the url to the repository
source => 'git+ssh://git@github.com/example/django.git',
# Just ensure present
# ensure => present
# or can ensure latest (for continous integration, for example)
# ensure => latest
# Note: latest doesn't work with specifying a revision or branch.
# So that's why there is an exec after.
ensure => present,
# Revision is where we specify what to checkout
revision => $revision,
# User to checkout with
user => 'root',
# Type of repo
provider => "git",
}
if ($latest == true) {
exec { 'pull-changes':
# This unless command makes it so this exec only runs when the branch is behind the head
unless => [
"/usr/bin/git fetch origin ${revision} && /usr/bin/git rev-list HEAD...origin/${revision} --count | /bin/grep '0'"
],
command => "/usr/bin/git pull origin ${revision}",
cwd => '/var/www/django/django',
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment