Image CM from the Ground up with packer
Recently I have had the opportunity to test drive packer.io on a project I am working on, and although I have heard the word packer here and there until you start using it you do not understand the power behind it. As a side note until now there was usage Razor which by the look of it the place where packer was inspired from + a better version of veewee
What is packer ?
From packer.io site -> Packer is a tool for creating identical machine images for multiple platforms from a single source configuration.
In My words -> Packer, is a complementery tool for DevOps needy of a consistent Infrustructure As Code, taking an image from Dev in to Production - using the same image in Dev with Vagrant (as an exmaple) then pushing it to PROD (AWS for exmaple).
BTW it's important to note that packer was developed by Mitchell Hashimoto the author of Vagrant, Vagrant cloud for exmaple really needed a tool like packer in order to provide a way to develop and publish boxes in a consitent manor - I recommend taking a look at Vagrant Cloud
Why is this important ?
Nowadays building a product doesn't end with developing a piece of software you in many cases deliver a virtual machine and more and more we find places where we deliver moire than 1 machine, but how do we makw sure this machine can run on multiple cloud provides - for example AWS & OSTK and many more whilst during development you want to use local hypervisors like VirtualBox, VMware fusion or maybe a local vSphere instance - how do you make sure all these provisioners will use the same image -> Packer !
Thats not all packer also has an integration with Configuration Management Frameworks like Chef / Puppet / Ansible etc which will do the OS customization for you.
How does packer do it (work)
There is a great approach here in order to create a image which starts from an OS iso and concludes with an Artifact(s) which you can take to the cloud ( private / public ) you need a few things:
- Template(s) - a json file which declares:
- Builders - What type of machines to build AWS, Virtualbox, VMware etc
- Provisioners - could be shell, chef, puupet, ansible etc
- Post-Processors - a great exmaple is uploading an artifact to a repository
Packer by exmaple: build for centos 6.4 on virtualbox
What you can see from the builder declaration is that packer will simulate a pxe boot server locally (over http) and will run a kickstart installation (this is the same way veewee and razor operates), of course there is a source url for the iso and other important stuff you can see ...
The next section is provisioners which as mentioned be a number of things but in this example I am using shell scripts:
I guess the install-vbox-guest-additions is understandable but the clean-empty-space script is used to save space on the instance just before packaging it (example taken from -> here).
An exmaple of chef provisioner:
Finally once we have an image we want to pack it (and maybe upload it somewhere), this where post-processing operation come in handy:
So in this case the post-processor packages the artifact and creates a Vagrant friendly box tar-ball.
Post-processor(s) - vagrant exmaple
A similar exmaple for an aws box would be somthing like this:
You use your AWS_SECRES_KEY & AWS_ACCESS_KEY + use a base ami (ami-21055220) then create a custom image on AWS.
This post just scratches the surface, I hope to write some more about it as I amture with it -> one of my next tasks is creating a windows image (I wonder how that one pulls through ...).
Hope you enjoyed it.