EC2 for Rails Deployment

Nick Plante, NH.rb

November 16, 2009

Once Upon A Time...

Deploying Ruby Web Apps was a Pain in the Ass.

Modern Conveniences

Make VPS Deployment much easier:


Apache / Passenger, Capistrano, GitHub, Hoptoad

Capistrano

Manage remote servers and automate remote tasks

  • Deploy versioned code from source control
  • Back up old versions (for roll-back)
  • Migrate database (optional)
  • Link shared assets, etc. Whatever you want!

Get Capistrano!


  • gem install capistrano
  • cd your-rails-app
  • capify .

edit config/deploy.rb

  • cap deploy:setup
  • cap deploy:cold
  • cap deploy
  • cap -T

* Remember to set up your ssh keys if deploying from GitHub!

This all makes deployment much more palatable.


And yet...

Provisioning servers still takes time.


Configuring servers / services still takes time.


Horizontal scaling takes a lot of time, money, effort.

Amazon Elastic Compute Cloud

Enter: The Cloud (EC2)


  • Fire up a server with no waiting period.
  • Deploy a working systems image (AMI).
  • Scale at will, on-demand. Pay for what you use.
  • Plug in other AWS pieces (S3, EBS, ELB).

Complaints?

It's not "Easy to Use"


  • Tools like ElasticFox help
  • But what we really need is scriptability (!)

Ruby tools (surprise) make this easier




Also: see commercial offerings like RightScale, Scalr.

Rubber

  • Extends Capistrano
  • Support for roles
  • Horizontally scale up and down
    • Single instance with everything
    • Or deploy roles to separate instances
  • Baked-in redundancy
    • (cuz instances can disappear)

Installing Rubber

gem install rubber


  • Sign up for EC2, get keypair
    • Optionally set up rubber-secret.yml
    • Rubber sets up EC2 security groups

Vulcanize!

script/generate vulcanize complete_passenger_mysql


  • Edit config/rubber/rubber.yml
    • Add keys, account info
    • List system packages, gems to install
    • Dynamic DNS config, etc

Create an Instant Staging Instance


  • cap rubber:create
  • cap rubber:bootstrap
  • cap deploy
  • or...

cap rubber:create_staging

Use RAILS_ENV to support multiple staging instances


  • cp config/environments/production.rb config/environments/nick.rb
  • RUBBER_ENV=nick cap rubber:create_staging

Surf to http://nick.mydomain.com

Rubber Admin Server


Web Admin UIs for Monit / HAProxy

Check server stats (Munin)


  • ALIAS=tools ROLES=web_tools cap rubber:create
  • cap rubber:bootstrap
  • cap deploy
  • visit http://tools.mydomain.com:8080

Time to scale up?

Add an app server to handle increased load

Roles in default templates can scale by default


  • ALIAS=app02 ROLES=app cap rubber:create
  • cap rubber:bootstrap
  • cap deploy

Further Customization

Create custom roles (need background queue / workers?)

Config files are just ERB templates


More information at the Rubber Wiki

Insert Demo Here.

Thanks


Rubber was created by Matt Conway


Questions?

@zapnap