+ All Categories
Home > Technology > Virtualization with Vagrant (ua.pycon 2011)

Virtualization with Vagrant (ua.pycon 2011)

Date post: 19-Jan-2015
Category:
Upload: dmitry-guyvoronsky
View: 2,520 times
Download: 0 times
Share this document with a friend
Description:
Presentation on topic of using virtualized environment in development and testing, especially for web applications. Prepared for Pycon Ukraine 2011
Popular Tags:
49
Virtual testing & development* * batteries included
Transcript
Page 1: Virtualization with Vagrant (ua.pycon 2011)

Virtual testing & development*

* batteries included

Page 2: Virtualization with Vagrant (ua.pycon 2011)

$ git clone git://server.com/project.git

$ run

Ideal world

Page 3: Virtualization with Vagrant (ua.pycon 2011)
Page 4: Virtualization with Vagrant (ua.pycon 2011)

$ git clone git://server.com/project.git

Real world

Page 5: Virtualization with Vagrant (ua.pycon 2011)

$ git clone git://server.com/project.git

... read help

$ mkdir, cp, vim config.conf, configure, make, make install

... ask guru

$ /project/hidden/blackmagic --fix_that --fix_this --undocumented_parameter=MAGIC_CONST_42

... %^ing @#$@#%@!!!!

Real world

Page 6: Virtualization with Vagrant (ua.pycon 2011)

$ git clone git://server.com/project.git

... read help

$ mkdir, cp, vim config.conf, configure, make, make install

... ask guru

$ /project/hidden/blackmagic --fix_that --fix_this --undocumented_parameter=MAGIC_CONST_42

... %^ing @#$@#%@!!!!

$ run

Real world

Page 7: Virtualization with Vagrant (ua.pycon 2011)
Page 8: Virtualization with Vagrant (ua.pycon 2011)

Why?

Page 9: Virtualization with Vagrant (ua.pycon 2011)

Operating System

User SpaceMusic

WebServer

DBAppServer

IMEditor

Browser

Page 10: Virtualization with Vagrant (ua.pycon 2011)

Problems

• No isolation (oh, wrong binary on path...?)

• Not repeatable (that README ain’t gonna run itself!)

• No guarantees (“..but it works on my computer!”)

Page 11: Virtualization with Vagrant (ua.pycon 2011)

Solution?

Page 12: Virtualization with Vagrant (ua.pycon 2011)
Page 13: Virtualization with Vagrant (ua.pycon 2011)

Operating System

Music

WebServer DBAppServer

IM Editor

BrowserUser Space

Virtualized OS

Page 14: Virtualization with Vagrant (ua.pycon 2011)

Benefits

• Isolation (project and version specific files only)

• Repeatable (snapshots, copies, automation)

• Guarantees (same OS different day)

Page 15: Virtualization with Vagrant (ua.pycon 2011)

Business benefits• Reduce costs (less hardware, lower energy

consumption)

• Backup and data protection

• Application availability

• Less time to respond to changing business needs

• Less time spent on routine tasks

• Better IT department perception

Page 16: Virtualization with Vagrant (ua.pycon 2011)

Time spend on routine tasks according to VMware small & medium business survey

Page 17: Virtualization with Vagrant (ua.pycon 2011)

Why haven’t we been doing this for a long time?

• Big companies have been

• Amazon EC2

• Microsoft

• Google

• Only recently possible on local machines

• Cheat hardware

• Cheap RAM

• Desktop virtualization API

Page 18: Virtualization with Vagrant (ua.pycon 2011)

Ok, let’s go virtual. Now what?

Page 19: Virtualization with Vagrant (ua.pycon 2011)

Vagrant is a tool for building and distributing virtualized development

environments (vagrantup.com)

Page 20: Virtualization with Vagrant (ua.pycon 2011)

VirtualBox is cross-platform virtualization software that works on all the major platforms

(virtualbox.org)

Page 21: Virtualization with Vagrant (ua.pycon 2011)

High level overview

• Describe environment with Vagrantfiles

• Command line interface to manage VM lifecycle

• Automate provisioning and configuration

• Share folder with host OS via NFS

• Provide SSH access to guest OS

• Network multiple VMs

• Package and distribute VMs

Page 22: Virtualization with Vagrant (ua.pycon 2011)

Vagrant boxes• Box = pre-packaged VM environment (~OS

image)

• A number of ready to use boxes @ http://vagrantbox.es

• Ubuntu 32 / 64

• CentOS

• Solaris

• RH

Page 23: Virtualization with Vagrant (ua.pycon 2011)

Vagrantfile• Vagrantfile is to Vagrant as Makefile is to

Make

• Describes VM in code

• One Vagrantfile per project (can contain multiple VMs)

• Commit it to version control

• Actually a Ruby code - easy to extent

Page 24: Virtualization with Vagrant (ua.pycon 2011)

Vagrantfile

Vagrant::Config.run do |config| config.vm.box = “base_ubuntu"end

Page 25: Virtualization with Vagrant (ua.pycon 2011)

Command line$ vagrant help

