Monday, December 23, 2013

Automate JBoss Teiid Development Environment with Vagrant and VirtualBox

Why To Automate?

What benefits has the development environment automation:
  • Ability to run several development versions in parallel. Each running environment can host a separate branch of the same product. Or keep some unique environment options, like different JVMs (Pentaho Mondrian is a good example);
  • Some complex project which require simultaneous development in several places (happens rare, so it is arguable benefit);
  • Freedom to experiment with your environment. You can always install something, rollback to a stable step, or start from scratch in minutes;
  •  Your development environment configuration now is a code itself. You can debug it, branch, release, or write tests;
  • You can migrate your environment to a new machine or upload it to a cloud in several mouse clicks. You just need to find a way to VNC or RDP to it. Finally you can do an Eclipse development from your android phone! (yeah, right...)
  • If you work for a company, spawn a new environment for new developers would take hours, not days or weeks;
  • Environment upgrades and updates for everyone in your team are centralized, tested and predictable. No more "it works on my side". 
Along with benefits above, here are the things to remember:
  • Your Host machine should have enough RAM and CPU. Maven can build in multiple threads, GWT compile permutations over all available cores. So obviously more you have, and more you can slice for your environments - better they work;
  • Commercial vs Free. If you develop on Windows or Mac - each generated environment should be registered, which means extra $$ and extra complexity;
  • You need good internet connection to generate the environment (can be several GB to download). On opposite side, most of the time you need to do it only once, the large downloads are cached locally;
  • Writing environment automation scripts can be a slow job. Depends of your goals the environment generation process might take from several minutes to several hours, and some stupid typo you carelessly made in the last step would require to start over;
  • You still have to install and get familiar with some (not very complex) tools which help you with the automation;
All this pros and cons are individual. If you think that in your case it worth attention, below is my recipe.

Instant Eclipse Development Environment

My goal is to have a development environment to work on data federation projects with JBoss Teiid. Below is the list of software I put to it, but your task might be different. Due to modularity, you can exclude some items or add new things very quickly.
  • Linux OS. I took Ubuntu 12.04.03 LTS, it is wide-known, considerably stable and supported by large community. No hassle or extra money for licenses.
  • Oracle Java 7 SDK. Installation requires to accept the license agreement, but it can be automated;
  • Apache Maven 3.0.4. I need specifically this version, but script can be easily changed to the most recent;
  • Git as a source control. Just use the one which Ubuntu has in its repository;
  • Eclipse Kepler SR1 for JEE. I need specifically this version, change several lines in script to put another one;
  • JBoss Application Server. I put EAP-6.1.0.Alpha, this is the one which works best with the latest Teiid;
  • Teiid 8.6.0.Final distribution, download and install on JBoss;
  • Latest Teiid 8.7.0.Alpha1 sources;
As a result, you're getting a pretty decent development environment (8 GB RAM, 2 CPU, 32GB storage), which you can immediately fire up and start working on your own project, or extend Teiid itself.
Steps to follow to generate your own environment using the template above:
  1. Get the latest version of Oracle VM VirtualBox. I used 4.3.6. It is free and easy to use virtualization;
  2. Install latest Vagrant. I have version 1.3.5. This is a tool which manages the collection of your virtual environments, takes care about network access and describes how you want to alter the original OS image for your purposes;
  3. Get the latest Packer. Version I used is 0.4.1. This is a nice functional addition to Vagrant, which allows you to get and apply the customizations and easy install additional software on generated box;
  4. Get the packer-teiid template I made for the environment described above. It is hosted on GitHub, so clone or simply download it to some folder;
  5. Go to the packer-template folder and run "packer build ubuntu-12.04.3-desktop-amd64.json". This will start the generation process. After some time (~40 minutes or so), you should see a shiny new "" file in the same folder, around 2GB size;
  6. Now it is a time to add your new box to a Vagrant collection. Type "vagrant box add ubuntu-12.04.3-desktop-amd64" in the packer-teiid folder, or specify a full path to your *.box file if you do it outside;
  7. You can bring your environment up now. If you want to do it in the same folder, run "vagrant up". If you want to do it from other place, you should do "vagrant init" first in this new folder. The generated "Vagrantfile" also included in my project, compare it with the one which appear in your new folder and see the differences ("vb.gui = true" is the most important one, otherwise your environment will start in background).
  8. If everything went well, you should see something line on image below. Feel free to login using vagrant/vagrant credentials, sudo and change the root password, run Eclipse or open JBoss bin folder using a shortcuts on a desktop.
  9. You can get to your running environment from Host using ssh (port 2222 on localhost). To transfer files between Host and Guest, you can use "/vagrant" mapping from inside your Guest. It is mapped to the actual folder on Host machine from where you started your VM box ("packer-teiid" in my case).
  10. To stop your environment, simply run "vagrant halt" or "vagrant suspend". To kill it - "vagrant destroy".
  11. Happy Packing!

Screenshot of Ubuntu Linux Development Environment running under Windows 7 host machine:

No comments:

Post a Comment