Packer is a tool for building identical machine images for multiple platforms from a single source configuration.
Packer is lightweight, runs on every major operating system, and is highly performant, creating machine images for multiple platforms in parallel
Packer can build images for AMIs (Amazon Machine Image), Digital Ocean, Docker, Vmware, VirtualBox, Vagrant… (Full list found here)
Inside this article, we’ll choose VirtualBox & Vagrant to demonstrate, since it’s free, convenient and widely adopted.
I. Preparation– Install Packer
– Install VirtualBox
II. Make configuration– As we stated recently, building a machine image by Packer is as easy as simple configuration. Packer takes advantage of JSON and it’s simple syntax.
Here’s an example:
Just a simple syntax to tell Packer:
– Use virtualbox as builder
– Base the machine on Ubuntu 14.04
– Setup default SSH username & password
– Provisioning: setup web stack packages with nginx, php-fpm..
– Some trivial configs, such as Shutdown message…
Actually, in real world we need to write a couple of configs to have a full-feature images. The code can be found here. In that config, we intend to install webstack with nginx & php & php-fpm packages.
III. BuildLet’s run:
Below are the output from our full configs:
IV. Use the image– We have image now, it’s usable, even production-ready :)!
By this example, we have an image that can be used by your team with Vagrant (remember to install Vagrant if you haven’t)
We now have a virtual machine with web-stack: nginx + php + php-fpm
For other builders, such as Amazon AMI, digitalocean… you can ‘push’ that image to have cloud running machine which ready for your usage!
I really love the idea of building images, modifying images, deploying images.. with just a couple of configuration changes. Packer and other Hashicorp opensource products do a great job like that. They explained their ecosystem here
If you have anything feedback or in the need of further discussion, please feel free to drop me an email at email@example.com