Chef & rvm

Is anyone using chef with rvm to install and manage multiple rubies and gemsets on their servers?

John


John Merrells
http://johnmerrells.com
+1.415.244.5808

Just for the record, I've got this working quite nicely. Here's what I did...

I wrote a simple cookbook to install rvm and some rubies.

============================================================
include_recipe("zlib") # for rvm
package 'curl' # for ree
package 'libreadline5-dev' # for ree

cookbook_file "/root/.bashrc" do
source "bashrc"
mode "0644"
end

cookbook_file "/root/.profile" do
source "profile"
mode "0644"
end

to update

rvm update --head

bash "install rvm" do
environment "HOME"=>"/root"
code <<-EOH
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
EOH
not_if { ::FileTest.exists?("/usr/local/rvm") } # JCM check version
end

bash "install ruby 1.8.7" do
environment "HOME"=>"/root"
code <<-EOH
source '/usr/local/rvm/scripts/rvm'
rvm install ruby-1.8.7-p299
rvm 1.8.7 gem install bundler --no-ri --no-rdoc
EOH
not_if { ::FileTest.exists?("/usr/local/bin/rvm/rubies/ruby-1.8.7-p299") }
end

bash "install ruby enterprise edition 1.8.7" do
environment "HOME"=>"/root"
code <<-EOH
source '/usr/local/rvm/scripts/rvm'
rvm install ree-1.8.7-2010.02
rvm ree gem install bundler --no-ri --no-rdoc
EOH
not_if { ::FileTest.exists?("/usr/local/bin/rvm/rubies/ree-1.8.7-2010.02") }
end

Since I'm using bundler I did't really have any gem_package calls,
which I thought would be the biggest challenge here. So, now I call
bundler like this....

============================================================
execute "bundle_install" do
command "rvm ree;bundle install"
end

...and then I'm using runit to spin up my ruby daemon, so the run
script changed to....

============================================================
#!/bin/bash
source '/usr/local/rvm/scripts/rvm'
rvm use ree
exec 2>&1
exec /usr/bin/env my_ruby_daemon

...now I can switch between rubies super easily, and all the ruby install and
setup work is done by rvm, rather than chef, so those {ruby|rails|passenger}
_enterprise cookbooks can go away, and now I can play with rubinious,
1.9.2, rails30, without worrying about messing up my environment.

John

On Jul 14, 2010, at 2:21 PM, John Merrells wrote:

Is anyone using chef with rvm to install and manage multiple rubies and gemsets on their servers?

John

--
John Merrells
http://johnmerrells.com
+1.415.244.5808

--
John Merrells

+1.415.244.5808

Hi,
I'll look forward to examining your rvm commands, to see where they
might be better than whats already in my rvm recipe.

Wouldn't really recommend using rvm head (yet) in production servers
because it can get broken pretty easily. This is a big reason why
people tend to prefer the standard opscode ree recipe. I've encouraged
Wayne to tag "more stable" commits with a stable release. And hoping
that Wayne will eventually just slow down the pace of it, and so
freezing certain features of rvm.

As for hardcoding the ruby versions into the cookbook, its reasonably
terse, but lacks a certain flexibility. One thing I have yet to do in
my rvm cookbook is to write a resource-provider for rvm rubies. Still
working on the syntax which is in need of some improvement...

rvm_rubies do
ruby :identifier => :default do
ruby_version = "ree"
flags << "--reconfigure" << "--jit"

patches = []
configure_flags = %w[]
compiler_flags = %w[]

ree_options = ""

update = true
update_rubygems = false

force_install = true

before do
  # some custom steps, like editing setup.rb ?
end

end

ruby :identifier => :ruby2 do
# ...
end
end

For example, Rvm has a concept of the "default" ruby, so in the above
example, the :identifier resource attribute string is checked to see
if its been set to :default. That seems a bit flowery and might get
dropped in favour of

rvm_ruby "ree" do
default = true
ruby_version = "ree"
flags << "--reconfigure" << "--jit"
# other rvm configuration options...
end

It would be nice to look further into customizing the setup.rb script
too. Haven't figured that out yet either. Currently my rvm recipe uses
a whole bunch of cookbook attributes to set all these things. It will
take some time to switch that over to a resource-provider model.

Previously, it was just going to be a simple array of rubies to
install like: ["ree","1.9.1"], etc.

On Thu, Jul 15, 2010 at 2:49 AM, John Merrells john@merrells.com wrote:

Just for the record, I've got this working quite nicely. Here's what I did...

I wrote a simple cookbook to install rvm and some rubies.

============================================================
include_recipe("zlib") # for rvm
package 'curl' # for ree
package 'libreadline5-dev' # for ree

cookbook_file "/root/.bashrc" do
source "bashrc"
mode "0644"
end

cookbook_file "/root/.profile" do
source "profile"
mode "0644"
end

to update

rvm update --head

bash "install rvm" do
environment "HOME"=>"/root"
code <<-EOH
bash < <( curl http://rvm.beginrescueend.com/releases/rvm-install-head )
EOH
not_if { ::FileTest.exists?("/usr/local/rvm") } # JCM check version
end

bash "install ruby 1.8.7" do
environment "HOME"=>"/root"
code <<-EOH
source '/usr/local/rvm/scripts/rvm'
rvm install ruby-1.8.7-p299
rvm 1.8.7 gem install bundler --no-ri --no-rdoc
EOH
not_if { ::FileTest.exists?("/usr/local/bin/rvm/rubies/ruby-1.8.7-p299") }
end

bash "install ruby enterprise edition 1.8.7" do
environment "HOME"=>"/root"
code <<-EOH
source '/usr/local/rvm/scripts/rvm'
rvm install ree-1.8.7-2010.02
rvm ree gem install bundler --no-ri --no-rdoc
EOH
not_if { ::FileTest.exists?("/usr/local/bin/rvm/rubies/ree-1.8.7-2010.02") }
end

Since I'm using bundler I did't really have any gem_package calls,
which I thought would be the biggest challenge here. So, now I call
bundler like this....

============================================================
execute "bundle_install" do
command "rvm ree;bundle install"
end

...and then I'm using runit to spin up my ruby daemon, so the run
script changed to....

============================================================
#!/bin/bash
source '/usr/local/rvm/scripts/rvm'
rvm use ree
exec 2>&1
exec /usr/bin/env my_ruby_daemon

...now I can switch between rubies super easily, and all the ruby install and
setup work is done by rvm, rather than chef, so those {ruby|rails|passenger}
_enterprise cookbooks can go away, and now I can play with rubinious,
1.9.2, rails30, without worrying about messing up my environment.

John

On Jul 14, 2010, at 2:21 PM, John Merrells wrote:

Is anyone using chef with rvm to install and manage multiple rubies and gemsets on their servers?

John

--
John Merrells
http://johnmerrells.com
+1.415.244.5808

--
John Merrells
http://johnmerrells.com
+1.415.244.5808