– 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.
$packer build example.json
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