Skip to content

Commit

Permalink
Add a parameter to make rbenv configuration optional
Browse files Browse the repository at this point in the history
This incidently provides a workaround for sbadia#172.
This uses a different method to change ruby path in
gitlab-shell hooks when rbenv is used and hence
fixes sbadia#202 as well.
  • Loading branch information
alexcern committed Jan 13, 2015
1 parent de96261 commit 64f0fce
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 77 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,9 @@ See [gitlab example](https://github.com/sbadia/vagrant-gitlab/blob/master/exampl
* `gitlab_ensure_postfix`: Whether or not this module should ensure the postfix
package is installed (used to manage conflicts with other modules) (default:
true)
* `exec_path`: PATH of executtion (default: `/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin`)
* `gitlab_manage_rbenv`: Whether this module should use rbenv to install a suitable version of Ruby for the Gitlab user (default: true)
* `gitlab_ruby_version`: Ruby version to install with rbenv for the Gitlab user (default: 2.1.2)
* `exec_path`: PATH of execution (default: ${git\_home}/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin)
* `ldap_enabled`: Enable LDAP backend for gitlab web (see bellow) (default: false)
* `ldap_host`: FQDN of LDAP server (default: ldap.domain.com)
* `ldap_base`: LDAP base dn (default: dc=domain,dc=com)
Expand Down
8 changes: 7 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -186,8 +186,13 @@
# Flags that should be passed to bundler when installing gems
# default: --deployment
#
# [*gitlab_manage_rbenv*]
# Whether this module should use rbenv to install a suitable version of Ruby
# for the Gitlab user; set to false to use the system Ruby or manage separately
# default: true
#
# [*gitlab_ruby_version*]
# Ruby version to install with rbenv for Gitlab user
# Ruby version to install with rbenv for the Gitlab user
# default: 2.1.2
#
# [*exec_path*]
Expand Down Expand Up @@ -351,6 +356,7 @@
$gitlab_bundler_jobs = $gitlab::params::gitlab_bundler_jobs,
$gitlab_ensure_postfix = $gitlab::params::gitlab_ensure_postfix,
$gitlab_ensure_curl = $gitlab::params::gitlab_ensure_curl,
$gitlab_manage_rbenv = $gitlab::params::gitlab_manage_rbenv,
$gitlab_ruby_version = $gitlab::params::gitlab_ruby_version,
$exec_path = $gitlab::params::exec_path,
$ldap_enabled = $gitlab::params::ldap_enabled,
Expand Down
18 changes: 12 additions & 6 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -136,12 +136,18 @@
group => 'root',
require => Exec['setup gitlab database'];
}

file { "${git_home}/gitlab-shell/hooks/update":
ensure => present,
content => template('gitlab/update.erb'),
mode => '0775',
require => File["${git_home}/gitlab-shell/config.yml"],

if ($gitlab_manage_rbenv) {
#gitlab-shell hooks must be updated to use the Ruby version installed by rbenv.
#Use a script because different versions of gitlab-shell have a varying
#set of hooks
$ruby_cmd="${git_home}/.rbenv/shims/ruby"
exec { 'fix ruby paths in gitlab-shell hooks':
command => "ruby -p -i -e '\$_.sub!(/^#!.*ruby\$/,\"#!${ruby_cmd}\")' *",
cwd => "${git_home}/gitlab-shell/hooks",
onlyif => "head -q -n 1 * | egrep -v '^#!${ruby_cmd}\$'",
require => Exec['install gitlab-shell'],
}
}

}
1 change: 1 addition & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
$gitlab_bundler_jobs = 1
$gitlab_ensure_postfix = true
$gitlab_ensure_curl = true
$gitlab_manage_rbenv = true
$gitlab_ruby_version = '2.1.2'
$exec_path = "${git_home}/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
$ldap_enabled = false
Expand Down
71 changes: 37 additions & 34 deletions manifests/setup.pp
Original file line number Diff line number Diff line change
Expand Up @@ -86,40 +86,43 @@
# dev. dependencies
ensure_packages($gitlab::system_packages)

rbenv::install { $git_user:
group => $git_group,
home => $git_home,
}

# By default, puppet-rbenv sets ~/.profile to load rbenv, which is
# read when bash is invoked as an interactive login shell, but we
# also need ~/.bashrc to load rbenv (which is read by interactive
# but non-login shells). This works, but may not be the best
# solution, please see issue #114 if you have a better solution.
file { "${git_home}/.bashrc":
ensure => link,
target => "${git_home}/.profile",
require => Rbenv::Install[$git_user],
}

rbenv::compile { 'gitlab/ruby':
user => $git_user,
group => $git_group,
home => $git_home,
ruby => $gitlab_ruby_version,
global => true,
notify => [
Exec['install gitlab-shell'],
Exec['install gitlab'],
],
}

