Guided Exploration
Deploying Rails apps with Chef and Capistrano
Dan Ivovich
BohConf Baltimore 2013
7/19/2013
Dan Ivovich
http://smartlogic.io
Twitter - @danivovich
Dan Ivovich on GitHub
Director, Development Operations
SmartLogic
What is the goal?
● Build a machine that can run the application
● Do so quickly and repeatedly
● Make deploying the app, ...
How?
● Chef - Infrastructure Management
● Capistrano - Application Deployment
Who does what?
● Chef
○ Users / SSH Keys
○ Web server
○ Database
○ Postfix
○ Redis / Memcached
○ Monit
○ NewRelic Server m...
Who does what?
● Capistrano
○ Virtual Hosts
○ Unicorn init.d script
○ Unicorn.rb
○ Monit process monitors
○ Normal Capistr...
Why both?
● Use each for what it is best at
● Chef is for infrastructure
● Capistrano is for the app
● Could have more tha...
How? - Chef
● Standard Recipes
● Custom Recipes
● Recipes assigned to Roles
● Roles assigned to Nodes
● Nodes with attribu...
How? - Capistrano
● Standard Tasks
● Custom Tasks
● Templating files
To The Code!
git clone git@github.com:smartlogic/chef-cap-
demo.git
See the README or follow along the following git tags
git checkout rails_app
Basic Rails Application
1. Displays some data from a database, includes a
rake task to add some data to the database
2. No...
git checkout meet_the_chef
Basic Chef Configuration
1. Web Server
2. Database Server
3. Dependencies
4. Nothing application specific
git checkout app_cookbook
Application Cookbook
1. User account to run the application as
2. Folder structure to store the application
3. Application...
git checkout cap_setup
Capistrano Setup
1. Virtual hosts configuration
2. Unicorn configuration
3. Monit configuration
4. Application setup (link...
git checkout cap_data
Capistrano Tasks
1. Simple to expose your rake tasks as capistrano
tasks
2. This task helps us see the impact of running a...
From the top!
Ready?!? Here we go!
1. vagrant destroy
2. vagrant up
3. bundle exec knife bootstrap -p 2222 -x vagrant
 -d precise32_vagr...
Thoughts....
● Vagrant and VMs are you friend. Rinse and repeat
● It is ok to tweak your Chef stuff and re-cook, but I alw...
Questions?
http://smartlogic.io
http://twitter.com/smartlogic
http://github.com/smartlogic
http://fb.me/smartlogic
Upcoming SlideShare
Loading in …5
×

Deploying Rails Apps with Chef and Capistrano

7,813 views

Published on

A walkthrough of how to deploy rails apps with Chef and Capistrano, from SmartLogic's Dan Ivovich at BohConf 2013.

Published in: Technology, Self Improvement

Deploying Rails Apps with Chef and Capistrano

  1. 1. Guided Exploration Deploying Rails apps with Chef and Capistrano Dan Ivovich BohConf Baltimore 2013 7/19/2013
  2. 2. Dan Ivovich http://smartlogic.io Twitter - @danivovich Dan Ivovich on GitHub Director, Development Operations SmartLogic
  3. 3. 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
  4. 4. How? ● Chef - Infrastructure Management ● Capistrano - Application Deployment
  5. 5. 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)
  6. 6. Who does what? ● Capistrano ○ Virtual Hosts ○ Unicorn init.d script ○ Unicorn.rb ○ Monit process monitors ○ Normal Capistrano Stuff
  7. 7. 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
  8. 8. How? - Chef ● Standard Recipes ● Custom Recipes ● Recipes assigned to Roles ● Roles assigned to Nodes ● Nodes with attributes to tailor the install
  9. 9. How? - Capistrano ● Standard Tasks ● Custom Tasks ● Templating files
  10. 10. To The Code!
  11. 11. git clone git@github.com:smartlogic/chef-cap- demo.git See the README or follow along the following git tags
  12. 12. git checkout rails_app
  13. 13. 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
  14. 14. git checkout meet_the_chef
  15. 15. Basic Chef Configuration 1. Web Server 2. Database Server 3. Dependencies 4. Nothing application specific
  16. 16. git checkout app_cookbook
  17. 17. 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
  18. 18. git checkout cap_setup
  19. 19. Capistrano Setup 1. Virtual hosts configuration 2. Unicorn configuration 3. Monit configuration 4. Application setup (linking database.yml)
  20. 20. git checkout cap_data
  21. 21. 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
  22. 22. From the top!
  23. 23. 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
  24. 24. 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
  25. 25. Questions? http://smartlogic.io http://twitter.com/smartlogic http://github.com/smartlogic http://fb.me/smartlogic

×