Building OCI machine images with Packer

Oracle recently launched an OCI (Oracle Cloud Infrastructure) builder for Hashicorp’s Packer. If you’re not familiar with Packer, it’s an open source tool for creating identical machine images for multiple platforms from a single source configuration. We originally built this to support work on Spinnaker, a CI/CD tool from Netflix.

Provisioning VMs tends to be slow and brittle. When you need to scale applications elastically in the cloud, the ability to start up hundreds of identical machines instantly is a huge advantage.

I’ll give you a quick overview of how to use Packer to build your first machine images on Oracle’s Cloud. For more information about machine images on OCI check out the docs here https://docs.us-phoenix-1.oraclecloud.com/Content/Compute/Tasks/managingcustomimages.htm

Machine images vs provisioning

While provisioning tools like Ansible, Chef and Puppet have their place, machine images offer a lot of advantages. Namely they can be started instantly and you can be 100% sure that each running machine is identical.

Provisioning VMs tends to be slow and brittle. When you need to scale applications elastically in the cloud, the ability to start up hundreds of identical machines instantly is a huge advantage.

Oracle Cloud Infrastructure uses images to launch instances. You specify an image to use when you launch an instance. You can create a custom image of a Bare Metal instance’s boot disk and use it to launch other instances. Instances you launch from your image include the customizations, configuration, and software installed when you created the image.

Building your first image

The best way to understand Packer is to use it. In this example, we’ll build a machine image that contains Redis server. Once the image is built, you’ll be able to view it in your OCI account and start up compute instances based on this image.

First we need to create a redis.json file that contains the following. Make sure to add your own auth information and compartment. The file is made up of two sections a “builders” section and a “provisioners” section. The builders are all the specific cloud vendors you want to build an image for. Obviously you might want to build images for more than one cloud provider (e.g for AWS and OCI) and you can do that by adding additional builders. We also use a provisioner with type shell to install Redis.

Now we have our configuration file we can use Packer to build our image. Run with

packer build redis.json

It does the following

  1. Creates a Virtual Machine in Oracle Cloud and provisions it using the scripts we defined
  2. Takes a snapshot of the VM and saves it as a machine image

After the image is successfully built you’ll be able to see it inside the OCI Console under “custom images”.

That’s it. If you have any questions about how to use Packer on OCI please get in touch (owain.lewis@oracle.com). I’d love to hear your feedback.

Links

https://www.packer.io/docs/builders/oracle-oci.html

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.