Initializing the Pairing Server with Vagrant

A pairing server is a centralized environment that is equally accessible by both halves of a pair-programming team. The pairing server contains all of the source code that the pair is working on, as well as the tools needed to run the code.

In most cases, the pairing server will be hosted in the cloud, but we’ll start by building a local virtual machine that’s managed by Vagrant. Vagrant uses Oracle’s VirtualBox to build configurable, lightweight, and portable virtual machines dynamically.[73] Once we work out the details, we’ll deploy our provisioning scripts to the EC2 instance. Because both virtual machines can use the same Ubuntu operating system, the scripts will transfer without difficulty.

You installed Vagrant in the Preface, so let’s open a terminal and run this command to make sure it’s healthy:

 
$ ​vagrant --version
 
Vagrant version 1.2.3

Now run the following commands to create a project directory and initialize the Vagrant configuration for our server.

 
$ ​mkdir ~/pairing-server
 
$ ​cd ~/pairing-server
 
$ ​vagrant init pairing-server http://files.vagrantup.com/precise32.box
 
A `Vagrantfile` has been placed in this directory. You are now
 
ready to `vagrant up` your first virtual environment! Please read
 
the comments in the Vagrantfile as well as documentation on
 
`vagrantup.com` for more information on using Vagrant.

The Vagrantfile tells Vagrant the name of the virtual machine we want to interact with when we use the vagrant command. It also defines the URL of the image we’ll create our server from. We used the 32-bit Ubuntu Precise (version 12.04).

Next, we need to add some extra configuration that will allow us to access a web server running inside of the virtual machine. Open the Vagrantfile and put this code inside the Vagrant::configure("2") block (you can delete all of the comments in it, but leave the config.vm.box and config.vm.box_url settings):

pairing-server/Vagrantfile
 
config.vm.network :forwarded_port, host: 3000, guest: 3000

This will route port 3000 on the virtual machine to port 3000 on the host.

Now we’ll boot our virtual machine. Run this command, but be aware that the first time will take a while as Vagrant downloads the precise32.box image:

 
$ ​vagrant up
 
Bringing machine 'default' up with 'virtualbox' provider...
 
[default] Box 'pairing-server' was not found. Fetching box from specified URL for
 
the provider 'virtualbox'. Note that if the URL does not have
 
a box for this provider, you should interrupt Vagrant now and add
 
the box yourself. Otherwise Vagrant will attempt to download the
 
full box prior to discovering this error.
 
Downloading with Vagrant::Downloaders::HTTP...
 
Downloading box: http://files.vagrantup.com/precise32.box
 
Extracting box...
 
Cleaning up downloaded box...
 
Successfully added box 'pairing-server' with provider 'virtualbox'!
 
[default] Importing base box 'pairing-server'...
 
[default] Matching MAC address for NAT networking...
 
[default] Setting the name of the VM...
 
[default] Clearing any previously set forwarded ports...
 
[default] Creating shared folders metadata...
 
[default] Clearing any previously set network interfaces...
 
[default] Preparing network interfaces based on configuration...
 
[default] Forwarding ports...
 
[default] -- 22 => 2222 (adapter 1)
 
[default] Booting VM...
 
[default] Waiting for VM to boot. This can take a few minutes.
 
[default] VM booted and ready for use!
 
[default] Configuring and enabling network interfaces...
 
[default] Mounting shared folders...
 
[default] -- /vagrant

The virtual machine (VM) is running! Let’s log in with the following command:

 
$ ​vagrant ssh

This will bring us to a vagrant@precise32:~$ prompt, which means that we are inside the virtual machine as the vagrant user. Exit the VM using the exit command, and we’ll start creating our provisioning scripts.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.136.233.153