Development environments made easy
Why?!
Gianluca - @GianArb – GianArb – gianarb.github.io
VagrantCommand Line Tool
Gianluca - @GianArb – GianArb – gianarb.github.io
Boxvagrant box add <name> <url> <*provider>
Vagrant box list
Vagrant box remove <name> <*provider>
Gianluca - @GianArb – GianArb – gianarb.github.io
$. Vagrant box add precise32 <url>
$. Vagrant init precise32
$. Vagrant up
Goooo!!!
Gianluca - @GianArb – GianArb – gianarb.github.io
ProvidersVirtualbox, VmWare…
Gianluca - @GianArb – GianArb – gianarb.github.io
Plugins
$. Vagrant plugin install <name>
$. Vagrant plugin uninstall <name>
$. Vagrant plugin list
Gianluca - @GianArb – GianArb – gianarb.github.io
ProvisioningHow can i install my services?
Chef Solo - Chef Client
Shell – ansiable
Puppet apply – puppet AgentGianluca - @GianArb – GianArb – gianarb.github.io
That’s all?!Where are my other commands?!
up – halt –suspend – provisioningReload – destroy - ssh -status
Gianluca - @GianArb – GianArb – gianarb.github.io
Sharing & ConfThis stuff is beautiful
Gianluca - @GianArb – GianArb – gianarb.github.io
# -*- mode: ruby -*-# vi: set ft=ruby :
Vagrant::Config.run do |config| config.vm.box = "precise32" config.vm.box_url = http://…./precise32.boxend
mode: ruby
Gianluca - @GianArb – GianArb – gianarb.github.io
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
Network
** Config.VM.Network :public_network,:bridge => ‘en1:Wi-Fi (AirPort)’’
Gianluca - @GianArb – GianArb – gianarb.github.io
Provider
config.vm.provider :virtualbox do |vb| vb.customize [
"modifyvm", :id, "--cpus", 2, "--memory", "1224"]……..
end
Gianluca - @GianArb – GianArb – gianarb.github.io
Share Folders
config.vm.synced_folder "~/Sites", "/var/www”
:owner=> "www-data", :group=> "www-data"
Nfs => true **
+
+
Gianluca - @GianArb – GianArb – gianarb.github.io
Share Folders
config.vm.synced_folder "~/Sites", "/var/www”
:owner=> "www-data", :group=> "www-data"
Nfs => true **
+
+
Gianluca - @GianArb – GianArb – gianarb.github.io
My Skeleton**
Gianluca - @GianArb – GianArb – gianarb.github.io
**/cookbooks
This is my vendor$. git submodule add
https://github.com/GianArb/opsworks-cookbooks cookbooks
But……Gianluca - @GianArb – GianArb – gianarb.github.io
Who is my Vendor?
http://github.com/opscode-cookbooks
Gianluca - @GianArb – GianArb – gianarb.github.io
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
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
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
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
What happen ifYou can run this
Configuration of VMNow?
Gianluca - @GianArb – GianArb – gianarb.github.io
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
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
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“
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
…./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>
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
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
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
Gianluca - @GianArb – GianArb – gianarb.github.io
http://vagrantup.comhttp://github.com/opscode-cookbookshttp://www.vagrantbox.esIrc.freenode.net/#vagrantIrc.freenode.net/#chefhttps://github.com/opscode/bentohttps://github.com/schisamo/vagrant-omnibushttps://github.com/PUGTorino/application_zf
Gianluca [email protected]