Infrastructure as Code – part 2 – Virtual Machines
The previous part presented information about provisioning and the tools allowing automating configuration management process. This software, beside preparing server infrastructure, can also be used to prepare developers' local working environment.
Of course, it is also possible to use provisioning for developer’s physical machine, however preparing a virtual one, which will serve as an environment for starting developer’s application, is a much more convenient solution that gives more flexibility.
One of the very important aspects in software engineering is virtualisation. People and companies providing hardware have been using this tool for a long time to assure high reliability of infrastructure while maintaining considerable flexibility and good parameters. However, it seems that if developers have got used to virtual machines in test and production environments, working on them in developer environment is still underestimated. Using identical platform in team work, prepared by a person responsible and with appropriate knowledge, can have significant advantages, such as:
- quick start of a new team member
- homogeneous working environment
- easy switching between different versions of environment
- possibility of working on different projects
Vagrant is a tool allowing a convenient and simple work with virtual machines. The elegant simplicity combined with high potential for configuring and expanding makes Vagrant a perfect tool. The most important concepts related to its environment are:
- Box – it is a format of a file including data essential for starting virtual machine i.e. disk or disks image and basic hardware configuration. A very important element is to appropriately prepare operating system. It is required to install and configure ssh services. It is also necessary to create a user named Vagrant with authorized public key available on the website and with possibility of obtaining administrative privileges without having to enter a password – sudo. During the first launch of such a machine, the key is automatically swapped, which ensures the basic safety rules.
- Vagrant cloud – it is a platform containing a catalogue of publicly available boxes. It is an incredibly convenient element of ecosystem because it allows to quickly start working on one of the most popular operating systems fully prepared to work with Vagrant. Provided solutions are safe and can be used as a solid base for building platform for developers. It is also possible to maintain private boxes, however this option is not free.
- Provider – Vagrant allows management of many types of virtual machines. Immediately after installing it, the following tools are available: VirtualBox, VMWare, Hyper-V and Docker. It is also possible to extend this list by creating our own provider.
- Plugin – thanks to the plugin system, it is possible to freely extend Vagrant functionalities. The example of excellent usage of this element are extras that enable virtual machine management in popular clouds, such as Amazon Web Services or Rackspace.
Vagrant has been integrated with popular provisioning tools. Due to that it not only has become useful for developers but also for person responsible for infrastructure and operating system configuration. Before releasing his work, administrator can thoroughly test it in virtual environment.
The Vagrantfile configuration file allows proper configuration of both, single and a set of virtual machines. It allows to define all aspects of work in virtual environment, starting with box, through the network configuration, shared catalogues, tools for provisioning and ending with the detailed information on hardware parameters. It should be added to the version control system so that all engaged people have access to it.
Using Vagrant, we can easily eliminate the need to install on developer’s machine any server applications that are not part of the tools used. In practice, a new member of a team can start working on a project in a few simple steps, assuming that his desktop is equipped with all the necessary developer tools. After downloading source code, required dependencies and building application, it is necessary to give vagrant up command, perform data base migration and start work on a new element of product in development. Additional asset is possibility to switch between projects with different requirements that may collide. For example, it might be applications that use the same data base in different versions and operating system, which doesn’t allow their simultaneous installation.
In the next article
The third, and final part, will be devoted to containers which represent a very interesting alternative for virtualization. A great tool, Docker, will be presented, which wide possibilities are ranging from automating creation of containers, through the management of their local and distributed pools, ending with version control and collaboration.