Top Banner
VAGRANT Agilizando seu ambiente de desenvolvimento Minicurso
70

Minicurso de Vagrant

Jul 08, 2015

Download

Documents

Leandro Nunes

Minicurso de Vagrant ministrado na 4ª Semana de Ciência da Computação e Tecnologia da Informação (SCTI 2014) - Campos - RJ - Link dos arquivos: https://github.com/LeandroSNunes/mini-curso-vagrant
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Minicurso de Vagrant

VAGRANT

Agilizando seu ambiente de desenvolvimento

Minicurso

Page 2: Minicurso de Vagrant

@leandrosnunes

Leandro Nunes http://leandronunes.com

Page 3: Minicurso de Vagrant

$ for name in {vagrant,git,vim,vboxmanage} ; do which $name ; done

Pré-requisito

Page 4: Minicurso de Vagrant

O QUE É NECESSÁRIO PARA INICIAR UM PROJETO?

Page 5: Minicurso de Vagrant

TODOS FAZEM INSTALAÇÕES LOCAIS

Page 6: Minicurso de Vagrant

FERRAMENTA PARA CONSTRUIR E DISTRIBUIR AMBIENTES DE FORMA SIMPLES

VAGRANT

Page 7: Minicurso de Vagrant

Mitchell Hashimoto @mitchellh

•  Inicio em 2010 •  Desenvolvido em Ruby •  Release 1.6.5 •  HashiCorp 2012

Page 8: Minicurso de Vagrant

O QUE É PRECISO PARA UTILIZAR O VAGRANT?

Page 9: Minicurso de Vagrant

PROVIDER Gerenciador de Máquinas Virtuais

UMA MÁQUINA HOST Maquina para instalar o vagrant – Máquina de Desenvolvimento

VAGRANT www.vagrantup.com

Page 10: Minicurso de Vagrant

PROVIDER

OU OU

DEFAULT OU

OU

Page 11: Minicurso de Vagrant

Download em:

www.vagrantup.com www.virtualbox.org

Page 12: Minicurso de Vagrant

Fonte: http://www.vcritical.com/

GUEST

HOST

Page 13: Minicurso de Vagrant

$ vBoxManage

Page 14: Minicurso de Vagrant

$ mkdir mini-curso-vagrant $ cd mini-curso-vagrant

Page 15: Minicurso de Vagrant

$ vagrant init vagrant init [box-name] [box-url]

Page 16: Minicurso de Vagrant

VagrantFile

VAGRANTFILE_API_VERSION = "2” Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|

config.vm.box = "base”end  

Page 17: Minicurso de Vagrant

BOX

REPRESENTA UM SISTEMA OPERACIONAL INSTALADO PARA UM PROVIDER ESPECÍFICO.

Page 18: Minicurso de Vagrant

BOX BASE vagrantbox.es

vagrantcloud.com

Page 19: Minicurso de Vagrant

$ vagrant init leandrosnunes/precise64

Page 20: Minicurso de Vagrant

VAGRANTFILE_API_VERSION = "2” Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| config.vm.box = ”leandrosnunes/precise64”end  

VagrantFile

Page 21: Minicurso de Vagrant

$ vagrant box add ADDRESS

$ vagrant box list

Page 22: Minicurso de Vagrant

$ vagrant up

Page 23: Minicurso de Vagrant
Page 24: Minicurso de Vagrant

VM RODANDO NO VIRTUALBOX

Page 25: Minicurso de Vagrant
Page 26: Minicurso de Vagrant

$ vagrant ssh

Page 27: Minicurso de Vagrant

$ vagrant halt

Page 28: Minicurso de Vagrant

$ vagrant init $ vagrant box $ vagrant up $ vagrant ssh$ vagrant halt

Page 29: Minicurso de Vagrant

EFETUAR TESTES DE NOVAS FERRAMENTAS

Page 30: Minicurso de Vagrant

$ vagrant up

$ vagrant ssh

$ sudo apt-get update

$ sudo apt-get –y install postgresql

$ sudo apt-get –y install nginx

$ sudo apt-get –y install php

$ sudo apt-get –y uninstall php

$ sudo apt-get –y install ruby

Page 31: Minicurso de Vagrant

$ vagrant up

$ vagrant ssh

$ sudo apt-get update

$ which nginx

$ sudo apt-get –y install nginx

$ which nginx

Page 32: Minicurso de Vagrant

$ vagrant status

Page 33: Minicurso de Vagrant

$ vagrant destroy

Page 34: Minicurso de Vagrant

$ vagrant up

Page 35: Minicurso de Vagrant

MEU IDE PREFERIDO SÓ FUNCIONA NO WINDOWS!

Page 36: Minicurso de Vagrant

AS MODIFICAÇÕES SÃO REFLETIDAS EM TEMPO REAL ENTRE AS MAQUINAS HOST E GUEST

SYNCED FOLDERS

Page 37: Minicurso de Vagrant

$ echo "Mini Curso de Vagrant" > hello_world.txt $ cat hello_world.txt $ vagrant ssh $ cd /vagrant $ ls $ cat hello_world.txt

Page 38: Minicurso de Vagrant

COMO ACESSAR A APLICAÇÃO?

Page 39: Minicurso de Vagrant

UMA REDE NAT É CRIADA POR DEFAULT. A REDE PRIVADA PERMITE ACESSO DE OUTROS DISPOSITIVOS NA MESMA REDE.

NETWORK

Page 40: Minicurso de Vagrant

$ vagrant destroy $ cd ../ $ rm –r mini-curso-vagrant $ git clone [email protected]:LeandroSNunes/mini-curso-vagrant.git $ cd mini-curso-vagrant $ git fetch origin step1 $ git checkout step1 $ git commit –am “update”

