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.
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:
- Install Packer.
- Create a json file defining the image you'll be creating.
- Patience - you're often working with some big ol' files here.
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 are the scripts or configuration tools used to apply change from the original OS image to become the finished OS image.
- Shell Scripts
"Builders are responsible for creating machines and generating images from them for various platforms."
- Amazon EC2 (AMI)
- Google Compute Engine
- Many others
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.
- Working inside the VM for the class, let's move in to the Packer directory
- Ensure the JSON file for the packer project is valid and ready to go
packer validate example-unifi-ubuntu-16.04.json.
- If you see any errors reported (which you should), correct them with the following steps.
- 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-containersto vendor the cookbooks and get back in our working directory.
- Validate the Packer template again to ensure we are error free.
packer validate example-unifi-ubuntu-16.04.json
- 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...).
- Congratulations, the provided cookbook you created in the previous section you have now built you your own Docker container with Unifi installed.
- When completed, you can run
docker imagesand see the
automationtools/unifiimage in the list.