Developer Automation Tools Bootcamp

Learning about development tools and automation

View project onGitHub

Introduction to Packer


This session is nearly the antithesis for the Chef topic that was just covered. Short and sweet. But you can't let that fool you, Packer is pow. er. ful.

"Packer is a tool for creating machine and container images for multiple platforms from a single source configuration." Packer is open source and watched over by creator Mitchell Hashimoto. Remember him?

Official Intro to Packer
And that is about it. Packer embodies the *nix philosophy. Do one job and do that one job well.

How to build your image

Packer is here to create OS images of your server platforms. "Golden Images" is a term used at times to describe this. But it is not VM images, it is Docker container images, Cloud provider images, or even going so far as to bundle your app in to an image of your preferred format.

You need three things to be get running with Packer:

  1. Install Packer.
  2. Create a json file defining the image you'll be creating.
  3. Patience - you're often working with some big ol' files here.

Advanced Packer

Yes, Packer is just going to build images for you. But there are mulitple paths to the destination.
Looking below, the top list multiplied by the bottom list = a lot of possible combinations. Pow. er. ful. If Packer can't meet your environmental needs, get a better environment. Or embrace the Open Source and add support to Packer for what you need.

Provisioners

Provisioners are the scripts or configuration tools used to apply change from the original OS image to become the finished OS image.

  • Shell Scripts
  • Chef
  • Puppet
  • Salt
  • Ansible
  • Others

Builders (output formats)

"Builders are responsible for creating machines and generating images from them for various platforms."

  • Amazon EC2 (AMI)
  • DigitalOcean
  • Docker
  • Google Compute Engine
  • OpenStack
  • VirtualBox
  • VMWare
  • Many others

Workout

We are going to complete the following actions to build a Docker container image with the Unifi cookbook from the Chef section applied to the OS.

  1. Working inside the VM for the class, let's move in to the Packer directory cd /vagrant/packer-container
  2. Ensure the JSON file for the packer project is valid and ready to go packer validate example-unifi-ubuntu-16.04.json.
  3. If you see any errors reported (which you should), correct them with the following steps.
  4. The bootcamp cookbook and it's dependent cookbooks need to be a single directory. The Chef tool Berkshelf has built-in functionality to do this called Vendoring. So cd /vagrant/chef/bootcamp; berks vendor; cd /vagrant/packer-containers to vendor the cookbooks and get back in our working directory.
  5. Validate the Packer template again to ensure we are error free. packer validate example-unifi-ubuntu-16.04.json
  6. Now we're ready to build our new Docker container. packer build example-unifi-ubuntu-16.04.json (ask the person next to tell you their life story and check back for progress...).
  7. Congratulations, the provided cookbook you created in the previous section you have now built you your own Docker container with Unifi installed.
  8. When completed, you can run docker images and see the automationtools/unifi image in the list.