Skip to content

Latest commit

 

History

History
168 lines (115 loc) · 2.63 KB

File metadata and controls

168 lines (115 loc) · 2.63 KB

% Vagrant % Zaki Mughal, CougarCS, University of Houston % 2013-09-12

Questions

  • who knows what a VM is?
  • ...used a VM?

Vagrant

  • spin up virtual machines
  • save your dependencies
  • share your dev environment
    • "But it works on my computer" - Never again.
  • Want to run the code? Just hand over the Vagrantfile.

Let's get started

[ host ] $ mkdir my-cool-project && cd my-cool-project
	# make a project directory and change in to it

[ host ] $ vi cool_script; chmod +x cool_script
    # some code!

Building the VM

[ host ]$ vagrant init precise32 http://files.vagrantup.com/precise32.box
	# this will create Vagrantfile and use precise32.box as our base image

[ host ] $ vagrant up
	# build our VM! (takes ~5 minutes the first time as we download
	# the box over the network)
	# 
	# It'll be faster next time because it will be saved.

Logging in

[ host ] $ vagrant ssh
	# Woot! We have a prompt!

[ vagrant ] $ ls /vagrant/
     # Our files!

[ vagrant ] $ ./cool_script
	# Yay! It runs!

Shared directory

[ vagrant ] $ touch foobar; exit
	# create a file


[ host ] $ ls
	# and it's over here too!

Done for the day

[ host ] $ vagrant suspend
	# save state of memory

# Have you tried turning off and on again?
[ host ] $ vagrant halt
	# shut down

Kill it with fire!

[ host ] $ vagrant destroy
    # VM go bye-bye

Tabula rasa

[ host ] $ vagrant up
	# builds it up again

Vagrantfile (aka the magic!)

Let's take a look


Vagrantfile

Vagrant.configure("2") do |config|
#  ...
  config.vm.provision "shell", path: "provision-vm.sh"
#  ...
end

provision-vm.sh

#!/bin/sh

apt-get update
apt-get --no-install-recommends -y install apache2 # install web server
rm -Rf /var/www # remove www directory contents (don't put a / at the end!)
ln -fs /vagrant /var/www # point www directory to Vagrant

More

  • Grab some custom VM images http://www.vagrantbox.es/
    • different Unix distros
    • different tools: git, MySQL, MongoDB
  • look at what boxes you have
$ vagrant box list