CSC/ECE 517 Spring 2015/ch1a 1 DZ

From Expertiza_Wiki
Revision as of 22:56, 4 February 2015 by Pdeng (talk | contribs)
Jump to navigation Jump to search

Vagrant

Vagrant is a computer software that helps create, configure and manage virtual development or work environments. With its great portability and compatibility, team members can share a common development environment. Therefore minimize the cost of time for deployment and maximize the productivity and flexibility.

Background

Vagrant works with mainstream virtualization softwares like VirtualBox, VMware and AWS or any other provider.

Virtualization Machine

Virtualization machine, which is created by virtualization software, is an emulation of a real computer that provides a complete operating system. In other words, a virtual machine(VM) is a computer with a complete set of hardwares and operating system which runs in your own operating system. In that way, for example, one using Windows operating system can easily install Linux operating system in the VM rather than actually installing it on local machine. Therefore, any changes or modifications in the VM will not propagate to the operating system on which it runs.

Vagrant Box

Boxes are the package format for Vagrant environments. In other words, a box is a packed operating system used by Vagrant. vagrant box is the utility that downloads and manages different types of boxes.
vagrant box add {title} {url} can be executed under either Windows and Unix operating system to add a new box to Vagrant. title is a identifier and can be any text, and url is the network location of the box.
For example:
vagrant box add base hashicorp/precise64 downloads a standard Ubuntu 12.04 LTS 64-bit box from Vagrant Cloud.
vagrant box add base https://dl.dropboxusercontent.com/u/29173892/vagrant-boxes/debian7.3.0-vbox4.3.6-puppet3.4.1.box downloads a Debian 7.3.0 64-bit Puppet 3.4.1 box which is shared by personal user.

Vagrantfile

Vagrantfile is a configuration file which exists in every single vagrant folder. This file allows you to configure some basic settings (including shared folder location, cpu core number and etc.) of the virtual machine.
For example:

config.vm.provider "virtualbox" do |vb|
    vb.memory = "1024"
    vb.cpus="2"
    config.vm.network :forwarded_port, host: 8000, guest: 80
    config.vm.network :forwarded_port, host: 33060, guest: 33060
end

This section of code specifies the memory and CPU core number of the virtual machine. Also, any network traffic on localhost:8000 and localhost:33060 will be forwarded to port 80 and 33060, respectively.

Provision

Provision in Vagrant is a process of automatically install your own softwares and modify configurations during the VM booting up.
Also, this process needs no human interaction and therefore makes it very convenient and repeatable. For example,

config.vm.provider "virtualbox" do |vb|
    config.vm.provision :shell, path: "bootstrap.sh"
end

This section of code enables bootstrap.sh every time the VM is initialized or reloaded.

How it works

Set up

Step 1: Install a mainstream VM software. (e.g. VirtualBox Download Page)
Step 2: Download Vagrant

Configure

Step 1: vagrant box add base hashicorp/precise32 to add a Ubuntu 32bit base box
"base" can be replaced with any text, also "hashicorp/precise32" is replacable. Step 2: vagrant init
If the title of the box is not "base", then you will need to specify the title of the box. For example, vagrant init "my own box"

Work

Step 1: vagrant up or vagrant up --provision if you want to run the VM in provision mode.
Step 2: vagrant ssh to login to the virtual machine.

References