Skip to content

Commit

Permalink
Update cookbooks to make everything work again, faster and including …
Browse files Browse the repository at this point in the history
…new rubies
  • Loading branch information
jeroenvandijk committed Feb 26, 2011
1 parent c45f25c commit 5fc70a1
Show file tree
Hide file tree
Showing 8 changed files with 107 additions and 41 deletions.
Binary file added cookbooks/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion cookbooks/rails_test_databases/recipes/postgres.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
require_recipe "postgresql"
require_recipe "postgresql::server"

execute "Create postgres vagrant user" do
user "postgres"
Expand Down
20 changes: 14 additions & 6 deletions cookbooks/rails_test_gems/definitions/setup_rails_gems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,23 @@
# a command that run against all rubies versions like RVM does.
define :setup_rails_gems do
Chef::Log.info "Setting up gems for Rails"

# Update rubygems, for bundler
execute "gem update --system"

gem_package "bundler"
gem_package "rake"

home = "/home/vagrant"

%w(bundler rake rb-inotify).each do |gem_name|
execute "Run bundle install for rails" do
command "gem install #{gem_name}"
user "vagrant"
cwd home
end
end

# We need the following for the pg gem
package "libpq-dev"

# FIXME Need to correct the permissions on the .gem dir
execute "chown -R vagrant:vagrant #{home}/.gem"

execute "Run bundle install for rails" do
command "bundle install"
cwd "#{home}/rails"
Expand Down
6 changes: 3 additions & 3 deletions cookbooks/rvm/definitions/rvm_default.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
define :rvm_default do
ruby_version = RVM.ruby_version params[:name]
rvm_ruby = RVM::Ruby.new params[:name]

# rvm_default
execute "set ruby #{ruby_version} as default" do
execute "set ruby #{rvm_ruby.version} as default" do
user "vagrant"
command "/home/vagrant/.rvm/bin/rvm --default #{ruby_version}"
command "/home/vagrant/.rvm/bin/rvm --default #{rvm_ruby.version}"
end

end
37 changes: 14 additions & 23 deletions cookbooks/rvm/definitions/rvm_install.rb
Original file line number Diff line number Diff line change
@@ -1,29 +1,20 @@
define :rvm_install do
ruby_version = RVM.ruby_version params[:name]

require_recipe "java" if ruby_version =~ /^jruby/

package "libreadline5-dev" if ruby_version =~ /^ree/

require_recipe "mono" if ruby_version =~ /^ironruby/

execute "install ruby #{ruby_version}" do
user node[:rvm][:user]
command "#{node[:rvm][:bin]}/rvm install #{ruby_version}"
not_if "ls #{node[:rvm][:home]}/rubies | grep #{ruby_version}"
rvm_ruby = RVM::Ruby.new params[:name]

rvm_ruby.recipes.each do |recipe|
require_recipe recipe
end

rvm_use ruby_version
rvm_ruby.packages.each do |pkg|
package pkg
end

if ruby_version =~ /^ruby/
# part of the rvm_install is the open ssl recompilation (from http://cjohansen.no/en/ruby/ruby_version_manager_ubuntu_and_openssl)
package "libssl-dev"

# FIXME the command below does not work if the patch version is not added to the ruby version, e.g. ruby-1.8.7 or ruby-1.9.2 will give an error
execute "Fix install openssl for RVM #{ruby_version}" do
user "vagrant"
command "cd #{node[:rvm][:home]}/src/#{ruby_version}/ext/openssl && ruby extconf.rb && make install"
not_if { File.exist?("#{node[:rvm][:home]}/.rvm/rubies/#{ruby_version}/lib/ruby/site_ruby/1.8/openssl") } # does not work for 1.9.1
end
execute "install ruby #{rvm_ruby.version}" do
user node[:rvm][:user]
command "#{node[:rvm][:bin]}/rvm install #{rvm_ruby.version}"
not_if "ls #{node[:rvm][:home]}/rubies | grep #{rvm_ruby.version}"
end

rvm_use rvm_ruby.version

end
6 changes: 3 additions & 3 deletions cookbooks/rvm/definitions/rvm_use.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
define :rvm_use do
ruby_version = RVM.ruby_version params[:name]
rvm_ruby = RVM::Ruby.new params[:name]

rvm_default ruby_version # FIXME shouldn't be necessary
rvm_default rvm_ruby.version # FIXME shouldn't be necessary

# The following code has been inspired from Chef's Adam Jacob http://gist.github.com/336951
ruby_block "/home/vagrant/.rvm/bin/rvm use #{ruby_version}" do
ruby_block "/home/vagrant/.rvm/bin/rvm use #{rvm_ruby.version}" do
block do
Chef::Mixin::Command.popen4(%{
bash -l -c "rvm_path=#{node[:rvm][:home]} &&
Expand Down
75 changes: 72 additions & 3 deletions cookbooks/rvm/libraries/rvm.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,74 @@
class RVM
def self.ruby_version(name)
name.strip =~ /^\d/ ? "ruby-#{name}" : name
module RVM
class Ruby
attr_accessor :name

def initialize(name)
@name = name
end

# Based on `rvm notes`, make sure you run it on the environment you are
# targetting. This is just targetted at ubuntu. Would be better if we could
# get this list easily by running a rvm command.
def packages
mri_packages = %w(build-essential bison openssl libreadline6 libreadline6-dev curl git-core
zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev
sqlite3 libxml2-dev libxslt1-dev autoconf libc6-dev)

if ree? || mri?
mri_packages
elsif ruby_head?
mri_packages + %w(subversion)
elsif jruby_head?
%w(ant openjdk-6-jdk)
elsif jruby?
%w(g++ openjdk-6-jre-headless)
elsif ironruby?
%w(mono-2.0-devel)
else
[]
end
end

def recipes
if jruby?
%w(java)
else
[]
end
end

def version
name.strip =~ /^\d/ ? "ruby-#{name}" : name
end

def mri?
version =~ /^ruby/
end

def requires_java?
version =~ /^jruby/
end

def ree?
version =~ /^ree/
end

def ironruby?
version =~ /^ironruby/
end

def ruby_head?
version =~ /^ruby-head$/
end

def jruby_head?
version =~ /^jruby-head$/
end

def jruby?
version =~ /^jruby/
end

end

end
2 changes: 0 additions & 2 deletions cookbooks/vagrant_main/recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@

require_recipe "rvm"

# require_recipe "rails_test_gems"

node[:rubies].each do |version|
rvm_install version
setup_rails_gems
Expand Down

0 comments on commit 5fc70a1

Please sign in to comment.