Customizing your Scalarium Cloud using Chef: Cooking with Chef

To customize our cloud to include a running Redis server, we're going to write Chef cookbooks. We've already build a good pile of example cookbooks for your perusal, but nonetheless we're going through the steps required to write your own.

A Chef cookbook is a self-contained package of recipes, configuration templates and attributes, altogether describing a specific part of your infrastructure, e.g. the setup of an Apache or a Redis server. Ideally a cookbook describes only one component of your infrastructure.

Chef cookbooks follow a set of conventions, not all of which you need to know to get going with it. First up, the
directory structure. In the place where you usually keep your code, create a directory called redis-cloud-example. In
that directory create a directory called redis, which will be the name of the cookbook we're going to build.

In the cookbook's directory, create a structure like so:

Cookbook directory structure

attributes contains the default settings for this particular cookbook and its recipes. For Redis this could be default settings for the virtual memory or IP address and port to listen on. For the Rails application server we set a
whole bunch like the Rails version to be installed, which application server stack should be used, and a whole lot more.
These are only the defaults, and can be overwritten from within Scalarium, a useful feature if you want to use the same
cookbooks on different clouds.

recipes contains files that each represent a description of the state your system is expected to be in after they ran. They contain things like installing packages, creating configuration files, adding users, and so on, usually
split up so that each recipe describes a part of the service, e.g. installing the software, configuring clients, and so
on.

templates is the place to store configuration file templates or any other files that you want to install on the instance, and that aren't part of the instance setup itself, or not fitting for your use case, e.g. updated init scripts. The rule of thumb is that whenever you even slightly change a file on the instance, it should be turned into a template and included in the cookbook.

The file metadata.rb contains a description of what this cookbook is offering and what kinds of recipes it has. You
can also specify dependencies on other cookbooks, but we'll ignore that for now. Here's how the file looks like for our
Redis setup:

Next step: Writing a Cookbook to set up Redis

Or go back to The Scalarium Lifecycle System