On Github eligolding / virtualization-presentation
by Eli Golding / eligolding@gmail.com / @eli_golding
Individual local development machines
install web server (apache/nginx)...
install PHP...
install MySQL...
install Redis, Memcache, NPM, RVM...
If the dev is not a sysadmin, he might need a ton of help doing this.configure all the things...
get the code...
attempt to serve the application...
configure some more things to get it to work...
Can only have one setup
Inflexible infrastructure
Potential to cause problems with main OS
Port conflicts
Different type of machine than production
explain what a provisioner is!Vagrant is a command line tool that fully controls the creation and provisioning of virtual machines.
Everything is configured in a single file (VagrantFile) that part of the project.
Can be viewed as a wrapper around the VM provider and the provisioner.
The VagrantFile is checked into version control, allowing for great portability.
Vagrant.configure(2) do |config| config.vm.box = "ubuntu/trusty64" config.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "private_network", ip: "192.168.33.10" config.vm.synced_folder ".", "/var/www" config.vm.provision "shell", inline: <<-SHELL sudo apt-get install -y apache2 SHELL end
config.vm.box = "ubuntu/trusty64"
Configures the base box of the machine. Value should be the name of an installed box or a shorthand name of a box in HashiCorp's Atlas.
box_urlconfig.vm.network "forwarded_port", guest: 80, host: 8080 config.vm.network "private_network", ip: "192.168.33.10"
Configures networks on the machine.
config.vm.synced_folder ".", "/var/www"
Synced folders enable Vagrant to sync a folder on the host machine to the guest machine, allowing you to continue working on your project's files on your host machine.
config.vm.provision "shell", inline: <<-SHELL sudo apt-get install -y apache2 SHELL
Set the Provisioners that will automatically install software, alter configurations, and more on the machine as part of the vagrant up process.
Represents a piece of your infrastructure and it's desired state.
execute "composer-install" do cwd '/var/www/app' command "composer install" end
directory "/vagrant/app/cache" do owner "vagrant" group "vagrant" mode 0777 action :create end
link "/etc/nginx/sites-enabled/my-cool-site" do to "/etc/nginx/sites-available/my-cool-site" end
execute "apt-get update" do command "apt-get update" end
apt_package "curl" do action :install end
php_packages = ['php5-cli','php5-curl','php5-mysql'] php_packages.each do |p| apt_package p do action :install end end
template "/etc/nginx/sites-available/my-awesome-site" do source "vhost.erb" variables({ :doc_root => '/var/www', :server_name => 'vagrant.rox' }) action :create notifies :restart, resources(:service => "nginx") end
server { listen 80; root <%= @doc_root %>; index index.html index.php; server_name <%= @server_name %>; location / { try_files $uri $uri/ /index.php; } error_page 404 /404.html; error_page 500 502 503 504 /50x.html; location = /50x.html { root /usr/share/nginx/www; } location ~ \.php$ { fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_pass unix:/var/run/php5-fpm.sock; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; include fastcgi_params; } }
Configuration file that describes resources and their desired state.
Recipes are stored in cookbooks.
Cookbook contain recipes, template, files, custom resources, etc.