Book Image

Vagrant Virtual Development Environment Cookbook

Book Image

Vagrant Virtual Development Environment Cookbook

Overview of this book

Table of Contents (17 chapters)
Vagrant Virtual Development Environment Cookbook
Credits
About the Author
About the Reviewers
www.PacktPub.com
Preface
Index

Introduction


Over the past decade, data centers and server architectures have been revolutionized with the practice of virtualization—the ability to host computational resources that once depended on hardware in specialized software containers. The ability to use flexible virtual environments on shared computational resources allowed system administrators to become more flexible on how software is configured and deployed. More recently, the advantages of virtualization got extended to the desktop. Software packages such as the VMware Desktop (Fusion for OS X, Workstation for Windows and Linux) along with Oracle VirtualBox make it possible to run different operating systems and environments in the context of the desktop operating systems. Web developers, for example, can run a Linux-based web server on their desktop without modifying the parent operating system or running entirely separate physical computers.

Vagrant was originally launched as an open source project by Mitchell Hashimoto with the core idea to make virtual machines simpler to manage. Virtual machines have been used for software development for some time. Some software development teams developed workflows around building virtual machines and shared them with others—often through the creation of a completely configured virtual machine (referred to as a "golden image") and shared by users. If you have worked with virtual environments for any length of time, you are likely to be familiar with the process of downloading a multigigabyte virtual machine or passing around a portable drive with virtual machine files. Vagrant makes it possible to share consistent and reproducible environments with code rather than binary files. In practical terms, this means that a virtual machine is often used by checking out the source definitions from version control and running a vagrant up command rather than finding ways to create, copy, and manage up-to-date versions of large binary files. More recently, Vagrant proved to be so useful and pervasive that Hashimoto founded HashiCorp to support the ongoing development and support of Vagrant. In addition to core Vagrant development, HashiCorp created add-on software that allows Vagrant to use other hypervisor software (plugins for VMware Fusion and Workstation) as well as other software projects. More recently, Vagrant has been extended with the provider framework in order to make development with containers (such as Docker available at http://docker.io) simpler. Developing with containers gives developers the option to create lightweight isolated Linux environments that can be easier and faster to work with these virtual machines.

In any case, the first step when using Vagrant is to set up a working environment in order to define and run Vagrant machines. With Vagrant, a virtual machine and the software that runs inside the machine can be defined in a special file called a Vagrantfile. A Vagrantfile defines a virtual machine, how this virtual machine interacts with the outside world, and how software is installed on the virtual machine.

Before we start with Vagrant, let's review some terminology that we will use in this chapter and throughout the book.

A virtual machine is a computing node that runs within a software process that mimics the behavior of a physical computer. The software process (often called a hypervisor) provides infrastructure to virtual machines such as computing power (CPU), memory (RAM), and interfaces to external resources (such as networking interfaces and physical (disk) storage).

A host machine is a computer that runs a hypervisor to host virtual machines. A host machine will, most likely, run one of two types of hypervisor:

  • A Type 1 hypervisor that runs natively on host machine hardware. A Type 1 hypervisor does not require a separate operating system; the hypervisor itself controls access to physical resources and shares them between hosted virtual environments. Most modern shared virtual environments are Type 1 hypervisors (common examples include VMware ESX/ESXi, Oracle VM Server, and some versions of Microsoft Hyper-V). These environments are typically installed as shared resources that define server infrastructure or other shared resources.

  • A Type 2 hypervisor is a software that runs on top of a traditional operating system. In this case, the hypervisor uses the underlying operating system to control (or define) resources and gain access to resources. Most use cases for Vagrant use Type 2 hypervisors as host environments for virtual machines and this will be the environment that will be used throughout this book. The two common Type 2 hypervisors are Oracle VirtualBox and the VMware Workstation / Fusion family of software. We'll take a look at these products later on in this chapter.

In both cases, the hypervisor is responsible for managing physical resources and sharing them with one or many virtual machines.

A guest machine is a virtual machine that runs within the hypervisor. The machines that we will define with Vagrant are guest machines that operate within the environment controlled by our hypervisor. Guest machines are often entirely different operating systems and environments from the host environment—something we can definitely use to our advantage when developing software to be executed on a different environment from our host. (For example, a developer can write software within a Linux environment that runs on a Windows host or vice versa.)

As we proceed with the recipes, you'll see that Vagrant is a useful tool to manage the complexities of hypervisors and virtual machines. Vagrant also allows a consistent API to operate virtual machines on different hypervisors—something that can make sharing virtual environments much simpler between teams and people working on different platforms.