Oracle Cloud Infrastructure (OCI) offers a wide variety of operating systems that should suit the needs of most large enterprises and customers. However, there may be instances when a company requires a specific or specially customized operating system that is not native to the underlying infrastructure. Businesses looking to migrate from on-premises to the cloud, but have strict operating system requirements that prevent them from using a native platform image, still have the option to Bring Your Own Image (BYOI) into OCI.
The purpose of this blog is to provide solution architects and cloud engineers an automated and easily configurable way to BYOI into Oracle Cloud. It uses VirtualBox as the virtualization environment and Packer to do all the heavy lifting. With the execution of just one command you can go from any linux distribution installation media to a fully customized instance running in OCI.
It is worth noting that this method should only be used when the native platform images do not satisfy some strict set of requirements (e.g. an OS platform requirement, or linux kernel version). Users will always get better support and improved performance when using native platform images. That being said, let’s take a look on how you can import your own customized image into OCI…
Additionally, you will need to create a Cloud Profile in VirtualBox to link it with your OCI account. Those instructions can be found in this White Paper.
An in-depth description of Packer is outside the scope of this blog post, however it is suffice to say for the purposes of this tutorial that a Packer configuration file - also called a template - is a JSON object that has a set of keys configuring various components of Packer. Our packer file will have two main components:
Builders: The builders section contains all the code responsible for creating, installing and configuring the OS in VirtualBox. Builders contain information like the disk size, memory and shape of the virtual machine. In our case, the builders section also contains a link to the linux ISO distribution media and a pointer to a preconfiguration file for automating the OS installation.
Provisioners: The provisioners section contains a list of provisioners that Packer should use to perform any additional configuration of the OS, and install any additional software. There are many provisioner types in packer. In this example we use the 'shell' type which enables us to execute a series of scripts. The
OCI.sh script performs the necessary configuration to make the image compatible within OCI (namely, adding kernel boot parameters and renaming the vNIC). The
cleanup.sh performs some basic actions related to cleaning up the image and reducing its size for upload.
Users who are starting out with this code as a template for their own workflows will want to insert another script in the provisioners section. The added script will be responsible for downloading and installing any additional software you wish to test.
To build the image will need to migrate to the directory containing the github repository, and execute the
packer build command:
packer build <json_template>
When the build process is complete, issue the following command. It will upload the image into OCI object storage, create a custom image, and spin up an instance (you will need to replace the arguments below with values specific to your environment):
VBoxManage export debian-10.6-1299708... \ --output OCI:// \ --cloud 0 \ --vmname debian-10.6_packer \ --cloudprofile DEFAULT \ --cloudbucket vbox-upload \ --cloudlaunchmode PARAVIRTUALIZED \ --cloudshape VM.Standard2.1 \ --clouddomain IYfK:US-ASHBURN-AD-1 \ --clouddisksize 120 \ --cloudocivcn
ocid1.subnet.oc1.iad.aaaaa...\ --cloudkeepobject true \ --cloudlaunchinstance true \ --cloudpublicip true
Now begins the part when you start testing in OCI. To do so, log in to the tenancy where the instance was launched and get its public ip address. You can now ssh into the instance using the public ip and the username/password specified in the preseed file.
There are a few additional considerations you will want to take into account before using this workflow in your environment:
Hopefully you have been able to successfully test your application within OCI. If so you may want to consider adding it to Oracle Marketplace. The same automated workflow outlined in this post to test your application can be refined to test future versions of your application, as well as testing against alternate OSes. When plugged into a DevOps development framework, maintaining your Marketplace Listings with CI/CD with up-to-date versions of your products will be a piece of cake!