Rapid Chef Development with Berkshelf, Test-Kitchen and Foodcritic
Upcoming SlideShare
Loading in...5
×
 

Rapid Chef Development with Berkshelf, Test-Kitchen and Foodcritic

on

  • 1,269 views

An introduction to Chef Cookbook development tools:

An introduction to Chef Cookbook development tools:
* Berkshelf
* Test-Kitchen
* Foodcritic

Statistics

Views

Total Views
1,269
Views on SlideShare
812
Embed Views
457

Actions

Likes
4
Downloads
22
Comments
0

8 Embeds 457

http://hart.io 240
http://www.hart.io 116
http://localhost 25
http://hhoover.flavors.me 24
http://flavors.me 24
http://hartio.mystagingwebsite.com 22
http://hhoover.tumblr.com 4
http://hhoover.github.io 2
More...

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Rapid Chef Development with Berkshelf, Test-Kitchen and Foodcritic Rapid Chef Development with Berkshelf, Test-Kitchen and Foodcritic Presentation Transcript

  • BROWN BAG: Rapid Chef Development Hart Hoover @hhoover CLOUD SAVVY
  • CLOUD SAVVY 2
  • ENTERPRISE CLOUD SAVVY 3
  • CHEF SOLO CLOUD SAVVY 4
  • OPEN SOURCE CHEF CLOUD SAVVY 5
  • TOOLS! CLOUD SAVVY 6
  • TOOLS! • Git/GitHub CLOUD SAVVY 6
  • TOOLS! • Git/GitHub • Berkshelf CLOUD SAVVY 6
  • TOOLS! • Git/GitHub • Berkshelf • Vagrant CLOUD SAVVY 6
  • TOOLS! • • • • CLOUD SAVVY Git/GitHub Berkshelf Vagrant Vagrant Plugins 6
  • TOOLS! • • • • • CLOUD SAVVY Git/GitHub Berkshelf Vagrant Vagrant Plugins Test Kitchen 6
  • TOOLS! • • • • • • CLOUD SAVVY Git/GitHub Berkshelf Vagrant Vagrant Plugins Test Kitchen Foodcritic 6
  • CLOUD SAVVY 7
  • CLOUD SAVVY 8
  • CLOUD SAVVY 8
  • CLOUD SAVVY 8
  • • A CLI Tool • A Source Code Management Tool • A Package Manager • Replaces parts of knife • Specifically cookbook management CLOUD SAVVY 8
  • • A CLI Tool • A Source Code Management Tool • A Package Manager • Replaces parts of knife • Specifically cookbook management THE BERKSHELF WAY IS BETTER CLOUD SAVVY 8
  • CLOUD SAVVY 9
  • CLOUD SAVVY 10
  • Why Vagrant? Developers • Repeatable • Customizable • “It works on my machine.” CLOUD SAVVY 11
  • Why Vagrant? Operations • Disposable Machines • Test your provisioning • Local → Production CLOUD SAVVY 12
  • Why Vagrant? = CLOUD SAVVY 13
  • TEST KITCHEN Convergence Integration Testing for Chef CLOUD SAVVY 14
  • TEST KITCHEN Convergence Integration Testing for Chef Does my cookbook work? CLOUD SAVVY 14
  • TEST KITCHEN NO Convergence Integration Testing for Chef Does my cookbook work? CLOUD SAVVY 14
  • FoodCritic Lint testing! Makes it easy to flag known issues Better Cookbooks! CLOUD SAVVY 15
  • Chef WorkFlowS CLOUD SAVVY
  • OLD CHEF DEV WORKFLOW CLOUD SAVVY 17
  • OLD CHEF DEV WORKFLOW Edit Cookbook CLOUD SAVVY 17
  • OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook CLOUD SAVVY 17
  • OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook Provision Machine CLOUD SAVVY 17
  • OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook Run Chef Client Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • OLD CHEF DEV WORKFLOW Edit Cookbook SSH & Validate Upload Cookbook Run Chef Client Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • OLD CHEF DEV WORKFLOW Edit Cookbook SSH & Validate Upload Cookbook Run Chef Client Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • NEW CHEF DEV WORKFLOW Edit Cookbook Test Kitchen Vagrant Up CLOUD SAVVY 18
  • Our Workflow Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • Our Workflow Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • Our Workflow { DEV Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • Our Workflow OPS { { DEV Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • Development Walkthrough Prerequisites CLOUD SAVVY
  • What You need • • • • • • • VirtualBox Vagrant Opscode’s 12.04 Vagrant Box Ruby (1.9.3 or higher!) Berkshelf Test Kitchen Foodcritic CLOUD SAVVY 21
  • Virtualbox https://www.virtualbox.org/wiki/Downloads CLOUD SAVVY 22
  • Vagrant http://downloads.vagrantup.com CLOUD SAVVY 23
  • OPSCODE’S VAGRANT BOX $  vagrant  box  add   opscode-­‐ubuntu-­‐12.04   http://tinyurl.com/chef1204   CLOUD SAVVY 24
  • CREATE A PROJECT $  mkdir  -­‐p  ~/projects/chefnovaclient $  cd  ~/projects/chefnovaclient CLOUD SAVVY 25
  • Berkshelf $  gem  install  berkshelf CLOUD SAVVY 26
  • Test Kitchen $  gem  install  test-­‐kitchen  -­‐-­‐pre CLOUD SAVVY 27
  • FoodCritic $  gem  install  foodcritic CLOUD SAVVY 28
  • CLOUD SAVVY 29
  • Development Walkthrough rackspace-novaclient & supernova CLOUD SAVVY
  • GET STARTED $  cd  ~/projects/chefnovaclient $  berks  init CLOUD SAVVY 31
  • $  berks  init berks  init            create    Berksfile            create    Thorfile            create    .gitignore                  run    git  init  from  "."            create    Gemfile            create    .kitchen.yml            append    Thorfile            create    test/integration/default            append    .gitignore            append    .gitignore            append    Gemfile            append    Gemfile You  must  run  `bundle  install'  to  fetch  any  new  gems.            create    Vagrantfile Successfully  initialized CLOUD SAVVY 32
  • $  berks  init berks  init            create    Berksfile            create    Thorfile            create    .gitignore                  run    git  init  from  "."            create    Gemfile            create    .kitchen.yml            append    Thorfile            create    test/integration/default            append    .gitignore            append    .gitignore            append    Gemfile            append    Gemfile You  must  run  `bundle  install'  to  fetch  any  new  gems.            create    Vagrantfile Successfully  initialized CLOUD SAVVY 33
  • $  berks  init berks  init            create    Berksfile            create    Thorfile            create    .gitignore                  run    git  init  from  "."            create    Gemfile            create    .kitchen.yml            append    Thorfile            create    test/integration/default            append    .gitignore            append    .gitignore            append    Gemfile            append    Gemfile You  must  run  `bundle  install'  to  fetch  any  new  gems.            create    Vagrantfile Successfully  initialized CLOUD SAVVY 34
  • $  berks  init berks  init            create    Berksfile            create    Thorfile            create    .gitignore                  run    git  init  from  "."            create    Gemfile            create    .kitchen.yml            append    Thorfile            create    test/integration/default            append    .gitignore            append    .gitignore            append    Gemfile            append    Gemfile You  must  run  `bundle  install'  to  fetch  any  new  gems.            create    Vagrantfile Successfully  initialized CLOUD SAVVY 35
  • $  berks  init berks  init            create    Berksfile            create    Thorfile            create    .gitignore                  run    git  init  from  "."            create    Gemfile            create    .kitchen.yml            append    Thorfile            create    test/integration/default            append    .gitignore            append    .gitignore            append    Gemfile            append    Gemfile You  must  run  `bundle  install'  to  fetch  any  new  gems.            create    Vagrantfile Successfully  initialized CLOUD SAVVY 36
  • $  berks  init berks  init            create    Berksfile            create    Thorfile            create    .gitignore                  run    git  init  from  "."            create    Gemfile            create    .kitchen.yml            append    Thorfile            create    test/integration/default            append    .gitignore            append    .gitignore            append    Gemfile            append    Gemfile You  must  run  `bundle  install'  to  fetch  any  new  gems.            create    Vagrantfile Successfully  initialized CLOUD SAVVY 37
  • $  berks  init berks  init            create    Berksfile            create    Thorfile            create    .gitignore                  run    git  init  from  "."            create    Gemfile            create    .kitchen.yml            append    Thorfile            create    test/integration/default            append    .gitignore            append    .gitignore            append    Gemfile            append    Gemfile You  must  run  `bundle  install'  to  fetch  any  new  gems.            create    Vagrantfile Successfully  initialized CLOUD SAVVY 38
  • CLOUD SAVVY 39
  • INSTALL Kitchen-Vagrant $  gem  install  kitchen-­‐vagrant CLOUD SAVVY 40
  • SET UP TEST KITCHEN Goodbye 10.04! CLOUD SAVVY 41
  • RUN Test KitchEN $  kitchen  verify Good Luck! CLOUD SAVVY 42
  • CLOUD SAVVY 43
  • WHAT FAILED? FATAL:  No  cookbook  found CLOUD SAVVY 44
  • What are our requirements? CLOUD SAVVY 45
  • What are our requirements? Python pip make package manager setuptools CLOUD SAVVY 45
  • COPY/PasTE http://tinyurl.com/chefpart2 CLOUD SAVVY 46
  • BERKSFILE: DependencIES! site  :opscode cookbook  'apt' cookbook  'build-­‐essential' cookbook  'python' CLOUD SAVVY 47
  • RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 48
  • Congrats! You installed something... CLOUD SAVVY 49
  • Congrats! You installed something... but not what we need. CLOUD SAVVY 49
  • BERKSFILE: THIS IS A COOKBOOK site  :opscode cookbook  'apt' cookbook  'build-­‐essential' cookbook  'python' metadata CLOUD SAVVY 50
  • BERKSFILE: THIS IS A COOKBOOK site  :opscode cookbook  'apt' cookbook  'build-­‐essential' cookbook  'python' metadata CLOUD SAVVY 51
  • RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 52
  • CLOUD SAVVY 53
  • WHAT FAILED? Failed  to  complete  #converge  action CLOUD SAVVY 54
  • metadata.RB: What is this THING?? name  "chefnovaclient" version  "1.0.0" description  "Installs  the  novaclient." maintainer  "Hart  Hoover" maintainer_email  "hart.hoover@rackspace.com" depends  "python" depends  "apt" supports  "ubuntu" CLOUD SAVVY 55
  • RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 56
  • Congrats! You installed something... CLOUD SAVVY 57
  • Congrats! You installed something... but STILL not what we need. CLOUD SAVVY 57
  • TIME TO WRITE RECIPES CLOUD SAVVY 58
  • TIME TO WRITE RECIPES $  berks  cookbook  . Don’t overwrite stuff CLOUD SAVVY 59
  • Default RECIPE: recipes/default.rb include_recipe  "apt" include_recipe  "python::pip" %w{git  python-­‐dev  build-­‐essential}.each  do  |pkg|   package  pkg  do     action  :install   end end python_pip  "rackspace-­‐novaclient"  do   action  :install end CLOUD SAVVY 60
  • Default RECIPE: recipes/default.rb include_recipe  "apt" include_recipe  "python::pip" %w{git  python-­‐dev  build-­‐essential}.each  do  |pkg|   package  pkg  do     action  :install   end end python_pip  "rackspace-­‐novaclient"  do   action  :install end CLOUD SAVVY 61
  • Default RECIPE: recipes/default.rb include_recipe  "apt" include_recipe  "python::pip" %w{git  python-­‐dev  build-­‐essential}.each  do  |pkg|   package  pkg  do     action  :install   end end python_pip  "rackspace-­‐novaclient"  do   action  :install end CLOUD SAVVY 62
  • Default RECIPE: recipes/default.rb include_recipe  "apt" include_recipe  "python::pip" %w{git  python-­‐dev  build-­‐essential}.each  do  |pkg|   package  pkg  do     action  :install   end end python_pip  "rackspace-­‐novaclient"  do   action  :install end CLOUD SAVVY 63
  • EDIT YOUR RUN LIST .kitchen.yaml suites: -­‐  name:  default    run_list:        -­‐  recipe[chefnovaclient::default]    attributes:  {} CLOUD SAVVY 64
  • EDIT YOUR RUN LIST .kitchen.yaml suites: -­‐  name:  default    run_list:        -­‐  recipe[chefnovaclient::default]    attributes:  {} CLOUD SAVVY 65
  • RUN FOODCRITIC! $  foodcritic  . Everything good? CLOUD SAVVY 66
  • If Not: FIX IT! CLOUD SAVVY 67
  • RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 68
  • Did it work? $  kitchen  login  default $  nova  help CLOUD SAVVY 69
  • CLOUD SAVVY 70
  • CLOUD SAVVY 71
  • SUPERNOVA CLOUD SAVVY 72
  • Let’s MAKE AUTOMATED TESTs $  mkdir  test/integration/default/bats $  touch  test/integration/default/bats/supernova.bats CLOUD SAVVY 73
  • TESTING test/integration/default/bats/supernova.bats #!/usr/bin/env  bats @test  "supernova  is  installed"  {    which  supernova } CLOUD SAVVY 74
  • TESTING test/integration/default/bats/supernova.bats @test  "supernova  config  exists"  {    cat  /home/vagrant/.supernova } CLOUD SAVVY 75
  • TESTING test/integration/default/bats/supernova.bats @test  "run  supernova"  {    supernova  myaccount  list } CLOUD SAVVY 76
  • TESTING test/integration/default/bats/supernova.bats @test  "novaclient  installed"  {    which  nova } CLOUD SAVVY 77
  • SUPERNOVA recipes/default.rb python_pip  "git+git://github.com/major/supernova.git"  do   action  :install end template  "/home/vagrant/.supernova"  do    source  "supernova.erb"    mode  0600    owner  "vagrant"    group  "vagrant" end CLOUD SAVVY 78
  • SuperNova templates/default/supernova.erb [myaccount] OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0/ OS_VERSION=2.0 OS_AUTH_SYSTEM=rackspace OS_REGION_NAME=DFW OS_SERVICE_NAME=cloudserversOpenStack OS_TENANT_NAME=<%=  node['chefnovaclient']['username']  %> OS_USERNAME=<%=  node['chefnovaclient']['username']  %> OS_PASSWORD=<%=  node['chefnovaclient']['password']  %> OS_NO_CACHE=1 NOVA_VOLUME_SERVICE_NAME=cloudBlockStorage CLOUD SAVVY 79
  • SuperNova templates/default/supernova.erb [myaccount] OS_AUTH_URL=https://identity.api.rackspacecloud.com/v2.0/ OS_VERSION=2.0 OS_AUTH_SYSTEM=rackspace OS_REGION_NAME=DFW OS_SERVICE_NAME=cloudserversOpenStack OS_TENANT_NAME=<%=  node['chefnovaclient']['username']  %> OS_USERNAME=<%=  node['chefnovaclient']['username']  %> OS_PASSWORD=<%=  node['chefnovaclient']['password']  %> OS_NO_CACHE=1 NOVA_VOLUME_SERVICE_NAME=cloudBlockStorage CLOUD SAVVY 80
  • SuperNova attributes/default.rb default['chefnovaclient']['username']  =  "USERNAME" default['chefnovaclient']['password']  =  "APIKEY" CLOUD SAVVY 81
  • RUN FOODCRITIC! $  foodcritic  . Everything good? CLOUD SAVVY 82
  • RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 83
  • RUN YOUR Tests $  kitchen  verify Good Luck! CLOUD SAVVY 84
  • “SAVE YOUR WORK” CLOUD SAVVY 85
  • THANK YOU! CLOUD SAVVY