Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Joy of Cooking: Whip up a Rails Environment with Chef

The Joy of Cooking: Whip up a Rails Environment with Chef

You've heard of Chef, Puppet, and other frameworks that can help you build out your infrastructure. You've been meaning to play around with one or more of them for some time now. Now's your chance; Start cooking up on your own servers!

In this tutorial, we'll provide an introduction to Chef with a focus on what you'll need to know to get a Rails application up and running.

Topics include:

* Introduction to Chef
* Provisioning an environment for a Rails application
* Deploying with Capistrano

You won't be ready to compete in Iron Chef, but you will be ready to serve up your own Rails environment in no time.

Nathen Harvey

April 03, 2012
Tweet

More Decks by Nathen Harvey

Other Decks in Technology

Transcript

  1. The Joy of Cooking Whip up a Rails Environment with

    Chef Nathen Harvey, CustomInk.com @nathenharvey https://github.com/nathenharvey/cooking-with-chef @nathenharvey 1
  2. Agenda •  Infrastructure as Code •  Introduction to Chef • 

    Building a project in Chef •  Provision a server for your Rails App •  Additional resources @nathenharvey 2
  3. Infrastructure as Code •  Enable the reconstruction of the business

    from nothing but –  a source code repository –  an application data backup –  and bare metal resources –  Jesse Robins, Opscode @nathenharvey 3
  4. Evolution of Server Provisioning •  Just build it •  Keep

    notes in server.txt •  Migrate notes to wiki •  Custom shell scripts (in git) •  Systems integration framework @nathenharvey 5
  5. Wrong question! •  YES – use a systems integration framework

    •  YES – use one that works for your team •  YES – this is a talk about Chef @nathenharvey 8
  6. Chef •  Declarative – What, not how •  Idempotent –

    Only take action if required •  Convergent – Takes care of itself @nathenharvey 9
  7. Building a Chef Project •  First, come up with your

    policy / specification •  Abstract the resources in your spec @nathenharvey 10
  8. Building a Chef Project •  First, come up with your

    policy / specification •  Abstract the resources in your spec •  Write recipes @nathenharvey 12
  9. Building a Chef Project •  First, come up with your

    policy / specification •  Abstract the resources in your spec •  Write recipes •  Package recipes in cookbooks @nathenharvey 14
  10. Building a Chef Project •  First, come up with your

    policy / specification •  Abstract the resources in your spec •  Write recipes •  Package recipes in cookbooks •  Apply recipes to nodes @nathenharvey 17
  11. Nodes •  Representation of a host –  runs the Chef

    client –  has attributes –  has a list of recipes to be applied @nathenharvey 18
  12. Building a Chef Project •  First, come up with your

    policy / specification •  Abstract the resources in your spec •  Write recipes •  Package recipes in cookbooks •  Apply recipes to nodes •  Group things into roles @nathenharvey 19
  13. Roles •  mechanism for easily composing sets of functionality • 

    have attributes and a list of recipes to be applied @nathenharvey 20
  14. Building a Chef Project •  First, come up with your

    policy / specification •  Abstract the resources in your spec •  Write recipes •  Package recipes in cookbooks •  Apply recipes to nodes •  Group things into roles @nathenharvey 22
  15. What is Chef? •  Server - API, search, Web UI

    •  Client - chef-client •  Command line tool - knife @nathenharvey 24
  16. What is Chef? •  Server - API, search, Web UI

    •  Client - chef-client •  Command line tool - knife •  Inspection library - ohai @nathenharvey 26
  17. What is Chef? •  Server - API, search, Web UI

    •  Client - chef-client •  Command line tool - knife •  Inspection library - ohai •  REPL - shef @nathenharvey 28
  18. What is Chef? •  Server - API, search, Web UI

    •  Client - chef-client •  Command line tool - knife •  Inspection library - ohai •  REPL - shef •  Community @nathenharvey 34
  19. chef-solo •  What you don't get: –  central server – 

    authentication –  authorization –  search indexes –  persistent attributes @nathenharvey 39
  20. Chef Server •  Open source •  Run it yourself, wherever

    you like •  Complicated to set-up and manage @nathenharvey 41
  21. Private Chef •  Commercial offering •  Managed by Opscode • 

    Pricing –  installation fee –  service contract @nathenharvey 43
  22. Get started with Hosted Chef 1.  Create a Hosted Chef

    account 2.  Install and Update dependencies - ruby, ruby gems, ruby-dev and git-core 3.  Install Chef and create directories needed 4.  Connect to Hosted Chef @nathenharvey 44
  23. Client configuration •  Get organization validation key •  Generate knife

    config •  Get a private key •  Set-up chef-repo directory •  Copy validation files and knife config to .chef @nathenharvey 45
  24. Provision a server •  knife ec2 server create •  knife

    rackspace server create •  Vagrant @nathenharvey 48
  25. Initial set-up steps •  Register with hosted chef •  Create

    a chef-repo •  Install chef •  Configure knife.rb •  Configure Vagrant file •  Register Vagrant instance with Chef hosted @nathenharvey 51
  26. Cookbook site install 1.  A new "pristine copy" branch is

    created in git for tracking the upstream 2.  All existing cookbooks are removed from the branch 3.  The cookbook is downloaded from the cookbook site in tarball form 4.  The downloaded cookbook is untarred, and its contents commited via git 5.  The pristine copy branch is merged into the master branch @nathenharvey 54
  27. Create some roles •  Group recipes together using roles • 

    Apply roles to nodes •  Our roles: –  base_ubuntu –  rubynation_web –  rubynation_db @nathenharvey 63
  28. Review •  Server provisioned and communicating with the Chef API

    •  Apache and Passenger installed with a default configuration •  MySQL installed and running @nathenharvey 70
  29. But wait, there's more! •  Encrypted databags •  Environments • 

    Lightweight Resources and Providers (LWRP) •  Exception and report handlers @nathenharvey 73
  30. Want even more? •  http://foodfightshow.org –  Episode 5: Getting Started

    with Chef •  ChefConf - May 15-17 in San Francisco @nathenharvey 75
  31. Shameless Plugs •  DevOpsDC •  Washington DC MongoDB Users Group

    •  CustomInk Friday Tech Lunches @nathenharvey 76