Vagrant - PugMI

33
Development environments made easy

description

Base usage of Vagrant and my experience. Why Vagrant? What is Vagrant?

Transcript of Vagrant - PugMI

Page 1: Vagrant - PugMI

Development environments made easy

Page 4: Vagrant - PugMI

Boxvagrant box add <name> <url> <*provider>

Vagrant box list

Vagrant box remove <name> <*provider>

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 5: Vagrant - PugMI

$. Vagrant box add precise32 <url>

$. Vagrant init precise32

$. Vagrant up

Goooo!!!

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 6: Vagrant - PugMI

ProvidersVirtualbox, VmWare…

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 7: Vagrant - PugMI

Plugins

$. Vagrant plugin install <name>

$. Vagrant plugin uninstall <name>

$. Vagrant plugin list

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 8: Vagrant - PugMI

ProvisioningHow can i install my services?

Chef Solo - Chef Client

Shell – ansiable

Puppet apply – puppet AgentGianluca - @GianArb – GianArb – gianarb.github.io

Page 9: Vagrant - PugMI

That’s all?!Where are my other commands?!

up – halt –suspend – provisioningReload – destroy - ssh -status

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 10: Vagrant - PugMI

Sharing & ConfThis stuff is beautiful

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 12: Vagrant - PugMI

Network

config.vm.forwardind_port(80, 8080)…

config.vm.network :private_network, IP: “192.168.33.111” **

Config.VM.Network :public_network *

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 13: Vagrant - PugMI

Network

** Config.VM.Network :public_network,:bridge => ‘en1:Wi-Fi (AirPort)’’

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 14: Vagrant - PugMI

Provider

config.vm.provider :virtualbox do |vb| vb.customize [

"modifyvm", :id, "--cpus", 2, "--memory", "1224"]……..

end

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 15: Vagrant - PugMI

Share Folders

config.vm.synced_folder "~/Sites", "/var/www”

:owner=> "www-data", :group=> "www-data"

Nfs => true **

+

+

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 16: Vagrant - PugMI

Share Folders

config.vm.synced_folder "~/Sites", "/var/www”

:owner=> "www-data", :group=> "www-data"

Nfs => true **

+

+

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 18: Vagrant - PugMI

**/cookbooks

This is my vendor$. git submodule add

https://github.com/GianArb/opsworks-cookbooks cookbooks

But……Gianluca - @GianArb – GianArb – gianarb.github.io

Page 20: Vagrant - PugMI

Where is my Conf?!

config.vm.provision :chef_solo do |chef| Chef.cookbooks_path=[‘my_cookbooks’,‘cookbooks’

chef.add_recipe “apt” chef.add_recipe “apache2”

chef.Add_recipe “apache2::mod_rewrite” chef.add_recipe “php” chef.add_recipe “MYSQL” ....

end

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 21: Vagrant - PugMI

How can I configure my conf? 0.o

config.vm.provision :chef_solo do |chef| …. chef.add_recipe “MYSQL” chef.json = {

:mysql=> {:server_root_password => ’root’,

:server_debian_password => ’root’,:server_Repl_password => ‘replica’,:bind_address => ‘127.0.0.1’

} }end

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 22: Vagrant - PugMI

config.vm.provision :chef_solo do |chef| …. chef.add_recipe “MYSQL” chef.json = {

:mysql=> {:server_root_password => ’root’,

:server_debian_password => ’root’,:server_Repl_password => ‘replica’,:bind_address => ‘127.0.0.1’

} }end

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 23: Vagrant - PugMI

Shell Provisioning

config.vm.provision :shell,:inline => “echo ‘hello ciao!’”

ORconfig.vm.provision :shell,

:path=> “/path/to/script.sh’”

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 24: Vagrant - PugMI

What happen ifYou can run this

Configuration of VMNow?

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 25: Vagrant - PugMI

Where is my virtualhost?

Is the moment,Now We are Beginning to

Create a custom cookbook for this application

Gianluca - @GianArb – GianArb – gianarb.github.io

Page 26: Vagrant - PugMI

App cookbooks

Gianluca - @GianArb – GianArb – gianarb.github.io

My_cookbooks/app/attributes/default.rbMy_cookbooks/app/recipes/virtualhost.rb

My_cookbooks/app/template/default/app.conf.erb

Page 27: Vagrant - PugMI

My_cookbooks/app/attributes/default.rb

Gianluca - @GianArb – GianArb – gianarb.github.io

In this file are setting all nodes of recipe configuration

default['app']['server_name'] = 'testapp.local'default['app_test']['docroot'] = “/vagrant/src“

Page 28: Vagrant - PugMI

My_cookbooks/app/recipes/virtualhost.rb

Gianluca - @GianArb – GianArb – gianarb.github.io

## Cookbook Name:: app# Recipe:: default#

app_name = 'app'app_config = node[app_name]include_recipe "apt"include_recipe "apache2"include_recipe "apache2::mod_php5"

# Set up the Apache virtual hostweb_app app_name do server_name app_config['server_name'] docroot app_config['docroot'] template "#{app_name}.conf.erb" log_dir node['apache']['log_dir']end

Page 29: Vagrant - PugMI

…./template/default/app.conf.erb

Gianluca - @GianArb – GianArb – gianarb.github.io

<VirtualHost *:80> ServerName <%= @params[:server_name] %> ServerAlias <% @params[:server_aliases] && @params[:server_aliases].each do |a| %><%= "#{a}" %> <% end %> DocumentRoot <%= @params[:docroot] %>

<Directory <%= @params[:docroot] %>> Options -Indexes FollowSymLinks MultiViews AllowOverride All Order allow,deny Allow from all </Directory></VirtualHost>

Page 30: Vagrant - PugMI

Vagrant-omnibus

$. Vagrant plugin install vagrant-omnibus

Gianluca - @GianArb – GianArb – gianarb.github.io

Vagrant.configure("2") do |config| config.omnibus.chef_version = :latest

OR config.omnibus.chef_version = “11.4.0” …end

Page 31: Vagrant - PugMI

BentoCreate your custom .box

Gianluca - @GianArb – GianArb – gianarb.github.io

$. git clone git://github.com/opscode/bento.git$. cd bento$. bundle install

$. bundle exec veewee vbox list$. bundle exec veewee vbox build ubuntu-12.04

Page 32: Vagrant - PugMI

Try now!

Gianluca - @GianArb – GianArb – gianarb.github.io

$. git clone http://github.com/GianArb/pugMi2013-vagrant$. cd pugMi2013-vagrant$. git submodule init$. git submodule update$. cd cookbooks$. git submodule init$. git submodule update