About Anirudh Bhatnagar

Anirudh is a Java programmer with extensive experience in building Java/J2EE applications. He has always been fascinated by the new technologies and emerging trends in software development. He has been involved in propagating these changes and new technologies in his projects. He is an avid blogger and agile enthusiast who believes in writing clean and well tested code.

Vagrant – a swiss Army knife for every developer

Whenever we move to a new project, or we want to explore a new stack of technologies; we face the problem of environments. Being a developer we generally have a tendency to install everything on our local environment; which many times proves to be a disaster.

Today, modern web applications involve a lot of moving parts, numerous underlying technologies and a lot of complexity. To talk about languages we have JS,python,Ruby,Java,Scala,Closure etc.

For databases there is MySQL, PostgreSQL, Redis, Cassandra, MongoDB etc. And there are multiple web servers, backend servers, application servers and services each with their own use cases (eg. Apache,Unicorn, Nginx, RabbitMQ, Solr etc.)

Installing and uninstalling all these technologies; their combinations and different versions manually on one local system could be a very tedious job.

Another problem with this approach is that every developer would do it in his or her own way and hence the famous “Worked on my system” excuse would appear now and then as the systems where QA are testing might have some difference in some configuration.

So, a better approach would be to install and configure everything on a virtual machine in an automated way, using the concept of Infrastructure as Code, wherein we create blue prints of our infrastructure which could be used to create identical environments in an automated way.

So, how do we create virtual machines, how do we configure them, what about SSH, network configuration, hostname etc.

This is where Vagrant comes into the picture. Vagrant is a tool for building an environment sandboxed in a virtual machine. Vagrant encourages use of shell scripts or configuration management softwares (like chef, puppet etc.) for creation of environments.

Vagrant allows you to work with the same OS that is running in production or QA, irrespective of the OS your physical machine is running. This is possible because Vagrant puts your development environment into a virtual machine. So you can work on different projects; different environments and different teams hassle free. Moreover on boarding a new team member to the project becomes very easy and quick.

Vagrant is a layer on top of some virtualisation solution; which, in one command does the following :

  1. Creates a virtual machine based on the os of your choice.
  2. Modifies physical properties like RAM,CPUs of the vm.
  3. Manage and establish network interfaces to access the vm.
  4. Set up shared folders between host and vm.
  5. Boots the vm, sets the hostname and other properties.
  6. Can club with provisioning softwares like chef and puppet.

So, basically vagrant handles the entire life cycle of the machine for you.

Additionally it can also,

  • SSH into machine
  • shut down machine, destroy machine and completely delete all feta
  • suspend/resume
  • package the machine state so that you can distribute it to other developers (Infrastructure as Code)

Installation

Vagrant works on Linux, Mac OSX and yes on Windows as well. We can download the installers based on the choice of OS from here. The complete documentation can be found here. Or for a more detailed installation on ubuntu refer my blog here.

Cloud

Another approach is to ditch desktop virtualisation altogether and do development directly in the cloud, such as on EC2. The main benefit of this approach is that it allows the developers to work from incredibly low-powered desktop machines in the environment that closely resembles production environments. The main disadvantage here is that this approach requires and Internet connection and have a much higher financial cost associated with it. So , for experimentation and dev environments cloud can be very expensive solution.

If you are using Vagrant you would be using some automated script or chef/puppet for provisioning and hence replicating this environment to other dev machine or to a QA or prod environment set-up on cloud, would be much easier.

Using Vagrant without Virtual Box

Previously (before 1.1) vagrant could only be used with VirtualBox, but after 1.1 vagrant can be used with VMware,EC2 or any other software providing virtualisation. We can also use vagrant with containers.

There is lxc support for vagrant – https://github.com/fgrehm/vagrant-lxc We can also use docker with vagrant.

So, Vagrant can be clubbed with any underlying virtualisation technology and can provide a seamless interface for it. It can do everything you need to create and manage a virtual machine and helps enforce good practices by use of automation.
 

Reference: Vagrant – a swiss Army knife for every developer from our JCG partner Anirudh Bhatnagar at the anirudh bhatnagar blog.

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

JPA Mini Book

Learn how to leverage the power of JPA in order to create robust and flexible Java applications. With this Mini Book, you will get introduced to JPA and smoothly transition to more advanced concepts.

JVM Troubleshooting Guide

The Java virtual machine is really the foundation of any Java EE platform. Learn how to master it with this advanced guide!

Given email address is already subscribed, thank you!
Oops. Something went wrong. Please try again later.
Please provide a valid email address.
Thank you, your sign-up request was successful! Please check your e-mail inbox.
Please complete the CAPTCHA.
Please fill in the required fields.

Leave a Reply


− 1 = three



Java Code Geeks and all content copyright © 2010-2014, Exelixis Media Ltd | Terms of Use | Privacy Policy | Contact
All trademarks and registered trademarks appearing on Java Code Geeks are the property of their respective owners.
Java is a trademark or registered trademark of Oracle Corporation in the United States and other countries.
Java Code Geeks is not connected to Oracle Corporation and is not sponsored by Oracle Corporation.
Do you want to know how to develop your skillset and become a ...
Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you two of our best selling eBooks for FREE!

Get ready to Rock!
You can download the complementary eBooks using the links below:
Close