Create Image

In this article, you will learn how to build custom image using Packer.

Prerequisites

You must have created the aws-dev IAM user and set the secret keys environment variables as explained in Create IAM User.

Packer Setup

On Mac, install packer using Brew:

Install Packer
brew install packer

Check version:

Packer Version
$ packer --version
Packer v1.10.1 

Your version of Packer is out of date! The latest version
is 1.10.2. You can update by downloading from www.packer.io/downloads

You can upgrade to latest version by running:

Upgrade Packer
brew upgrade packer

Packer Workflow

Clone the project:

Clone Project
git clone git@github.com:bparanj/hivegrid.dev.git

Go into the packer directory and run:

Format Packer Template
$ packer fmt .

Validate:

Validate Packer Template
$ packer validate .

Build image:

Build Image
$ packer build aws-ubuntu.pkr.hcl

This runs on a c5.4xlarge EC2 instance and takes about 20 minutes to build the custom image. You will be charged by AWS. You can save time and money by using the prebuilt image.

The Packer template needs to be modified to copy images to all AWS regions. For sharing the image with anyone this step is required. However this will incur costs. Check tasks/regions.md file in learning-nuxt project.

You need to follow these steps only if you make changes to the aws-ubuntu.pkr.hcl or any of the Ansible playbooks in the ansible directory. If the default image meets your needs you can use it to provision a EC2 instance using the Terraform template. This is covered in Provision Server.

If the default image does not meet your needs, post on discussions with your requirements. I can help you customize the image.