Skip to content

Commit

Permalink
Move complex dependency to a separate class
Browse files Browse the repository at this point in the history
This commit allow end users to easily disable/replace the dependency
management of GitLab module. Retro-compatibility is kept and by default
puppet-gitlab take care of GitLab dependency.

To override internal puppet-gitlab class, we can use this call:
  class {'gitlab':
    gitlab_dependency => 'mydepsclass'
  }

Refs: #35, #102
  • Loading branch information
sbadia committed Mar 28, 2014
1 parent 727ea9e commit 566edd4
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 92 deletions.
82 changes: 82 additions & 0 deletions manifests/dependency.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Class:: gitlab::dependency inherits gitlab
#
#
class gitlab::dependency inherits gitlab {

include logrotate

# database dependencies
case $gitlab_dbtype {
'mysql': {
case $::osfamily {
'Debian': {
ensure_packages(['libmysql++-dev','libmysqlclient-dev'])
}
'RedHat': {
ensure_packages(['mysql-devel'])
}
default: {
err "${::osfamily} not supported yet for mysql"
}
} # Case $::osfamily

} # mysql
'pgsql': {
case $::osfamily {
'Debian': {
ensure_packages(['libpq-dev'])
}
'RedHat': {
ensure_packages(['postgresql-devel'])
}
default: {
err "${::osfamily} not supported yet for pgsql"
}
} # Case $::osfamily

} # pgsql
default: {
err "${gitlab_dbtype} not supported yet"
}
} # Case $::gitlab_dbtype

# other packages
ensure_packages([$git_package_name,'postfix','curl'])

# dev. dependencies
ensure_packages($system_packages)

case $::operatingsystem {
'ubuntu': {
class { 'ruby':
ruby_package => 'ruby1.9.3',
rubygems_package => 'rubygems1.9.1',
rubygems_update => false,
}
Package <| name == 'ruby1.9.3' |> {
notify +> [ Exec['ruby-version'], Exec['gem-version'] ],
}
exec { 'ruby-version':
command => '/usr/bin/update-alternatives --set ruby /usr/bin/ruby1.9.1',
user => root,
refreshonly => true,
before => Class['Ruby::Dev'],
}
exec { 'gem-version':
command => '/usr/bin/update-alternatives --set gem /usr/bin/gem1.9.1',
user => root,
refreshonly => true,
before => Class['Ruby::Dev'],
}
}
default: {
class { 'ruby':
version => '1:1.9.3',
rubygems_update => false;
}
}
}

class { 'ruby::dev': }

} # Class:: gitlab::dependency inherits gitlab
2 changes: 2 additions & 0 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@
#
class gitlab(
$ensure = $gitlab::params::ensure,
$gitlab_dependency = $gitlab::params::gitlab_dependency,
$git_user = $gitlab::params::git_user,
$git_home = $gitlab::params::git_home,
$git_email = $gitlab::params::git_email,
Expand Down Expand Up @@ -332,6 +333,7 @@
validate_string($google_analytics_id)

anchor { 'gitlab::begin': } ->
class { $gitlab_dependency: } ->
class { '::gitlab::setup': } ->
class { '::gitlab::package': } ->
class { '::gitlab::install': } ->
Expand Down
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
class gitlab::params {

$ensure = 'present'
$gitlab_dependency = 'gitlab::dependency'
$git_user = 'git'
$git_home = '/home/git'
$git_email = '[email protected]'
Expand Down
40 changes: 1 addition & 39 deletions manifests/setup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,53 +41,15 @@
mode => '0755',
}

# database dependencies
case $::osfamily {
'Debian': {
case $gitlab_dbtype {
'mysql': {
ensure_packages(['libmysql++-dev','libmysqlclient-dev'])
}
'pgsql': {
ensure_packages(['libpq-dev','postgresql-client'])
}
default: {
fail("unknow dbtype (${gitlab_dbtype})")
}
}
}
'RedHat': {
case $gitlab_dbtype {
'mysql': {
ensure_packages(['mysql-devel'])
}
'pgsql': {
ensure_packages(['postgresql-devel'])
}
default: {
fail("unknow dbtype (${gitlab_dbtype})")
}
}
}
default: {
fail("${::osfamily} not supported yet")
}
} # Case $::osfamily

# system packages
package { 'bundler':
ensure => installed,
provider => gem,
}

# dev. dependencies
ensure_packages($system_packages)

package { 'charlock_holmes':
ensure => '0.6.9.4',
provider => gem,
}

# other packages
ensure_packages([$git_package_name,'postfix','curl'])
}
} # Class:: gitlab::setup inherits gitlab
66 changes: 66 additions & 0 deletions spec/classes/gitlab_dependency_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
require 'spec_helper'

