What is the goal?
● Build a machine that can run the application
● Do so quickly and repeatedly
● Make deploying the app, upgrading
components, adding components, etc seamless
and easy
Who does what?
● Chef
○ Users / SSH Keys
○ Web server
○ Database
○ Postfix
○ Redis / Memcached
○ Monit
○ NewRelic Server monitoring
○ /etc/hosts
○ rbenv & Ruby
○ Binary dependencies (e.g. Sphinx)
Who does what?
● Capistrano
○ Virtual Hosts
○ Unicorn init.d script
○ Unicorn.rb
○ Monit process monitors
○ Normal Capistrano Stuff
Why both?
● Use each for what it is best at
● Chef is for infrastructure
● Capistrano is for the app
● Could have more than one Capistrano app with
the same Chef config
● Chef config changes infrequently, Capistrano
config could change more frequently
How? - Chef
● Standard Recipes
● Custom Recipes
● Recipes assigned to Roles
● Roles assigned to Nodes
● Nodes with attributes to tailor the install
Basic Rails Application
1. Displays some data from a database, includes a
rake task to add some data to the database
2. No deployment code of any kind at this point
Application Cookbook
1. User account to run the application as
2. Folder structure to store the application
3. Application specific dependencies
4. rbenv
5. The application database
Capistrano Tasks
1. Simple to expose your rake tasks as capistrano
tasks
2. This task helps us see the impact of running a deploy
3. Easy to insert into the capistrano execution chain
Ready?!? Here we go!
1. vagrant destroy
2. vagrant up
3. bundle exec knife bootstrap -p 2222 -x vagrant
-d precise32_vagrant chef_cap_demo
4. bundle exec knife cook
vagrant@chef_cap_demo
5. cap staging deploy:setup deploy:migrations
Thoughts....
● Vagrant and VMs are you friend. Rinse and repeat
● It is ok to tweak your Chef stuff and re-cook, but I always
like to restart with a fresh VM once I think I'm done
● Capistrano tweaks should be easy to apply, especially with
tasks like nginx:setup, unicorn:setup etc.
● Chef issues are harder to debug and more frustrating than
Capistrano issues, another reason to put more app specific
custom stuff in Capistrano and do standard things in Chef