12
Getting started with Vagrant Guillermo Guerrero Ibarra Simpple [email protected] http: // guillermo. guerreroibarra. com March 5, 2015 Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 1 / 12

Getting started with Vagrant

Embed Size (px)

Citation preview

Getting started with Vagrant

Guillermo Guerrero Ibarra

Simpple

[email protected]: // guillermo. guerreroibarra. com

March 5, 2015

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 1 / 12

Overview

1 IntroWhy Vagrant?

2 VagrantInstallationHow it worksConfiguration

3 ProvisioningWays to provisionCookbooksBerkshelf

4 Interesting linksVagrant auto generators

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 2 / 12

Why Vagrant?

Project dependencies:

DatabasesProgramming languagesDevelopment tools

Isolation

Easy to use

Multiplatform

Compatible with multiple virtualization software:

VirtualBox / VMware / ParallelsSnapshots

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 3 / 12

Vagrant installation

Download and install the following packages:

Virtual box → https://www.virtualbox.org

Vagrant → https://www.vagrantup.com

Chefdk → https://downloads.chef.io/chef-dk

Berkshelf → http://berkshelf.com

$ vagrant plugin install vagrant-berkshelf$ vagrant plugin install vagrant-triggers

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 4 / 12

How it works

Vagrant commands:

init → Vagrantfile

up (First time Vagrant executes provision)

halt

suspend / resume

provision → Shell / Chef

destroy

ssh

Vagrant triggers:

On up

On destroy

On provision

...

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 5 / 12

Vagrant configuration

$ vagrant init → Vagrantfile

1 Vagrant . c o n f i g u r e (2 ) do | c o n f i g |2 c o n f i g . vm . box = ’ ubuntu/ t r u s t y 6 4 ’34 c o n f i g . s sh . f o rwa rd ag en t = t r u e5 c o n f i g . vm . network ’ f o rwa r d ed po r t ’ , : gue s t => 3000 , : ho s t

=> 90006 c o n f i g . vm . network ’ f o rwa r d ed po r t ’ , : gue s t => 3306 , : ho s t

=> 930678 c o n f i g . vm . network ’ p r i v a t e n e two r k ’ , : i p => ’ 1 0 . 1 0 . 1 0 . 1 20 ’9

10 c o n f i g . vm . p r o v i d e r ’ v i r t u a l b o x ’ do | vb |11 vb . memory = ’ 1024 ’12 end13 end

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 6 / 12

Ways to provision

Shell

1 c o n f i g . vm . p r o v i s i o n ” s h e l l ” , i n l i n e : <<−SHELL2 sudo apt−get update3 sudo apt−get i n s t a l l −y apache24 SHELL

Chef

1 c o n f i g . vm . p r o v i s i o n : c h e f s o l o do | che f |2 che f . a d d r e c i p e ’ apt ’3 ch e f . a d d r e c i p e ’ bu i l d−e s s e n t i a l ’4 ch e f . a d d r e c i p e ’ g i t ’5 ch e f . a d d r e c i p e ’ node j s ’6 end

Others → puppet, knife, chef, ansible...Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 7 / 12

Cookbooks

Supermarket → https://supermarket.chef.io

Recipe order is importantChef.json parameters in Vagrantfile

Chef

1 c o n f i g . vm . p r o v i s i o n : c h e f s o l o do | che f |2 che f . a d d r e c i p e ’ apt ’3 ch e f . a d d r e c i p e ’ bu i l d−e s s e n t i a l ’4 ch e f . a d d r e c i p e ’ g i t ’5 ch e f . a d d r e c i p e ’ node j s ’6 ch e f . a d d r e c i p e ’ rvm : : system ’7 che f . a d d r e c i p e ’ rvm : : vag ran t ’8 ch e f . a d d r e c i p e ’ app : : packages ’9 ch e f . a d d r e c i p e ’ app : : mysql ’

10 che f . a d d r e c i p e ’ app : : gemset ’11 che f . a d d r e c i p e ’ app : : env i ronment ’12 che f . a d d r e c i p e ’ app : : post− i n s t a l l ’13 end

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 8 / 12

Berkshelf

Berkshelf → http://berkshelf.com

Berksfile

1 sou r c e ” h t t p s : // supe rmarke t . g e t c h e f . com”23 cookbook ’ apt ’4 cookbook ’ g i t ’5 cookbook ’ bu i l d−e s s e n t i a l ’6 cookbook ’ node j s ’7 cookbook ’ mysql ’8 cookbook ’ rvm ’9 cookbook ’ o p e n s s l ’

10 cookbook ’ app ’ , path : ’ . / s i t e −cookbooks /app ’

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 9 / 12

Custom cookbooks

My example →https://github.com/ryanfox1985/vagrant-rails-dev

Recipes are in ruby

Templates files support erb (parameters)

Cookbooks folders

1 s i t e −cookbooks /app2 a t t r i b u t e s3 l i s t o f a t t r i b u t e s . rb4 r e c i p e s5 l i s t o f r e c i p i e s . rb6 t emp l a t e s7 d e f a u l t s f i l e s8 B e r k s f i l e9 metadata . rb

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 10 / 12

Vagrant auto generators

For noobs:

PuPHPet → https://puphpet.com

Getprotobox → http://getprotobox.com

Phansible → http://phansible.com

Rove → http://rove.io

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 11 / 12

Questions?

Guillermo Guerrero Ibarra (Simpple) Getting started with Vagrant March 5, 2015 12 / 12