While a Chef Server is not necessary for deployments, it adds some great features and functionality to recipes. Robin explains the indexing features of the Chef Server.
- [Teacher] In this last chapter I'd like to take a moment to talk about what we could have done differently in this class. You've worked with me to apply cookbook code to a virtual machine via a Chef server. Now you've seen us develop locally inside of a virtual machine near the beginning of class. This process is great for learning. However, when it comes to using a Chef server, it can really slow down the speed and integrity of your cookbook development, meaning every time you want to test a small change or a refactor that you've made, you're forced to actually upload your new cookbook code to a Chef server, and then run the Chef client on that node to pull down your cookbook changes.
This can cause some level of discomfort whenever you're making changes, and force you to maybe batch changes together in such a way that it speeds up your cookbook development. Fortunately, there's a much better way. Test Kitchen is a project that ships with the Chef Development Kit. You already have it installed on your local machine if you followed along with the class. It provides a testing harness to apply our cookbook code on various platforms in isolation.
This means that we can use it to apply our cookbook code from scratch and see if it works as intended. It works with Vagrant, Docker, and most cloud providers like AWS, Microsoft Azure, or Google Compute Engine. It can even run on bare metal machines or integrate with an on-premise data center. The reason that Test Kitchen is great for cookbook development is because it not only deploys your code to an isolated platform, but it also allows you to run tests and automate the testing procedure to see if the changes that you made broke any of your infrastructure.
It integrates with many popular testing frameworks like InSpec, ServerSpec, or BATS. InSpec is an open-source compliance testing framework that's used with Test Kitchen. It ships as a Ruby Gem and is again packaged with the Chef Development Kit. It provides a simple Ruby DSL, and it maps directly to Chef resources. If you know how to write Chef code, writing InSpec tests will be easy for you.
Similar to Chef, it's platform-agnostic and extensible, so that you can customize it for your deployments. It allows for local or remote testing and is more of a compliance framework than anything else. But we can use it to build tests for our Chef code and run those tests locally or in the cloud. Since it integrates directly with Test Kitchen, we can get started with it immediately and demonstrate how you might have gone about developing our cookbook with a little bit more speed.
This intermediate-level course provides insights into the Chef architecture through practical examples and demos, including the deployment of a PHP application on top of a LAMP stack. Instructor Robin Beck walks through recipe development and the various prebuilt cookbooks available from the Chef community Supermarket, and reviews best practices for building wrapper cookbooks that allow you to access recipes from different cookbooks. He also shows how to work more efficiently with knife commands for managing clients, cookbooks, and data.
- Building a setup recipe
- Using cookbooks to organize recipes
- Using community recipes
- Uploading cookbooks
- Using the database cookbook
- Adding PHP to the mix
- Searching with knife
- Testing cookbooks with Kitchen