August 12, 2015

Applying Vagrant in Software Development

Hello, I am a freelance developer, trainer and DevOps enthusiast. I think Vagrant is a highly underestimated tool in software development and also deeply out shined by Docker. I want to place some spotlight on Vagrant in this article. In my opinion it cut costs in a highly efficient manner and nicely plays along with Docker. It's a virtual machine management console tool implemented and maintained by Hashicorp Inc. and I want to give some insight in how to apply Vagrant and make the best out of it in a developers daily work.

VAGRANT WILL CHANGE HOW YOU WORK

Currently, the developers machine is the holy kingdom in delivering the features and solutions of your company. In front there is the developers IDE and in the back the server, services, queue system and the database. In a multi project setup with branches there are now multiple servers, services and queue systems and databases or just one server and database. Either the developer switches services between projects or redeploys any time he switches the project's context.
In any way it seems cumbersome and it is cumbersome and especially it's a waste of time. Although starting a complex application server running on a developer's machine can be easy as typing:

$ vagrant init mycompany/websphere-7
$ vagrant up

SETUP, CONFIGURE, WORK

The installation and configuration complexity now plays out for each team member and just multiplies. Now let's put that effort inside vagrant boxes and distribute them throughout the team! Actually Backend servers and services should be installed and maintained inside vagrant boxes. I have seen this approach fail in teams. The reasons are manifold:

* The installation process is often not reproduce able and not transparent for team members. There is a lack of trust and team members tend to fall back to old procedures.

* The time to setup a virtual machine in a non automatic manner is very costly. It hurts if it breaks, corrupts or does not boot anymore. Next time team members will fall back to old procedures.

* The virtual machine is maintained and supported by someone that has a tight schedule. Team members can not wait for updates and fall back to old procedures.

* Discordance: Some team members like virtual machines done with Virtualbox but others would never work without VMWare.

VMWARE, VIRTUALBOX, DOCKER, HYPER-V

Vagrant is a tool where the installation process itself can be scripted or in Vagrant slang "Provisioned". Vagrant is a management console for creating, starting and stopping  "Providers" which can be popular virtual machine technologies like Virtualbox, VMWare, Docker and many more. Furthermore, Boxes can be maintained as composites, e.g. managing servers and databases as local clusters. What's left is a powerful host machine but that should be granted for a serious developer.

Realizing a Vagrant box for Websphere, JBoss, MySQL, DB2, PostgreSQL, MongoDB is no wasted effort. It can be easily scripted by console commands inside the Vagrantfile and put under source control and version management. It also supports popular scripting languages like Puppet, Chef, Salt and Ansible. This can be done by team members or operation specialists. The installation is transparent and highly editable.

The Box itself is handled like the software you produce. It is usually enough to simply provision the box by your team. You can also pay external specialists in order to do the provisioning for you and then use review tool in order to accept the installation procedure. Remember, you pay for transparent and readable Vagrantfiles and installation scripts.

BUILD, DOWNLOAD, WORK

Vagrant can be easily maintained as an on-premise solution. Vagrantfiles are written by team members or operation specialists and then checked-in inside the local version control system. Afterwards the boxes are build by Continuous Integration Systems for each checkin and updated using nightly builds. The latest version will be deployed inside an Artifact Repository for immediate download for each developer. The developer simply initializes a template Vagrantfile for his local machine and pulls the required box:

$ vagrant init myimages/mongodb 
$ vagrant up

Boxes can be versioned for any development scenario, projects and customers:

$ vagrant init myimages/mongodb https://myrespository/myimages/mongodb/versions/2.4.14
$ vagrant up

YOUR ENVIRONMENT, YOUR SOLUTION

The whole stack can be implemented inside your company, behind your firewall and in accordance with your operational guidelines. The tools are free to use and open source. My personal preference for an on-premise solution is the following technology stack:

  • Gitlab as the Git Source/Version Control System.
  • Jenkins as the CI- and Build-System with Build Slaves for Vagrant boxes.
  • Artifactory the Artifact Repository for Vagrant Boxes.
  • Virtualbox as the free Open Source VM-Technology.

SUMMARY

Vagrant boxes contain the developers backend systems: Application Servers, Queues and Databases. They are downloaded and fired up in about 30 seconds by any developer. They can be put together to composites, simulate system scenarios and enable system tests. The can be used for evaluation and bug hunting on a developers or operational team machine. Boxes can help to speed up setup work, building, maintaining systems and all in all enable proper DevOps. 

You can be sure it's a big help in keeping heads up in the complex world of IT!

Thanks for reading!

References