Deploying Rails Apps with Chef and Capistrano

Jul. 26, 2013

More Related Content


Deploying Rails Apps with Chef and Capistrano

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