Vagrant development environments made easy Michele Orselli - - PowerPoint PPT Presentation

vagrant
SMART_READER_LITE
LIVE PREVIEW

Vagrant development environments made easy Michele Orselli - - PowerPoint PPT Presentation

Vagrant development environments made easy Michele Orselli CTO@Ideato _orso_ micheleorselli / ideatosrl mo@ideato.it How many of you are developers? Which is your OS? Win? Mac? Linux? Project setup/configuration can be time consuming


slide-1
SLIDE 1

Vagrant

development environments made easy

slide-2
SLIDE 2

Michele Orselli

CTO@Ideato _orso_ micheleorselli / ideatosrl mo@ideato.it

slide-3
SLIDE 3
slide-4
SLIDE 4
slide-5
SLIDE 5
slide-6
SLIDE 6

How many of you are developers?

slide-7
SLIDE 7

Which is your OS? Win? Mac? Linux?

slide-8
SLIDE 8

Project setup/configuration can be time consuming

slide-9
SLIDE 9

Several clients, several projects in one machine is painful

slide-10
SLIDE 10
slide-11
SLIDE 11

Trying new things is difficult

slide-12
SLIDE 12

Can we do better?

slide-13
SLIDE 13

Virtual machines

slide-14
SLIDE 14
slide-15
SLIDE 15

Meet Vagrant

vagrantup.com

slide-16
SLIDE 16

Vagrant: a command line tool for managing virtual machines

slide-17
SLIDE 17

Providers: virtualbox, vmware, ec2, …

slide-18
SLIDE 18

$ vagrant init hashicorp/precise64 $ vagrant up … enjoy how does it works

slide-19
SLIDE 19

Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.hostname = "myvm" config.vm.box = "hashicorp/precise64" config.vm.network "private_network", ip: "192.168.33.10" config.ssh.forward_agent = true config.vm.synced_folder "./www", "/var/www", type: "nfs", id: “vagrant-root" config.vm.provider :virtualbox do |v| v.customize ["modifyvm", :id, "--memory", 1024] end config.vm.provision "puppet" do |puppet| puppet.manifests_path = "vagrant/puppet/manifests" puppet.manifest_file = "default.pp" puppet.options = '--verbose --modulepath /etc/puppet/modules' end

Vagrantfile

slide-20
SLIDE 20

config.vm.box = "hashicorp/precise64"

preconfigured machines, different flavors all have the same user: vagrant (password: vagrant) Base Boxes

slide-21
SLIDE 21

https://atlas.hashicorp.com/boxes/search

slide-22
SLIDE 22

http://www.vagrantbox.es/

slide-23
SLIDE 23

config.vm.network "private_network", ip: "192.168.33.10"

how to reach the machine private or public Network

slide-24
SLIDE 24

config.vm.synced_folder “./myproject", “/var/ www/myproject”, type: "nfs", id: “vagrant-root"

share your working directory with the vm you can continue using your favorite IDE vm native nfs (sry Win users) rsync synced folders

slide-25
SLIDE 25

config.ssh.forward_agent = true

nice if you need access to private repo don’t need to configure the vm SSH forward agent

slide-26
SLIDE 26

config.vm.hostname = "myvm" config.vm.provider :virtualbox do |vb| vb.memory = "4096" vb.cpus = "4" end

setting hostname, nice if you ssh in the vm setting cpus and memory for performance common settings

slide-27
SLIDE 27

config.vm.provision "puppet" do |puppet| puppet.manifests_path = "vagrant/puppet/manifests" puppet.manifest_file = "default.pp" puppet.options = '--modulepath /etc/puppet/modules' end

configure & install db, files, webserver… provisioners: puppet, chef, ansible, bash, … provisioning

slide-28
SLIDE 28

mysql_database{ 'mydatabase': ensure => present, charset => 'utf8', collate => 'utf8_general_ci', require => Class['mysql::server'], } file { "/var/www/web/logs": ensure => "directory", mode => 777 }

provisioning with puppet

slide-29
SLIDE 29

VMs management

slide-30
SLIDE 30

$ vagrant init $ vagrant up

creating a vm

slide-31
SLIDE 31

$ vagrant provision

provision a vm

slide-32
SLIDE 32

$ vagrant halt

stopping a vm

slide-33
SLIDE 33

$ vagrant reload

reloading a vm

slide-34
SLIDE 34

$ vagrant destroy

destroy a vm

slide-35
SLIDE 35

Usage patterns

slide-36
SLIDE 36

. Vagrantfile vagrant puppet … index.php wp-admin wp-config.php wp-content … wp-cron.php wp-includes xmlrpc.php

config.vm.synced_folder “./", “/var/www/myproj”

  • ne vm, one project
slide-37
SLIDE 37

every project is self contained you might end up with a lot of VMs

  • ne vm, one project
slide-38
SLIDE 38

. vmconfig Vagrantfile vagrant puppet …

  • project1

wp-content … project2 wp-content … project3 wp-content

config.vm.synced_folder “../“, “/var/www/”

  • ne vm, n projects
slide-39
SLIDE 39

good for related apps/projects less duplicated vm

  • ne vm, n projects
slide-40
SLIDE 40

“golden image” pattern share a fully configured vm with your team package your own base box

slide-41
SLIDE 41

$ vagrant package mybox.box

package your own base box

slide-42
SLIDE 42

$ vagrant box add ./mybox.box mybox

config.vm.box = "mybox"

package your own base box

slide-43
SLIDE 43

expose your vm on the internet testing webhook, debugging, … $ vagrant share [--ssh] make your vm accessible

slide-44
SLIDE 44

extends vagrant functionalities tons of plugins:

  • providers
  • provisioners
  • host management

https://github.com/mitchellh/vagrant/wiki/Available-Vagrant-Plugins http://vagrant-lists.github.io/

plugins

slide-45
SLIDE 45

$ vagrant plugin install [plugin] vbguest: keeps vbox guest addition updated hostmanager: modifies your host file install a plugin

slide-46
SLIDE 46

if Vagrant.has_plugin?(“HostManager") config.hostmanager.enabled = true config.hostmanager.manage_host = true config.hostmanager.ignore_private_ip = false config.hostmanager.include_offline = true config.hostmanager.aliases=%w(www.myproj.local) end

configuring hostmanager

slide-47
SLIDE 47

tired of configuring projects? vagrant can help! if you work alone: no shared environment if you work in a team: share project easily wrap up

slide-48
SLIDE 48

Questions?

_orso_ mo@ideato.it

that’s all folks!