Page 41: Minicurso de Vagrant

VagrantFile

config.vm.network :private_network, ip: "192.168.33.30”config.vm.network :forwarded_port, guest: 3000, host: 3000config.vm.network :forwarded_port, guest: 3306, host: 3306config.vm.post_up_message = ”Mini curso de vagrant\n IP: 192.168.33.30"  

Page 42: Minicurso de Vagrant

$ vagrant up

$ vagrant ssh

$ sudo apt-get update

$ sudo apt-get –y install nginx

$ sudo service nginx start

Page 43: Minicurso de Vagrant

Acessando o nginx

Page 44: Minicurso de Vagrant

$ vagrant package

Page 45: Minicurso de Vagrant

AMBIENTE DE DESENVOLVIMENTO IGUAL PARA TODO TIME

Page 46: Minicurso de Vagrant

Postgresql

Nginx Puma

Assets

Page 47: Minicurso de Vagrant

Postgresql Nginx Puma

Assets

Page 48: Minicurso de Vagrant

1 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 2 config.vm.box = "leandrosnunes/precise64" 3 4 config.vm.define :development do |dev| 5 dev.vm.network "private_network", ip: "192.168.33.30" 6 dev.vm.network :forwarded_port, guest: 3306, host: 3306 # mysql 7 8 dev.vm.post_up_message = "Dev mini curso de vagrant\n IP: 192.168.33.30" 9 end10 11 config.vm.define :production do |pro|12 pro.vm.network "private_network", ip: "192.168.33.31"13 14 pro.vm.post_up_message = "Prod mini curso de vagrant\n IP: 192.168.33.31"15 end16 end

Page 49: Minicurso de Vagrant

$ vagrant up

$ vagrant up development

$ vagrant up production

$ vagrant ssh

$ vagrant ssh development

$ vagrant ssh production

Page 50: Minicurso de Vagrant

$ vagrant destroy

$ vagrant destroy development

$ vagrant destroy production

$ vagrant halt

$ vagrant halt development

$ vagrant halt production

Page 51: Minicurso de Vagrant

A APLICAÇÃO PODE RODAR EM AMBIENTE SIMILAR AO DE PRODUÇÃO

Page 52: Minicurso de Vagrant

ACABA COM A FRASE

“FUNCIONA NA MINHA MÁQUINA”

Page 53: Minicurso de Vagrant

1 Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 2 config.vm.box = "leandrosnunes/precise64" 3 4 config.vm.define :development do |dev| 5 dev.vm.network "private_network", ip: "192.168.33.30" 6 dev.vm.network :forwarded_port, guest: 3306, host: 3306 # mysql 7 8 dev.vm.provider "virtualbox" do |vb| 9 vb.customize ["modifyvm", :id, "--memory", "1024"]10 vb.customize ["modifyvm", :id, "--cpus", "1"]11 end12 13 dev.vm.post_up_message = "Dev mini curso de vagrant\n IP: 192.168.33.30"14 end15 16 config.vm.define :production do |pro|17 pro.vm.network "private_network", ip: "192.168.33.31"18 19 pro.vm.provider "virtualbox" do |vb|20 vb.customize ["modifyvm", :id, "--memory", "1024"]21 vb.customize ["modifyvm", :id, "--cpus", "2"]22 end23 24 pro.vm.post_up_message = "Prod mini curso de vagrant\n IP: 192.168.33.31"25 end26 end

Page 54: Minicurso de Vagrant

TAREFAS MANUAIS NÃO PERMITEM QUALIDADE

Page 55: Minicurso de Vagrant

ANSIBLE CHEF PUPPET SHELL

PROVISIONER

Page 56: Minicurso de Vagrant

development 1 dev.vm.provision :puppet do |puppet|2 puppet.module_path = "modules"3 puppet.manifest_file = "development.pp"4 puppet.options = "--verbose --debug"5 end  

production 1 pro.vm.provision :puppet do |puppet|2 puppet.module_path = "modules"3 puppet.manifest_file = "production.pp"4 end  

Page 57: Minicurso de Vagrant

$ vagrant up development

$ vagrant up production

Page 58: Minicurso de Vagrant

$ vagrant provision

Page 59: Minicurso de Vagrant

$ vagrant reload --provision

Page 60: Minicurso de Vagrant

GERÊNCIA DE CONFIGURAÇÃO

Page 61: Minicurso de Vagrant

INCENTIVO PARA PRÁTICAS DO MOVIMENTO DEVOPS

Page 62: Minicurso de Vagrant

PARTICIPAR DE PROJETOS COM PECULIARIDADES DIFERENTES

Page 63: Minicurso de Vagrant

SIMPLICIDADE PARA CONTRIBUIR PARA PROJETOS OPEN SOURCE

Page 64: Minicurso de Vagrant

FUNCIONALIDADES EXTRAS, COMO SUPORTE A OUTROS PROVIDERS

PLUGIN

Page 65: Minicurso de Vagrant

$ vagrant install plugin vagrant-vbguest

$ vagrant install vagrant-librarian-puppet

Page 66: Minicurso de Vagrant

VagrantFile

config.vm.synced_folder ".", "/vagrant", type: "nfs"  

Page 67: Minicurso de Vagrant
Page 68: Minicurso de Vagrant

VAGRANT OPEN SOURCE

Github: https://github.com/mitchellh/vagrant IRC: #vagrant Google Groups: vagrant-up

Page 69: Minicurso de Vagrant

VAGRANT DOCS

http://docs.vagrantup.com/v2/

Page 70: Minicurso de Vagrant

?