This example repository demonstrates the simple usage of Packer.
Examples in this repo:
- Basic AMI image
- Image with Redis pre-installed
- Parallel Builds on AWS and DigitalOcean
- Turning machine image into a Vagrant Box
Packer template files are written in json format.
This is to ensure the template file is correct such that it has the correct Packer syntax.
e.g.
packer validate basic-image.json
Once validated, we can build the machine image using the validated template file.
e.g.
packer build basic-image.json
See basic-image.json
Using Packer provisioners to run predefined scripts to install certain software onto the machine images.
e.g.
"provisioners" : [
{
"type" : "shell",
"inline" : [
"sleep 30",
"sudo apt-get update",
"sudo apt-get install -y redis-server"
]
}
]
Packer allows the generation of multiple machine images for different cloud providers and even multiple machine images for the same cloud providers/platforms at once.
To achieve this Packer syntax contains a "builders" section of the template which is used to define the list of 'builders' to build the machine image(s) for the different and/or same cloud provider/platform.
e.g.
"builders" : [
{
// ... AWS
},
{
// ... DigitalOcean
}
],
See the image-with-redis-parallel-builds.json
for detailed code block.
Makes use of "post processors".
e.g.
"post-processors" : ["vagrant"]