Vagrant is automation software designed to simplify the process of creating and configuring virtual machines for development and test environments.
This post explains how to provision Turbo containers with Vagrant using the new Turbo Provisioner plugin.
Using Turbo with Vagrant and VirtualBox allows containerized environments to be executed within a full hardware-virtualized environment. This is useful when running on non-Windows hosts or when the stronger isolation provided by hardware virtualization is required.
To learn more about Vagrant, see their official website.
Vagrant supports several virtual machine providers but this example uses VirtualBox with the Vagrant Turbo Provisioner to set up a virtual machine with Mozilla Firefox with Adobe Flash Player running in a Turbo container.
(You can skip this section if you already have Vagrant and Virtual Box installed on your machine.)
First, install Vagrant for Windows, available here.
Next, install VirtualBox 4.3. At the time of this post, Vagrant doesn’t officially support VirtualBox 5.0.
Finally, confirm that Vagrant is installed and move on to the next section.
> vagrant --version
Install the Turbo Provisioner for Vagrant
Run the following command to install the Turbo Provisioner for Vagrant.
> vagrant plugin install vagrant-turbo
Create the Vagrantfile
Virtual environments managed by Vagrant are defined in a single configuration file. By convention it should be named Vagrantfile and be present in the current working directory where executing Vagrant commands.
Create a new folder for the demo and open a command prompt from that location.
Run the following command to create an empty Vagrantfile.
> vagrant init
The example below presents our sample Vagrantfile.
VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provider :virtualbox do |v| v.gui = true v.memory = 2048 end config.vm.box = "opentable/win-2012r2-standard-amd64-nocm" config.vm.communicator = :winrm config.vm.guest = :windows config.vm.network :forwarded_port, host: 33389, guest: 3389, id: "rdp", auto_correct: true config.vm.provision :turbo do |turbo| turbo.max_memory_per_shell = 1024 # TODO: provide user credentials to https://turbo.net hub turbo.login :h do |h| h.username = "username" h.password = "password" end turbo.shell :s do |s| s.inline = <<-EOF layer adobe/flash layer mozilla/firefox name firefox EOF end end config.vm.provision :shell, inline: "turbo install firefox" end
The following sections will explain the Vagrantfile step by step.
If you want to blaze ahead and start Vagrant before reading the full post, don’t forget to add your user credentials to the Turbo Hub underneath the TODO comment.
Vagrantfile: Configure the Virtual Machine
The virtual machine configuration in this section is provided as an example. Experienced users may wish to use their own preferred virtual provider settings.
Start VirtualBox with the graphical user interface enabled and allocate 2GB of RAM for the virtual machine. Create the box based on Windows Server 2012 R2 image, available in Vagrant’s Atlas cloud service. Provision the VM using Windows Remote Management. Port forwarding is required to establish a remote desktop connection to the guest machine.
VAGRANTFILE_API_VERSION = "2" Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.provider :virtualbox do |v| v.gui = true v.memory = 2048 end config.vm.box = "opentable/win-2012r2-standard-amd64-nocm" config.vm.communicator = :winrm config.vm.guest = :windows config.vm.network :forwarded_port, host: 33389, guest: 3389, id: "rdp", auto_correct: true end
Vagrantfile: Provision the Turbo Container
Instruct Vagrant to install the latest release of Turbo Plugin on the guest machine by adding a turbo block to the main configuration.
config.vm.provision :turbo do |turbo| end
Increase the quota for maximum memory allocated per remote shell to 1024 MB. Vagrant will check if the Windows default value of 1024 MB was changed by the publisher of the operating system image and increase the limit if necessary.
turbo.max_memory_per_shell = 1024
Replace the default username and password with your Turbo.net Hub credentials. This will allow us to download application images in the next step.
turbo.login :h do |h| h.username = "username" h.password = "password" end
In our example, we will create a container called firefox that will be built using two application images: the latest version of Mozilla Firefox and the Adobe Flash Plugin. Images will be downloaded from the Turbo Hub.
turbo.shell :s do |s| s.inline = <<-EOF layer adobe/flash layer mozilla/firefox name firefox EOF end
The commands used to define the container are TurboScript instructions. For a complete list of available commands, see the TurboScript documentation.
Finally, add a shortcut for the firefox container to Start Menu using the turbo install command.
config.vm.provision :shell, inline: "turbo install firefox"
Run the Example
Save the Vagrantfile and enter the command below.
> vagrant up
Vagrant will download the base image of the operating system, create a virtual machine in VirtualBox and provision it. Depending on a speed of your Internet connection, the initial run may take a long time.
Once provisioning completes, go to the guest operating system and run the firefox container using the shortcut created in Start Menu.
Now let’s confirm that the Flash Player was layered in. Use Firefox browser to open Adobe Flash Player test page at https://helpx.adobe.com/flash-player.html. Scroll down to find the animation. Can you see it?
You’ve successfully provisioned a Turbo container with Vagrant!
For more examples of Vagrant provisioner for Turbo, check out the project on GitHub.