# Gitlab
describe 'gitlab' do

## Gitlab::setup
describe 'gitlab::dependency' do

### Packages setup
#= Packages helper
p = {
'Debian' => {
'db_packages' => {
'mysql' => ['libmysql++-dev','libmysqlclient-dev'],
'pgsql' => ['libpq-dev']
},
'system_packages' => ['libicu-dev', 'python2.7','python-docutils',
'libxml2-dev','libxslt1-dev','python-dev'],
'git_packages' => ['git-core']
},
'RedHat' => {
'db_packages' => {
'mysql' => ['mysql-devel'],
'pgsql' => ['postgresql-devel']
},
'system_packages' => ['libicu-devel','perl-Time-HiRes','libxml2-devel',
'libxslt-devel','python-devel','libcurl-devel',
'readline-devel','openssl-devel','zlib-devel',
'libyaml-devel','patch','gcc-c++'],
'git_packages' => ['git']
}
}

#### Db and devel packages
describe 'packages' do
#= On each distro
['Debian','RedHat'].each do |distro|
#= With each dbtype
['mysql','pgsql'].each do |dbtype|
context "for #{dbtype} devel on #{distro}" do
let(:facts) {{ :osfamily => distro }}
let(:params) {{ :gitlab_dbtype => dbtype }}
p[distro]['db_packages'][dbtype].each do |pkg|
it { should contain_package(pkg) }
end
end
end
context "for devel dependencies on #{distro}" do
let(:facts) {{ :osfamily => distro }}
p[distro]['system_packages'].each do |pkg|
it { should contain_package(pkg) }
end
p[distro]['git_packages'].each do |pkg|
it { should contain_package(pkg) }
end
end
end
#### Commons packages (all dist.)
describe 'commons packages' do
['git-core','postfix','curl'].each do |pkg|
it { should contain_package(pkg) }
end
end
end # packages
end # gitlab::dependency
end # gitlab
53 changes: 0 additions & 53 deletions spec/classes/gitlab_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,55 +65,8 @@
)}
end

### Packages setup
#= Packages helper
p = {
'Debian' => {
'db_packages' => {
'mysql' => ['libmysql++-dev','libmysqlclient-dev'],
'pgsql' => ['libpq-dev', 'postgresql-client']
},
'system_packages' => ['libicu-dev', 'python2.7','python-docutils',
'libxml2-dev','libxslt1-dev','python-dev'],
'git_packages' => ['git-core']
},
'RedHat' => {
'db_packages' => {
'mysql' => ['mysql-devel'],
'pgsql' => ['postgresql-devel']
},
'system_packages' => ['libicu-devel','perl-Time-HiRes','libxml2-devel',
'libxslt-devel','python-devel','libcurl-devel',
'readline-devel','openssl-devel','zlib-devel',
'libyaml-devel','patch','gcc-c++'],
'git_packages' => ['git']
}
}

#### Db and devel packages
describe 'packages' do
#= On each distro
['Debian','RedHat'].each do |distro|
#= With each dbtype
['mysql','pgsql'].each do |dbtype|
context "for #{dbtype} devel on #{distro}" do
let(:facts) {{ :osfamily => distro }}
let(:params) {{ :gitlab_dbtype => dbtype }}
p[distro]['db_packages'][dbtype].each do |pkg|
it { should contain_package(pkg) }
end
end
end
context "for devel dependencies on #{distro}" do
let(:facts) {{ :osfamily => distro }}
p[distro]['system_packages'].each do |pkg|
it { should contain_package(pkg) }
end
p[distro]['git_packages'].each do |pkg|
it { should contain_package(pkg) }
end
end
end
#### Gems (all dist.)
describe 'commons gems' do
it { should contain_package('bundler').with(
Expand All @@ -125,12 +78,6 @@
:provider => 'gem'
)}
end
#### Commons packages (all dist.)
describe 'commons packages' do
['git-core','postfix','curl'].each do |pkg|
it { should contain_package(pkg) }
end
end
end # packages
end # gitlab::setup
end # gitlab

0 comments on commit 566edd4

Please sign in to comment.