Press "Enter" to skip to content

Category: DevOps

Chef and Docker for a rapid infrastructure development

We started using Chef a while ago and one of the first steps we took was to use Docker instead of Vagrant for performing tests due to it’s faster setup.
After all this time I can say it was a nice experience and now our CI is happily testing our in minutes. So…

What do you need?

Basically you need to install the latest ChefDK where the gem kitchen-dokken is installed by default. This gem enables a light-weight tooling to use Docker containers for executing Kitchen.

Setup

After that you just need to setup your kitchen.yml to use dokken as driver like so:

---
driver:
  name: dokken
  chef_version: latest

transport:
  name: dokken

provisioner:
name: dokken

...

The transport and the provisioner are set to dokken so kitchen will use the lighter tooling from the driver. Then you can setup your platform to test your cookbooks:

  - name: ubuntu-16.04
    driver:
      image: ubuntu:16.04
      pid_one_command: /bin/systemd
      intermediate_instructions:
        - RUN /usr/bin/apt-get update

Considerations

  • Docker is designed for isolating and packaging processes that runs as the only process inside a container.
    If your cookbook setup services you may need to choose a complete Docker base image that normally is bigger in size, also you need to explicitly start the system daemon (such as systemd) like you saw on the code snippet earlyer.

  • Do not try to run Docker inside a container. If your cookbook uses Docker somehow is better to use Vagrant instead because then you may need to manually setup the container to host docker and that is a pain.

DevOps with Chef. Sweet.

I needed to setup few servers for QA and provision development environments for my team so I started a small make-based repo where to put all the nasty configuration and provisioning stuff. After few days of work I decided to look for solutions in the world wide web. Then discovered DevOps discipline.

DevOps enlightened me. Is exactly what I was looking for!

I work in an industrial environment with real time and embedded software using tools such as Yocto and scripting. Not related to web development at all and even less with cloud computing… So DevOps was quite far away from my environment, but as a curious guy I started diving into it: Ansible, Docker, Puppet, Salt… And finally I looked into Chef.

Exactly what I was looking for.

Remember my objective: setting up some servers for QA and CI for my team and provisioning our developer environments with the proper tools. Well,  Chef is designed exactly for that!

Why Chef?

Ruby.

If you don’t know about Ruby, it is a small and nifty language. I recommend to start with the koans.

As a developer, having a language instead of some custom file syntax or an obscure engine is allays a plus. Of course you will have some drawbacks enforcing yourself to deal with infrastructure and setup, but depending on the size of your team, is something you may need to deal with it anyway.

If your team is not enlightened yet by DevOps something you will get from Chef among other similar tools are the DevOps mantras:

  • Environment replication.
  • Scalability.
  • Infrastructure as code. (Version controlled)
  • Quality and reliability.

And with Chef, as an open source project, you will also have lots and lots of community support and a complete community repository of recipes: The supermarket.

Where to start?

Is not in the scope of this blog entry to show Chef, but there are lots of information in their learning portal and some nice books to start with. Is a matter of a couple of days to start doing Chef recipes and organizing your infrastructure just learning Ruby and having a nice introductory reading, I personally read Learning Chef.

Please, let me know if this information was helpful for you!