From c9b8bb78976bcde579d394ef89444acb3a7beaf4 Mon Sep 17 00:00:00 2001 From: Kevin Lamontagne Date: Tue, 18 Jun 2013 13:08:57 -0400 Subject: [PATCH] Use rbenv for ruby --- attributes/default.rb | 15 ++++----- metadata.rb | 2 +- recipes/default.rb | 73 +++++++++++++++++++++---------------------- 3 files changed, 43 insertions(+), 47 deletions(-) diff --git a/attributes/default.rb b/attributes/default.rb index 229c41d..4c0e60d 100644 --- a/attributes/default.rb +++ b/attributes/default.rb @@ -40,7 +40,6 @@ case node['platform'] when "ubuntu","debian" default['gitlab']['packages'] = %w{ - ruby1.9.1 ruby1.9.1-dev ri1.9.1 libruby1.9.1 curl wget checkinstall libxslt-dev libsqlite3-dev libcurl4-openssl-dev libssl-dev libmysql++-dev libicu-dev libc6-dev libyaml-dev nginx python python-dev @@ -62,7 +61,6 @@ end else default['gitlab']['packages'] = %w{ - ruby1.9.1 ruby1.9.1-dev ri1.9.1 libruby1.9.1 curl wget checkinstall libxslt-dev libsqlite3-dev libcurl4-openssl-dev libssl-dev libmysql++-dev libicu-dev libc6-dev libyaml-dev nginx python @@ -72,13 +70,7 @@ default['gitlab']['trust_local_sshkeys'] = "yes" -# Problems deploying this on RedHat provided rubies. -case node['platform'] -when "redhat","centos","scientific","amazon" - default['gitlab']['install_ruby'] = "1.9.2-p290" -else - default['gitlab']['install_ruby'] = "package" -end +default['gitlab']['install_ruby'] = "1.9.3-p429" default['gitlab']['https'] = false default['gitlab']['ssl_certificate'] = "/etc/nginx/#{node['fqdn']}.crt" @@ -90,3 +82,8 @@ # workers for puma "cluster mode", see config/puma.rb default['gitlab']['puma_wokers'] = 0 + +# rbenv +node.default['rbenv']['user_installs'] = [ + { 'user' => default['gitlab']['user'] } +] diff --git a/metadata.rb b/metadata.rb index d5fbe79..3fd5e2c 100644 --- a/metadata.rb +++ b/metadata.rb @@ -8,7 +8,7 @@ %w{ gitolite nginx }.each do |cb_conflict| conflicts cb_conflict end -%w{ yumrepo ruby_build git redisio build-essential python readline sudo openssh perl xml zlib database mysql postgresql }.each do |cb_depend| +%w{ yumrepo ruby_build rbenv git redisio build-essential python readline sudo openssh perl xml zlib database mysql postgresql }.each do |cb_depend| depends cb_depend end %w{ redhat centos scientific amazon debian ubuntu }.each do |os| diff --git a/recipes/default.rb b/recipes/default.rb index 08ebffc..f9661a8 100644 --- a/recipes/default.rb +++ b/recipes/default.rb @@ -35,26 +35,6 @@ to "/usr/local/bin/redis-cli" end -# There are problems deploying on Redhat provided rubies. -# We'll use Fletcher Nichol's slick ruby_build cookbook to compile a Ruby. -if node['gitlab']['install_ruby'] !~ /package/ - ruby_build_ruby node['gitlab']['install_ruby'] - - # Drop off a profile script. - template "/etc/profile.d/gitlab.sh" do - owner "root" - group "root" - mode 0755 - variables( - :fqdn => node['fqdn'], - :install_ruby => node['gitlab']['install_ruby'] - ) - end - - # Set PATH for remainder of recipe. - ENV['PATH'] = "/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/usr/local/ruby/#{node['gitlab']['install_ruby']}/bin" -end - # Install required packages for Gitlab node['gitlab']['packages'].each do |pkg| package pkg @@ -65,12 +45,6 @@ action :install end -# Install required Ruby Gems for Gitlab -%w{ charlock_holmes bundler }.each do |gempkg| - gem_package gempkg do - action :install - end -end # Install pygments from pip python_pip "pygments" do @@ -97,6 +71,31 @@ members node['gitlab']['user'] end +# setup rbenv (after git user setup) +%w{ ruby_build rbenv::user_install }.each do |requirement| + include_recipe requirement +end + +# Install appropriate Ruby with rbenv +rbenv_ruby node['gitlab']['install_ruby'] do + action :install + user node['gitlab']['user'] +end + +# Set as the rbenv default ruby +rbenv_global node['gitlab']['install_ruby'] do + user node['gitlab']['user'] +end + +# Install required Ruby Gems for Gitlab (via rbenv) +%w{ charlock_holmes bundler }.each do |gempkg| + rbenv_gem gempkg do + action :install + user node['gitlab']['user'] + rbenv_version node['gitlab']['install_ruby'] + end +end + # Create a $HOME/.ssh folder directory "#{node['gitlab']['home']}/.ssh" do owner node['gitlab']['user'] @@ -204,6 +203,17 @@ ) end +without_group = node['gitlab']['database']['type'] == 'mysql' ? 'postgres' : 'mysql' + +# Install Gems with bundle install +execute "gitlab-bundle-install" do + command "bundle install --without development test #{without_group} --deployment" + cwd node['gitlab']['app_home'] + user node['gitlab']['user'] + group node['gitlab']['group'] + environment({ 'LANG' => "en_US.UTF-8", 'LC_ALL' => "en_US.UTF-8" }) + not_if { File.exists?("#{node['gitlab']['app_home']}/vendor/bundle") } +end # Setup the database case node['gitlab']['database']['type'] when 'mysql' @@ -239,17 +249,6 @@ ) end -without_group = node['gitlab']['database'] == 'mysql' ? 'postgres' : 'mysql' - -# Install Gems with bundle install -execute "gitlab-bundle-install" do - command "bundle install --without development test #{without_group} --deployment" - cwd node['gitlab']['app_home'] - user node['gitlab']['user'] - group node['gitlab']['group'] - environment({ 'LANG' => "en_US.UTF-8", 'LC_ALL' => "en_US.UTF-8" }) - not_if { File.exists?("#{node['gitlab']['app_home']}/vendor/bundle") } -end # Setup sqlite database for Gitlab execute "gitlab-bundle-rake" do