loading table of contents...

4.1.6.2. Vagrant

Vagrant is a tool, that allows you to automate the bootstrapping and configuration of virtualized images and thereby provides you with a workflow to test your code in an isolated environment keeping your developers machine clean from any project specific software. By abstracting the virtualization provider and the configuration provisioner, it is highly adaptable to your projects infrastructure.

By default, CoreMedia uses Oracle VirtualBox as the provider and Chef as the provisioner, but there are many free plugins adding other providers and provisioners. A list of free plugins can be seen here. Beside these free plugins there are also several commercial plugins, notably the VMware provider plugin, which is developed by the Vagrant founder himself.

Vagrants main configuration interface is the Vagrantfile, written in a Ruby DSL to configure hardware and network characteristics as well as a provisioning process to be triggered after booting the box.

To control the lifecycle of the boxes, Vagrant comes with an easy to learn command-line interface. Vagrant has commands to start, stop, destroy, suspend and resume the boxes. There are also commands to trigger the provisioning process to update the applications in the boxes. For a complete list of the available commands, either call vagrant --help on your shell or visit the official Vagrant documentation athttps://docs.vagrantup.com/v2/.

As Vagrant uses an approach, where it imports a base box and starts provisioning from that state, CoreMedia provides you with a preconfigured base box, containing only a minimum of preinstalled packages like Java. Visit CoreMedia Vagrant base boxes reference for the current base box state.

[Note]Note

Be aware that Vagrant is NOT a deployment tool for production use, it is a developer aid to get rid of installing and configuring server software on your laptop. More precisely, it closes the gap between infrastructure and code, allowing you to develop and test complex deployment scenarios from within your workspace.

The Vagrant file

The main file in any Vagrant based scenario is the Vagrantfile file, it is the pom.xml file of the virtualization process. In the workspace you will find it beside the main pom.xml at the root directory.

Vagrant.configure("2") do |config|
  ...
  config.vm.box = "coremedia/base"
  config.vm.box_version = "~> 1.16"
  config.omnibus.chef_version = "12.8.1"
  config.vm.define :blueprint do |blueprint_config|
    blueprint_config.vm.network "private_network", ip: "192.168.252.100"
    blueprint_config.vm.provider "virtualbox" do |v|
      v.customize ["modifyvm", :id, "--memory", 4096]
      v.customize ["modifyvm", :id, "--cpus", 2]
    end
    blueprint_config.vm.provision "chef_solo" do |chef|
      chef.cookbooks_path = path_cookbooks
      chef.roles_path = path_roles
      chef.add_role("coremedia-box-common")
      ...
    end
  end
end

Example 4.11. Vagrantfile Example


In the Vagrantfile file, several Ruby blocks describe particular configurations. For example the opening Vagrant.configure("2") do |config| block starts the Vagrant DSL, whereas the config.vm.define :blueprint do |blueprint_config| block starts the configuration of a particular box. Within this configuration block, you will encounter two more blocks. The blueprint_config.vm.provider "virtualbox" do |v| block, that defines the Oracle VirtualBox provider and the blueprint_config.vm.provision "chef_solo" do |chef| block, that starts the Chef chef-solo provisioner. For a more comprehensive documentation visit the official Vagrant documentation athttps://docs.vagrantup.com/v2/.