Your SlideShare is downloading. ×
  • Like
Rapid Chef Development with Berkshelf, Test-Kitchen and Foodcritic
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

Rapid Chef Development with Berkshelf, Test-Kitchen and Foodcritic

  • 1,597 views
Published

An introduction to Chef Cookbook development tools: …

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

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,597
On SlideShare
0
From Embeds
0
Number of Embeds
10

Actions

Shares
Downloads
29
Comments
0
Likes
4

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. BROWN BAG: Rapid Chef Development Hart Hoover @hhoover CLOUD SAVVY
  • 2. CLOUD SAVVY 2
  • 3. ENTERPRISE CLOUD SAVVY 3
  • 4. CHEF SOLO CLOUD SAVVY 4
  • 5. OPEN SOURCE CHEF CLOUD SAVVY 5
  • 6. TOOLS! CLOUD SAVVY 6
  • 7. TOOLS! • Git/GitHub CLOUD SAVVY 6
  • 8. TOOLS! • Git/GitHub • Berkshelf CLOUD SAVVY 6
  • 9. TOOLS! • Git/GitHub • Berkshelf • Vagrant CLOUD SAVVY 6
  • 10. TOOLS! • • • • CLOUD SAVVY Git/GitHub Berkshelf Vagrant Vagrant Plugins 6
  • 11. TOOLS! • • • • • CLOUD SAVVY Git/GitHub Berkshelf Vagrant Vagrant Plugins Test Kitchen 6
  • 12. TOOLS! • • • • • • CLOUD SAVVY Git/GitHub Berkshelf Vagrant Vagrant Plugins Test Kitchen Foodcritic 6
  • 13. CLOUD SAVVY 7
  • 14. CLOUD SAVVY 8
  • 15. CLOUD SAVVY 8
  • 16. CLOUD SAVVY 8
  • 17. • A CLI Tool • A Source Code Management Tool • A Package Manager • Replaces parts of knife • Specifically cookbook management CLOUD SAVVY 8
  • 18. • 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
  • 19. CLOUD SAVVY 9
  • 20. CLOUD SAVVY 10
  • 21. Why Vagrant? Developers • Repeatable • Customizable • “It works on my machine.” CLOUD SAVVY 11
  • 22. Why Vagrant? Operations • Disposable Machines • Test your provisioning • Local → Production CLOUD SAVVY 12
  • 23. Why Vagrant? = CLOUD SAVVY 13
  • 24. TEST KITCHEN Convergence Integration Testing for Chef CLOUD SAVVY 14
  • 25. TEST KITCHEN Convergence Integration Testing for Chef Does my cookbook work? CLOUD SAVVY 14
  • 26. TEST KITCHEN NO Convergence Integration Testing for Chef Does my cookbook work? CLOUD SAVVY 14
  • 27. FoodCritic Lint testing! Makes it easy to flag known issues Better Cookbooks! CLOUD SAVVY 15
  • 28. Chef WorkFlowS CLOUD SAVVY
  • 29. OLD CHEF DEV WORKFLOW CLOUD SAVVY 17
  • 30. OLD CHEF DEV WORKFLOW Edit Cookbook CLOUD SAVVY 17
  • 31. OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook CLOUD SAVVY 17
  • 32. OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook Provision Machine CLOUD SAVVY 17
  • 33. OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • 34. OLD CHEF DEV WORKFLOW Edit Cookbook Upload Cookbook Run Chef Client Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • 35. OLD CHEF DEV WORKFLOW Edit Cookbook SSH & Validate Upload Cookbook Run Chef Client Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • 36. OLD CHEF DEV WORKFLOW Edit Cookbook SSH & Validate Upload Cookbook Run Chef Client Provision Machine Bootstrap Machine CLOUD SAVVY 17
  • 37. NEW CHEF DEV WORKFLOW Edit Cookbook Test Kitchen Vagrant Up CLOUD SAVVY 18
  • 38. Our Workflow Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • 39. Our Workflow Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • 40. Our Workflow { DEV Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • 41. Our Workflow OPS { { DEV Berkshelf Vagrant Up Test Kitchen GitHub CLOUD SAVVY Production Monitoring 19
  • 42. Development Walkthrough Prerequisites CLOUD SAVVY
  • 43. What You need • • • • • • • VirtualBox Vagrant Opscode’s 12.04 Vagrant Box Ruby (1.9.3 or higher!) Berkshelf Test Kitchen Foodcritic CLOUD SAVVY 21
  • 44. Virtualbox https://www.virtualbox.org/wiki/Downloads CLOUD SAVVY 22
  • 45. Vagrant http://downloads.vagrantup.com CLOUD SAVVY 23
  • 46. OPSCODE’S VAGRANT BOX $  vagrant  box  add   opscode-­‐ubuntu-­‐12.04   http://tinyurl.com/chef1204   CLOUD SAVVY 24
  • 47. CREATE A PROJECT $  mkdir  -­‐p  ~/projects/chefnovaclient $  cd  ~/projects/chefnovaclient CLOUD SAVVY 25
  • 48. Berkshelf $  gem  install  berkshelf CLOUD SAVVY 26
  • 49. Test Kitchen $  gem  install  test-­‐kitchen  -­‐-­‐pre CLOUD SAVVY 27
  • 50. FoodCritic $  gem  install  foodcritic CLOUD SAVVY 28
  • 51. CLOUD SAVVY 29
  • 52. Development Walkthrough rackspace-novaclient & supernova CLOUD SAVVY
  • 53. GET STARTED $  cd  ~/projects/chefnovaclient $  berks  init CLOUD SAVVY 31
  • 54. $  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
  • 55. $  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
  • 56. $  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
  • 57. $  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
  • 58. $  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
  • 59. $  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
  • 60. $  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
  • 61. CLOUD SAVVY 39
  • 62. INSTALL Kitchen-Vagrant $  gem  install  kitchen-­‐vagrant CLOUD SAVVY 40
  • 63. SET UP TEST KITCHEN Goodbye 10.04! CLOUD SAVVY 41
  • 64. RUN Test KitchEN $  kitchen  verify Good Luck! CLOUD SAVVY 42
  • 65. CLOUD SAVVY 43
  • 66. WHAT FAILED? FATAL:  No  cookbook  found CLOUD SAVVY 44
  • 67. What are our requirements? CLOUD SAVVY 45
  • 68. What are our requirements? Python pip make package manager setuptools CLOUD SAVVY 45
  • 69. COPY/PasTE http://tinyurl.com/chefpart2 CLOUD SAVVY 46
  • 70. BERKSFILE: DependencIES! site  :opscode cookbook  'apt' cookbook  'build-­‐essential' cookbook  'python' CLOUD SAVVY 47
  • 71. RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 48
  • 72. Congrats! You installed something... CLOUD SAVVY 49
  • 73. Congrats! You installed something... but not what we need. CLOUD SAVVY 49
  • 74. BERKSFILE: THIS IS A COOKBOOK site  :opscode cookbook  'apt' cookbook  'build-­‐essential' cookbook  'python' metadata CLOUD SAVVY 50
  • 75. BERKSFILE: THIS IS A COOKBOOK site  :opscode cookbook  'apt' cookbook  'build-­‐essential' cookbook  'python' metadata CLOUD SAVVY 51
  • 76. RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 52
  • 77. CLOUD SAVVY 53
  • 78. WHAT FAILED? Failed  to  complete  #converge  action CLOUD SAVVY 54
  • 79. 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
  • 80. RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 56
  • 81. Congrats! You installed something... CLOUD SAVVY 57
  • 82. Congrats! You installed something... but STILL not what we need. CLOUD SAVVY 57
  • 83. TIME TO WRITE RECIPES CLOUD SAVVY 58
  • 84. TIME TO WRITE RECIPES $  berks  cookbook  . Don’t overwrite stuff CLOUD SAVVY 59
  • 85. 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
  • 86. 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
  • 87. 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
  • 88. 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
  • 89. EDIT YOUR RUN LIST .kitchen.yaml suites: -­‐  name:  default    run_list:        -­‐  recipe[chefnovaclient::default]    attributes:  {} CLOUD SAVVY 64
  • 90. EDIT YOUR RUN LIST .kitchen.yaml suites: -­‐  name:  default    run_list:        -­‐  recipe[chefnovaclient::default]    attributes:  {} CLOUD SAVVY 65
  • 91. RUN FOODCRITIC! $  foodcritic  . Everything good? CLOUD SAVVY 66
  • 92. If Not: FIX IT! CLOUD SAVVY 67
  • 93. RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 68
  • 94. Did it work? $  kitchen  login  default $  nova  help CLOUD SAVVY 69
  • 95. CLOUD SAVVY 70
  • 96. CLOUD SAVVY 71
  • 97. SUPERNOVA CLOUD SAVVY 72
  • 98. Let’s MAKE AUTOMATED TESTs $  mkdir  test/integration/default/bats $  touch  test/integration/default/bats/supernova.bats CLOUD SAVVY 73
  • 99. TESTING test/integration/default/bats/supernova.bats #!/usr/bin/env  bats @test  "supernova  is  installed"  {    which  supernova } CLOUD SAVVY 74
  • 100. TESTING test/integration/default/bats/supernova.bats @test  "supernova  config  exists"  {    cat  /home/vagrant/.supernova } CLOUD SAVVY 75
  • 101. TESTING test/integration/default/bats/supernova.bats @test  "run  supernova"  {    supernova  myaccount  list } CLOUD SAVVY 76
  • 102. TESTING test/integration/default/bats/supernova.bats @test  "novaclient  installed"  {    which  nova } CLOUD SAVVY 77
  • 103. 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
  • 104. 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
  • 105. 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
  • 106. SuperNova attributes/default.rb default['chefnovaclient']['username']  =  "USERNAME" default['chefnovaclient']['password']  =  "APIKEY" CLOUD SAVVY 81
  • 107. RUN FOODCRITIC! $  foodcritic  . Everything good? CLOUD SAVVY 82
  • 108. RUN Test KitchEN $  kitchen  converge Good Luck! CLOUD SAVVY 83
  • 109. RUN YOUR Tests $  kitchen  verify Good Luck! CLOUD SAVVY 84
  • 110. “SAVE YOUR WORK” CLOUD SAVVY 85
  • 111. THANK YOU! CLOUD SAVVY