RSS Feed!

Archives

Chef + RVM + Capistrano + Bundler

So I have spent some time this past week getting some server automation setup.  We’re deploying our new app in the cloud (on EC2) and I wanted to make sure that we could bring new servers online quickly are reliably, I also like knowing that all of my server configuration is kept safely in source control.

Here is what I setup:

Chef: Configuration management and server deployment.

RVM: Install and manage multiple versions of Ruby.

Capistrano: Ruby on Rails app deployment.

Bundler: Manage Ruby gem dependancies.

And some extras: Nagios to monitor everything, rsyslog for a central log store, and a Hudson CI server (I’ll get more into that in a later post).

All to run a Ruby on Rails app, on Apache HTTP with REE and Passenger.

The first step for me was installing a Chef server.  I turned up a new EC2 small instance with a base Ubuntu 10.04LTS image and followed the directions found here: http://wiki.opscode.com/display/chef/Package+Installation+on+Debian+and+Ubuntu.

Once the Chef server was up and running and I had setup my laptop with knife, it was time to start cooking.

Opscode has a good selection of cookbooks ready for you to use and adapt to your needs, but my first cookbook,for RVM, actually came from http://www.agileweboperations.com/chef-rvm-ruby-enterprise-edition-as-default-ruby/.  Matthias did a great job documenting his RVM with REE cookbook, the only thing I added was ‘–passenger’ to the ‘rvm install ree’ line.

bash "install REE in RVM" do
user "root"
code "rvm install ree --passenger"
not_if "rvm list | grep ree"
end

Now that I had my first cookbook I was eager to try a knife EC2 cloud deployment.  First, I setup a new role so that I would have something to place in the servers run list.

#roles/web.rb
#Chef Role for web servers

name "web"
description "Swingpal Web Server Role"
run_list("recipe[rvm]")

Then to save this role to your Chef server:

knife role from file roles/web.rb

Now my Chef server had a role, and it was time to make sure that it also had the cookbooks it needed.  You might have noticed that the RVM cookbook required ‘build-essential’.  In order to get those cookbooks I needed to:

knife cookbook site download build-essential

Now you I had the build-essential cookbook added to my Chef repository.  Next I uploaded my cookbooks to the Chef server.

knife cookbook upload build-essential rvm

Now it was time to launch and configure a new EC2 instance.  This is where the magic happens, a base Ubuntu install becomes a server with Chef client, registers with the Chef server and receives instruction on how to configure itself.

knife ec2 server create -G web,production,monitoring --flavor m1.small -i ami-6c06f305 -x ubuntu 'role[production]' 'role[web]' 'role[monitored]' -Z us-east-1c -S mykey

I’ll walk through the various pieces of the knife EC2 server create:

  • knife ec2 server create – the command to create a new EC2 instance
  • -G web,produciton, monitoring – these are the EC2 security groups that the instance will belong to, they need to exist already on your EC2 account or the launch will fail
  • –flavor m1.small – this is the type of EC2 server instance, in my case m1.small which costs $0.085/hour
  • -i ami-6c06f305 – this tells EC2 which AMI (Amazon Machine Image) you would like to start with, in this case it is an Ubuntu 32bit image – you can find all of the available Ubuntu AMIs http://uec-images.ubuntu.com/releases/lucid/release/

This is a good stopping point, I’ll continue my description of our setup in the next post.

Share and Enjoy:
  • Print
  • Digg
  • StumbleUpon
  • del.icio.us
  • Facebook
  • Yahoo! Buzz
  • Twitter
  • Google Bookmarks
  • Google Buzz
  • HackerNews
  • Identi.ca
  • LinkedIn
  • Reddit

Tags: , , , , , , ,

By | 22. Oct 2010 | Technology | 2 Comments »

2 Comments

  1. skrewler says:

    Just found your blog and enjoy it. Just thought I’d mention that your page seems to be rendering oddly on Firefox 3.6.12 on Mac OS X 10.6. There’s no left margin. It looks okay in Chrome tho.

    http://img710.imageshack.us/img710/9971/screenshot20101224at714.png

  2. admin says:

    Thanks for the comment, I think that is how the page is supposed to look.

Leave a Reply