vagrant init vagrant up vagrant halt vagrant reload vagrant suspend vagrant resume vagrant destroy vagrant provision vagrant package …

Page 26: Virtualization with Vagrant (ua.pycon 2011)
Page 27: Virtualization with Vagrant (ua.pycon 2011)

• Isolation (project and version specific files only)

• Repeatable (snapshots, copies, automation)

• Guarantees (same OS different day)

Page 28: Virtualization with Vagrant (ua.pycon 2011)

Chef is an open-source systems integration framework built specifically for automating the cloud (opscode.com/

chef)

Page 29: Virtualization with Vagrant (ua.pycon 2011)

Puppet is a system for automating system administration tasks, works

on most UNIX-like operating systems (puppetlabs.com)

Page 30: Virtualization with Vagrant (ua.pycon 2011)

How Chef/Puppet works

• You create recipes

• Recipes describe desired system state

• Then you manage your server park

• Safely

• Repeatedly

• In automated way

Page 31: Virtualization with Vagrant (ua.pycon 2011)
Page 32: Virtualization with Vagrant (ua.pycon 2011)

Provisioning in Vagrant

• Use Chef, Puppet, bash scripts, etc. to manage VM configuration

• Repeatable!

• Use same tools for production - Chef, Puppet

Page 33: Virtualization with Vagrant (ua.pycon 2011)

Vagrant + Chef

Vagrant::Config.run do |config| config.vm.box = “base_ubuntu_box"

config.vm.provision :chef_solo do |chef| chef.recipe_url = "http://server/cookbooks.tar.gz"

chef.add_recipe(“aptitude") chef.add_recipe(“apache2") chef.add_recipe(“mysql-server") chef.add_recipe(“python27") chef.add_recipe(“pip") endend

Page 34: Virtualization with Vagrant (ua.pycon 2011)

Networking

• Assign IP to VM in Vagrantfile

• Forward ports

• Access VM from your browser

Page 35: Virtualization with Vagrant (ua.pycon 2011)

Networking

Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.network("10.20.30.49") config.vm.forward_port("web", 80, 4567)end

Page 36: Virtualization with Vagrant (ua.pycon 2011)

• Isolation (project and version specific files only)

• Repeatable (snapshots, copies, automation)

• Guarantees (same OS different day)

Page 37: Virtualization with Vagrant (ua.pycon 2011)

Packaging

• When environment is stable

• Package and distribute prepared VMs

• Minimize setup time

Page 38: Virtualization with Vagrant (ua.pycon 2011)
Page 39: Virtualization with Vagrant (ua.pycon 2011)

• Isolation (project and version specific files only)

• Repeatable (snapshots, copies, automation)

• Guarantees (same OS different day)

Page 40: Virtualization with Vagrant (ua.pycon 2011)

Beyond that• Multi-VM Vagrantfile

• DB

• AppServer

• WebServer

• Use vagrant as library

• Call API functions to do the tasks from Ruby code

• Run custom SSH commands

Page 41: Virtualization with Vagrant (ua.pycon 2011)

Demo

http://youtu.be/O3-MNsowgHc

Page 42: Virtualization with Vagrant (ua.pycon 2011)

Demo

github.com/dreamiurg/timetest

•Django application

•Apache2 + MySQL on single VM

•Additional Python packages like used (South, annoying)

•DB migrations handled by South

•Deployment process

• Vagrant is used to create VM, install required packages and configure services

• Fabric (fabfile.org) is used to populate DB, set up apache2 conf and install Python modules

Page 43: Virtualization with Vagrant (ua.pycon 2011)

Prerequisites

$ <install python>$ <install ruby>$ <install virtualbox>$ gem install vagrant

$ git clone http://server/project.git$ cd project

Page 44: Virtualization with Vagrant (ua.pycon 2011)

Demo: create VM, deploy project

00:00:00 $ vagrant box add base http://server/base.box

... base box for VM is copied to your computer

00:02:00 $ vagrant up

... vagrant creates VM from base box, installs and configures required packages – apt, apache2, mysql, python, git, …

00:05:00 $ fab deploy

... DB is populated with initial data, apache config updated, apache restarted

00:07:00 $ curl http://localhost:8080/

... site is up and running.

Page 45: Virtualization with Vagrant (ua.pycon 2011)

Real world

Page 46: Virtualization with Vagrant (ua.pycon 2011)

Our experience• 10+ projects during last 18 months

• From small (single webserver, no DB) to medium (several webservers + load balancer, master/slave DB replication)

• New developer start time reduced from 2-3 days to 1 hr on average

• Number of deployment/environment defects reduced by 75%

Page 47: Virtualization with Vagrant (ua.pycon 2011)
Page 48: Virtualization with Vagrant (ua.pycon 2011)

Links• http://vagrantup.com

• http://www.vagrantbox.es

• http://fabfile.org

• http://opscode.com

• http://puppetlabs.com

• http://github.com/dreamiurg/timetest

• http://www.vmware.com/files/pdf/VMware-SMB-Survey.pdf

Page 49: Virtualization with Vagrant (ua.pycon 2011)

Dmitry Guyvoronsky

http://about.me/[email protected]

@dreamiurg


Recommended