The topic of quickly creating an Oracle development VM is not new. Several years ago Edwin Biemond and Lucas Jellema have written several blogs about this and have given presentations about the topics at various conferences. You can also download ready made Virtualbox images from Oracle here and specifically for SOA Suite here.
Over the years I have created a lot (probably 100+) of virtual machines manually. For SOA Suite, the process of installing the OS, installing the database, installing WebLogic Server, installing SOA Suite itself can be quite time consuming and boring if you have already done it so many times. Finally my irritation has passed the threshold that I needed to automate it! I wanted to easily recreate a clean environment with a new version of specific software. This blog is a start; provisioning an OS and installing the XE database on it. It might seem a lot but this blog contains the knowledge of two days work. This indicates it is easy to get started.
I decided to start from scratch and first create a base Vagrant box using Packer which uses Kickstart. Kickstart is used to configure the OS of the VM such as disk partitioning scheme, root password and initial packages. Packer makes using Kickstart easy and allows easy creation of a Vagrant base box. After the base Vagrant box was created, I can use Vagrant to create the Virtualbox machine, configure it and do additional provisioning such as in this case installing the Oracle XE database.
First install Vagrant from HashiCorp (here).
If you just want a quick VM with Oracle XE database installed, you can skip the Packer part. If you want to have the option to create everything from scratch, you can first create your own a base image with Packer and use it locally or use the Vagrant cloud to share the base box.
Every Vagrant development environment requires a base box. You can search for pre-made boxes at https://vagrantcloud.com/search.
Oracle provides Vagrant boxes you can use here. Those boxes have some default settings. I wanted to know how to create my own box to start with in case I for example wanted to use an OS not provided by Oracle. I was presented with three options in the Vagrant documentation. Using Packer was presented as the most reusable option.
‘Packer is an open source tool for creating identical machine images for multiple platforms from a single source configuration.’ (from here) Download Packer from HashiCorp (here).
Avast Antivirus and maybe other antivirus programs, do not like Packer so you might have to temporarily disable them or tell them Packer can be trusted.
Packer can be used to build Vagrant boxes (here) but also boxes for other platforms such as Amazon and Virtualbox. See here. For VirtualBox there are two so called builders available. Start from from scratch by installing the OS from an ISO file or start from an OVF/OVA file (pre-build VM). Here of course I choose the ISO file since I want to be able to easily update the OS of my VM and do not want to create a new OVF/OVA file for every new OS version. Thus I decided to use the virtualbox-iso builder.
For my ISO file I decided to go with Oracle Linux Release 7 Update 4 for x86 (64 bit) which is currently the most recent version. In order for Packer to work fully autonomous (and make it easy for the developer), you can provide a remote URL to a file you want to download. For Oracle Linux there are several mirrors available which provide that. Look one up close to you here. You have to update the checksum in the template file (see below) when you update the ISO image if you want to run on a new OS version.
template JSON file
In order to use Packer with the virtualbox-iso builder, you first require a template file in JSON format. Luckily samples for these have already been made available here. You should check them though. I made my own version here.
In order to make the automatic installation of Oracle Linux work, you need a Kickstart file. This is generated automatically when performing an installation at /root/anaconda-ks.cfg. Read here. I’ve made my own here in order to have the correct users, passwords, packages installed and swap partition size.
After you have a working Kickstart file and the Packer ol74.json, you can kickoff the build by:
packer build ol74.json
Packer uses a specified username to connect to the VM (present in the template file). This should be a user which is created in the Kickstart script. For example if you have a user root with password Welcome01 in the kickstart file, you can use that one to connect to the VM. Creating the base box will take a while since it will do a complete OS installation and first download the ISO file.
You can put the box remote or keep it local.
Put the box remote
After you have created the box, you can upload it to the Vagrant Cloud so other people can use it. The Vagrant Cloud free option offers unlimited free public boxes (here). The process of uploading a base box to the Vagrant cloud is described here. You first create a box and then upload the file Packer has created as provider.
After you’re done, the result will be a Vagrant box which can be used as base image in the Vagrantfile. This looks like:
Use the box locally
Alternatively you can use the box you’ve created locally:
vagrant box add ol74 file:///d:/vagrant/packer/virtualbox/ol74.box
You of course have to change the box location to be specific to your environment
And use ol74 as box name in your Vagrantfile. You can see an example of a local and remote box here.
If you have recreated your box and want to use the new version in Vagrant to create a new Virtualbox VM:
vagrant box remove ol74
vagrant box add ol74 file:///d:/vagrant/packer/virtualbox/ol74.box
You now have a base clean OS (relatively clean, I added a GUI) and you want to install stuff in it. Vagrant can help you do that. I’ve used a simple shell script to do the provisioning (see here) but you can also use more complex pieces of software like Chef or Puppet. These are of course in the long run better suitable to also update and manage machines. Since this is just a local development machine, I decided to keep it simple.
I’ve prepared the following Vagrant file.
This expects to find a structure like:
These can be downloaded here. Except the oracle-xe-11.2.0-1.0.x86_64.rpm.zip file which can be downloaded here.
Oracle XE comes with a rsp file (a so-called response file) which makes automating the installation easy. This is described here. You just have to fill in some variables like password and port and such. I’ve prepared such a file here.
After everything is setup, you can do:
vagrant up soadb
And it will create the soadb VM for you in Virtualbox