Last active
October 21, 2016 13:34
-
-
Save bernd/4556606 to your computer and use it in GitHub Desktop.
Quick & dirty puppet manifest to install GitLab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Gitlab installation via puppet on Debian/Ubuntu (quick & dirty) | |
# | |
# Based on https://github.com/gitlabhq/gitlabhq/blob/stable/doc/install/installation.md | |
# | |
# Tested on Ubuntu 12.04. | |
# | |
# Run it: | |
# $ apt-get install puppet | |
# $ puppet apply puppet.pp | |
# | |
# After puppet: | |
# open http://localhost:8080/ and login | |
# | |
# Username: [email protected] | |
# Password: 5iveL!fe | |
Exec { path => '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin' } | |
exec { 'apt-get-update': command => 'apt-get update' } | |
# Trigger 'apt-get update' before executing a package resource. | |
Exec['apt-get-update'] -> Package <||> | |
class ruby { | |
package { 'ruby1.9.3': ensure => installed } | |
package { 'bundler': | |
ensure => installed, | |
provider => 'gem', | |
require => Package['ruby1.9.3']; | |
} | |
} | |
class gitlab::dependencies { | |
include ruby | |
$packages = [ | |
'build-essential', 'zlib1g-dev', 'libyaml-dev', 'libssl-dev', | |
'libgdbm-dev', 'libreadline-dev', 'libncurses5-dev', 'libffi-dev', | |
'wget', 'curl', 'git', 'openssh-server', 'redis-server', 'postfix', | |
'checkinstall', 'libxml2-dev', 'libxslt1-dev', 'libcurl4-openssl-dev', | |
'libicu-dev', 'python2.7', 'mysql-server', 'mysql-client', | |
'libmysqlclient-dev' | |
] | |
package { $packages: ensure => installed; } | |
} | |
class gitlab::users { | |
User { | |
ensure => present, | |
system => true, | |
shell => '/bin/sh', | |
managehome => true | |
} | |
user { 'git': | |
home => '/home/git', | |
comment => 'Git Version Control'; | |
} | |
user { 'gitlab': | |
home => '/home/gitlab', | |
comment => 'Gitlab', | |
groups => ['git'], | |
require => User['git']; | |
} | |
file { '/home/gitlab/.ssh': | |
ensure => directory, | |
owner => 'gitlab', | |
group => 'gitlab', | |
mode => '0700', | |
require => User['gitlab']; | |
} | |
exec { 'ssh-keygen-gitlab': | |
command => 'sudo -u gitlab -H ssh-keygen -q -t rsa -f /home/gitlab/.ssh/id_rsa', | |
creates => '/home/gitlab/.ssh/id_rsa', | |
require => File['/home/gitlab/.ssh']; | |
} | |
} | |
class gitolite { | |
require gitlab::users | |
File { owner => 'git', group => 'git', mode => '0755' } | |
file { '/home/git/bin': ensure => directory; } | |
file { '/home/git/gitlab.pub': | |
ensure => present, | |
mode => '444', | |
source => '/home/gitlab/.ssh/id_rsa.pub'; | |
} | |
Exec { user => 'root', group => 'root', cwd => '/home/git', logoutput => true } | |
exec { 'clone-gitolite': | |
command => 'sudo -u git -H git clone -b gl-v320 https://github.com/gitlabhq/gitolite.git /home/git/gitolite', | |
creates => '/home/git/gitolite/.git', | |
notify => Exec['install-gitolite'], | |
require => File['/home/git/bin']; | |
} | |
exec { 'install-gitolite': | |
command => 'sudo -u git -H sh -c "/home/git/gitolite/install -ln /home/git/bin"', | |
notify => Exec['setup-gitolite-admin-key'], | |
refreshonly => true; | |
} | |
exec { 'setup-gitolite-admin-key': | |
command => 'sudo -u git -H sh -c "/home/git/bin/gitolite setup -pk /home/git/gitlab.pub"', | |
creates => '/home/git/.gitolite/keydir/gitlab.pub', | |
refreshonly => true, | |
notify => Exec['fix-gitolite-repo-permission'], | |
require => File['/home/git/gitlab.pub']; | |
} | |
exec { 'fix-gitolite-repo-permission': | |
command => 'chmod -R ug+rwXs,o-rwx repositories', | |
refreshonly => true; | |
} | |
} | |
class gitlab::ssh_config { | |
require gitlab::users | |
$ssh_config = "Host localhost | |
StrictHostKeyChecking no | |
UserKnownHostsFile=/dev/null | |
" | |
file { '/home/gitlab/.ssh/config': | |
ensure => present, | |
owner => 'gitlab', | |
group => 'gitlab', | |
mode => '0600', | |
content => $ssh_config; | |
} | |
} | |
class gitlab::source { | |
require gitlab::dependencies | |
require gitlab::users | |
$dir = '/home/gitlab/gitlab' | |
Exec { user => 'gitlab', group => 'gitlab' } | |
exec { 'clone-gitlab-source': | |
command => 'git clone https://github.com/gitlabhq/gitlabhq.git gitlab', | |
cwd => '/home/gitlab', | |
creates => $dir, | |
notify => Exec['checkout-gitlab-stable-branch'], | |
logoutput => true; | |
} | |
exec { 'checkout-gitlab-stable-branch': | |
command => 'git checkout 4-2-stable', | |
cwd => '/home/gitlab/gitlab', | |
logoutput => true, | |
refreshonly => true; | |
} | |
} | |
class gitlab::config { | |
require gitolite | |
require gitlab::users | |
require gitlab::source | |
$database_config = "--- | |
production: | |
adapter: mysql2 | |
encoding: utf8 | |
reconnect: false | |
database: gitlab | |
pool: 5 | |
username: root | |
password: | |
" | |
$gitconfig = "[user] | |
\tname = GitLab | |
\temail = gitlab@localhost | |
" | |
File { owner => 'gitlab', group => 'gitlab', mode => '0640' } | |
file { "${gitlab::source::dir}/config/database.yml": | |
ensure => present, | |
content => $database_config; | |
} | |
file { "${gitlab::source::dir}/config/gitlab.yml": | |
ensure => present, | |
source => "${gitlab::source::dir}/config/gitlab.yml.example"; | |
} | |
file { '/home/gitlab/gitlab-satellites': | |
ensure => directory, | |
mode => '0755'; | |
} | |
file { '/home/gitlab/.gitconfig': | |
ensure => present, | |
mode => '0644', | |
content => $gitconfig; | |
} | |
file { '/home/git/.gitolite/hooks/common/post-receive': | |
ensure => present, | |
owner => 'git', | |
group => 'git', | |
mode => '0755', | |
source => "${gitlab::source::dir}/lib/hooks/post-receive"; | |
} | |
exec { 'install-gitlab-unicorn-config': | |
command => "sed -e 's,listen \"#{app_dir}/tmp/sockets/gitlab.socket\",,g' -e 's,#listen 8080,listen 8080,g' config/unicorn.rb.example > config/unicorn.rb", | |
cwd => $gitlab::source::dir, | |
creates => "${gitlab::source::dir}/config/unicorn.rb"; | |
} | |
file { "${gitlab::source::dir}/config/unicorn.rb": | |
ensure => present, | |
require => Exec['install-gitlab-unicorn-config']; | |
} | |
} | |
class gitlab::bundle { | |
require gitlab::source | |
package { 'charlock_holmes': ensure => '0.6.9', provider => 'gem'; } | |
exec { 'bundle-gitlab-gems': | |
command => 'bundle install --deployment --without development:test:postgres', | |
user => 'gitlab', | |
group => 'gitlab', | |
cwd => $gitlab::source::dir, | |
unless => 'bundle check', | |
timeout => 1800, # Might take some time. | |
logoutput => true, | |
require => Package['charlock_holmes']; | |
} | |
} | |
class gitlab::setup { | |
require gitlab::config | |
require gitlab::bundle | |
Exec { | |
user => 'gitlab', | |
group => 'gitlab', | |
cwd => $gitlab::source::dir, | |
logoutput => true | |
} | |
exec { 'init-gitlab-database': | |
command => 'bundle exec rake db:create db:setup db:seed_fu gitlab:enable_automerge', | |
environment => 'RAILS_ENV=production', | |
creates => "${gitlab::source::dir}/__INITIALIZED__"; | |
} | |
file { "${gitlab::source::dir}/__INITIALIZED__": | |
ensure => present, | |
owner => 'gitlab', | |
group => 'gitlab', | |
mode => '0644', | |
require => Exec['init-gitlab-database'], | |
content => "rake db:setup gitlab:setup cookie\n"; | |
} | |
exec { 'download-gitlab-init-script': | |
command => 'wget -O gitlab.init https://raw.github.com/gitlabhq/gitlab-recipes/b934957c7a7f805bc069302eed1e42e354ee4988/init.d/gitlab', | |
creates => "${gitlab::source::dir}/gitlab.init"; | |
} | |
file { '/etc/init.d/gitlab': | |
ensure => present, | |
owner => 'root', | |
group => 'root', | |
mode => '0755', | |
require => Exec['download-gitlab-init-script'], | |
source => "${gitlab::source::dir}/gitlab.init"; | |
} | |
service { 'gitlab': | |
ensure => running, | |
enable => true, | |
hasrestart => true, | |
require => File['/etc/init.d/gitlab']; | |
} | |
} | |
class gitlab { | |
require gitolite | |
require gitlab::dependencies | |
require gitlab::users | |
require gitlab::ssh_config | |
require gitlab::source | |
require gitlab::config | |
require gitlab::bundle | |
require gitlab::setup | |
} | |
include gitlab |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment