12
Virtualização do Ambiente de Desenvolvimento com Vagrant Crie e configure ambientes leves, reproduzíveis e portáteis. http://vagrantup.com Mario Rezende http://about.me/mariorez

Virtualização do Ambiente de Desenvolvimento com Vagrant

Embed Size (px)

DESCRIPTION

"Lightning Talk" realizado no encontro mensal "PHPubSP" (Grupo de usuários PHP de São Paulo) - http://phpsp.org.br/2012/08/phpubsp-talks/

Citation preview

Page 1: Virtualização do Ambiente de Desenvolvimento com Vagrant

Virtualização do Ambiente de

Desenvolvimentocom Vagrant

Crie e configure ambientesleves, reproduzíveis e portáteis.

http://vagrantup.com

Mario Rezendehttp://about.me/mariorez

Page 2: Virtualização do Ambiente de Desenvolvimento com Vagrant

Configuração do Ambiente de Dev

Host Machine

● Dependente do Sistema Operacional

● Softwares relevantes ao Desenvolvimento

● Duplicidade de Softwares( Apache x Nginx | MySQL x Postgre )

● Dificil reproduzir Ambiente de Produção

● Maior velocidade na execusão

Virtual Machine

● Ambiente não interfere na maquina "Host"(isolamento)

● Reproduzir Ambiente de Produção com exatidão.

● Varios Ambientes com configuração diferentes(Apache x Nginx / MySQL x Postgre)

● Lentidão na execução

Page 3: Virtualização do Ambiente de Desenvolvimento com Vagrant

Antes de tudo...

● Instale VirtualBox -> http://www.virtualbox.org

● Instale Vagrant -> http://downloads.vagrantup.com [ Ubuntu: apt-get install vagrant ]

Page 4: Virtualização do Ambiente de Desenvolvimento com Vagrant

$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box

Criando um Ambiente Virtual

$ vagrant box add debian-squeeze-64 ~/my_boxes/debian-squeeze-64.box

[vagrant] Downloading with Vagrant::Downloaders::File...[vagrant] Copying box to temporary location...[vagrant] Extracting box...[vagrant] Verifying box...[vagrant] Cleaning up downloaded box...

Page 5: Virtualização do Ambiente de Desenvolvimento com Vagrant

$ vagrant init lucid32

Vagrantfile configurações do ambiente

Page 6: Virtualização do Ambiente de Desenvolvimento com Vagrant

$ vagrant init debian-squeeze-64

Vagrantfile configurações do ambiente

Page 7: Virtualização do Ambiente de Desenvolvimento com Vagrant

$ vagrant up[default] Importing base box 'debian-squeeze-64'...[default] Matching MAC address for NAT networking...[default] Clearing any previously set forwarded ports...[default] Forwarding ports...[default] -- 22 => 2222 (adapter 1)[default] -- 3306 => 3309 (adapter 1)[default] -- 80 => 9090 (adapter 1)[default] Exporting NFS shared folders...[vagrant] Preparing to edit /etc/exports. Administrator privileges will be required...[sudo] password for mario: * Stopping NFS kernel daemon [ OK ] * Unexporting directories for NFS kernel daemon... [ OK ] * Exporting directories for NFS kernel daemon... [ OK ] * Starting NFS kernel daemon [ OK ][default] Creating shared folders metadata...[default] Clearing any previously set network interfaces...[default] Preparing network interfaces based on configuration...[default] Booting VM...[default] Waiting for VM to boot. This can take a few minutes.[default] VM booted and ready for use![default] Configuring and enabling network interfaces...[default] Mounting shared folders...[default] -- v-root: /vagrant[default] Mounting NFS shared folders...

Vagrant up "levantando" o ambiente

Page 8: Virtualização do Ambiente de Desenvolvimento com Vagrant

mario@deep-thought:~/Projects/test$ ls -altotal 16drwxrwxr-x 2 mario mario 4096 Aug 28 03:00 .drwxrwxr-x 6 mario mario 4096 Aug 28 01:47 ..-rw-rw-r-- 1 mario mario 61 Aug 28 02:31 .vagrant-rw-rw-r-- 1 mario mario 306 Aug 28 02:27 Vagrantfilemario@deep-thought:~/Projects/test$

Vagrant ssh acessando a VM

mario@deep-thought:~/Projects/test$ vagrant sshLinux vagrant-debian-squeeze 2.6.32-5-amd64 #1 SMP Sun May 6 04:00:17 UTC 2012 x86_64Last login: Tue Aug 28 02:55:17 2012 from 10.0.2.2vagrant@vagrant-debian-squeeze:~$ cd /vagrant/vagrant@vagrant-debian-squeeze:/vagrant$ ls -altotal 16drwxrwxr-x 2 vagrant vagrant 4096 Aug 28 03:00 .drwxr-xr-x 23 root root 4096 Aug 28 02:33 ..-rw-rw-r-- 1 vagrant vagrant 61 Aug 28 02:31 .vagrant-rw-rw-r-- 1 vagrant vagrant 306 Aug 28 02:27 Vagrantfilevagrant@vagrant-debian-squeeze:/vagrant$

Page 9: Virtualização do Ambiente de Desenvolvimento com Vagrant

Multi-VM ambientes multiplos

$ vagrant up

$ vagrant up web

$ vagrant up db

Page 10: Virtualização do Ambiente de Desenvolvimento com Vagrant

$ vagrant package --vagrantfile Vagrantfile.pkg --include README.txt[default] Attempting graceful shutdown of VM...[default] Clearing any previously set forwarded ports...[default] Creating temporary directory for export...[default] Exporting VM...[default] Compressing package to: /home/mario/Projects/test/package.box[default] Packaging additional file: Vagrantfile.pkg[default] Packaging additional file: README.txt

Criando Box distrubua seu ambiente

mario@deep-thought:~/Projects/test$ ls -altotal 467512drwxrwxr-x 2 mario mario 4096 Aug 28 03:19 .drwxrwxr-x 6 mario mario 4096 Aug 28 01:47 ..-rw-rw-r-- 1 mario mario 478708224 Aug 28 03:20 package.box-rw-rw-r-- 1 mario mario 0 Aug 28 03:18 README.txt-rw-rw-r-- 1 mario mario 61 Aug 28 02:31 .vagrant-rw-rw-r-- 1 mario mario 306 Aug 28 02:27 Vagrantfile-rw-rw-r-- 1 mario mario 306 Aug 28 02:27 Vagrantfile.pkg

Page 11: Virtualização do Ambiente de Desenvolvimento com Vagrant

cofigure seu ambiente via scriptsProvisioners

Page 12: Virtualização do Ambiente de Desenvolvimento com Vagrant

VALEU !!!

● Vagrant -> http://vagrantup.com

● Vagrant Boxes -> http://www.vagrantbox.es

● VirtualBox -> http://www.virtualbox.org

Mario Rezendehttp://about.me/mariorez