rbenv::gem { 'charlock_holmes':
ensure => '0.6.9.4',
user => $git_user,
home => $git_home,
ruby => $gitlab_ruby_version,
}
if ($gitlab_manage_rbenv) {
rbenv::install { $git_user:
group => $git_group,
home => $git_home,
}

# By default, puppet-rbenv sets ~/.profile to load rbenv, which is
# read when bash is invoked as an interactive login shell, but we
# also need ~/.bashrc to load rbenv (which is read by interactive
# but non-login shells). This works, but may not be the best
# solution, please see issue #114 if you have a better solution.
file { "${git_home}/.bashrc":
ensure => link,
target => "${git_home}/.profile",
require => Rbenv::Install[$git_user],
}

rbenv::compile { 'gitlab/ruby':
user => $git_user,
group => $git_group,
home => $git_home,
ruby => $gitlab_ruby_version,
global => true,
notify => [
Exec['install gitlab-shell'],
Exec['install gitlab'],
],
}

#Gitlab <= 6.3 requires us to install the charlock_holmes gem
rbenv::gem { 'charlock_holmes':
ensure => '0.6.9.4',
user => $git_user,
home => $git_home,
ruby => $gitlab_ruby_version,
}
} #end if ($gitlab_manage_rbenv)

# other packages
if $gitlab_ensure_curl {
Expand Down
18 changes: 16 additions & 2 deletions spec/classes/gitlab_install_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,14 @@
'Gitlab::Config::Resque[gitlab]']
)}
end # pgsql
it { should contain_file('/home/git/gitlab-shell/hooks/update').with_content(/^#!\/home\/git\/.rbenv\/shims\/ruby$/)}
it { should contain_exec('fix ruby paths in gitlab-shell hooks').with(
:user => 'git',
:path => '/home/git/.rbenv/shims:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin',
:command => 'ruby -p -i -e \'$_.sub!(/^#!.*ruby$/,"#!/home/git/.rbenv/shims/ruby")\' *',
:cwd => '/home/git/gitlab-shell/hooks',
:onlyif => 'head -q -n 1 * | egrep -v \'^#!/home/git/.rbenv/shims/ruby$\'',
:require => 'Exec[install gitlab-shell]'
)}
end # install gitlab
describe 'setup gitlab database' do
it { is_expected.to contain_exec('setup gitlab database').with(
Expand Down Expand Up @@ -283,7 +290,14 @@
'Gitlab::Config::Resque[gitlab]']
)}
end # pgsql
it { should contain_file("#{params_set[:git_home]}/gitlab-shell/hooks/update").with_content(/^#!#{params_set[:git_home]}\/.rbenv\/shims\/ruby$/)}
it { should contain_exec('fix ruby paths in gitlab-shell hooks').with(
:user => params_set[:git_user],
:path => params_set[:exec_path],
:command => "ruby -p -i -e '$_.sub!(/^#!.*ruby$/,\"#!#{params_set[:git_home]}/.rbenv/shims/ruby\")' *",
:cwd => "#{params_set[:git_home]}/gitlab-shell/hooks",
:onlyif => "head -q -n 1 * | egrep -v '^#!#{params_set[:git_home]}/.rbenv/shims/ruby$'",
:require => 'Exec[install gitlab-shell]'
)}
end # install gitlab
describe 'setup gitlab database' do
it { is_expected.to contain_exec('setup gitlab database').with(
Expand Down
34 changes: 14 additions & 20 deletions spec/classes/gitlab_setup_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
:git_comment => 'Labfooboozoo',
:git_email => 'gitlab@fooboozoo.fr',
:git_proxy => 'http://proxy.fooboozoo.fr:3128',
:gitlab_ruby_version => '2.0.0'
:gitlab_ruby_version => '2.0.0',
:gitlab_manage_rbenv => false,
}
end

Expand Down Expand Up @@ -77,22 +78,9 @@
end
context 'with specific params' do
let(:params) { params_set }
it { is_expected.to contain_rbenv__install(params_set[:git_user]).with(
:group => params_set[:git_user],
:home => params_set[:git_home]
)}
it { is_expected.to contain_file('/srv/gitlab/.bashrc').with(
:ensure => 'link',
:target => '/srv/gitlab/.profile',
:require => 'Rbenv::Install[gitlab]'
)}
it { is_expected.to contain_rbenv__compile('gitlab/ruby').with(
:user => params_set[:git_user],
:home => params_set[:git_home],
:ruby => '2.0.0',
:global => true,
:notify => ['Exec[install gitlab-shell]', 'Exec[install gitlab]']
)}
it { is_expected.not_to contain_rbenv__install(params_set[:git_user]) }
it { is_expected.not_to contain_file('/srv/gitlab/.bashrc') }
it { is_expected.not_to contain_rbenv__compile('gitlab/ruby') }
end
end

Expand Down Expand Up @@ -155,9 +143,15 @@
end
#### Gems (all dist.)
describe 'commons gems' do
it { is_expected.to contain_rbenv__gem('charlock_holmes').with(
:ensure => '0.6.9.4'
)}
context 'with default params' do
it { is_expected.to contain_rbenv__gem('charlock_holmes').with(
:ensure => '0.6.9.4'
)}
end
context 'with specific params' do
let(:params) { params_set }
it { is_expected.not_to contain_rbenv__gem('charlock_holmes') }
end
end
#### Commons packages (all dist.)
describe 'commons packages' do
Expand Down
13 changes: 0 additions & 13 deletions templates/update.erb

This file was deleted.

0 comments on commit 64f0fce

Please sign in to comment.