Cooking up the best in OS’s Martin de Keijzer 17-08-2013, Borsele Nederland - PHPBenelux Summer BBQ The environment restaurant
May 06, 2015
Cooking up the best in OS’s
Martin de Keijzer17-08-2013, Borsele Nederland - PHPBenelux Summer BBQ
The environment restaurant
A.K.A. Who the hell are you?Introduction
!2
About me
•Martin de Keijzer •Dutch web developer
!3
@Martin1982
PHPBenelux Board Member
Working for Ibuildings
http://www.martindekeijzer.nl
!4
Devs
No PHP in this talk....
Ways to developDev environments
!5
Central server
!6
•Everyone has the same environment
•Code can be tested immediately by PM’s
•Developers don’t need to install stuff
Central server
!7
•If the server is down, everyone’s down
•If the code breaks, a lot of people can’t continue
•Everyone needs access to a critical business asset (even the interns)
Local server
!8
•Everyone has an environment to break
•Deployment tests are easily done by one developer
•Developer freedom of software
Local server
!9
•Developers can install unsupported software
•Every developer needs time to setup an environment
•An environment-dependent change can still break the code
The homeless love restaurantsVagrant
!10
Versionable environment
!11
•Save your environment to a VCS and share
•Everyone can tinker with their environment and rebuild in minutes
•Developers have the freedom to update environments
•Environments can be reviewed by team leads
Versionable environment
!12
•Steep learning curve to make it really functional
We’ll fix this.... today!
Prerequisites
!13
OR
VirtualBox (free)
VMWare (commercial)
Getting started
!15
vagrant init
Create a basic vagrant file
Vagrantfile•# -‐*-‐ mode: ruby -‐*-‐ •# vi: set ft=ruby : !•Vagrant.configure("2") do |config| • config.vm.box = "precise64" • config.vm.box_url = "http://dl.dropbox.com/u/1537815/precise64.box" • config.vm.network :private_network, ip: "192.168.33.10" • config.vm.synced_folder ".", "/vagrant_data" • config.vm.provider :virtualbox do |vb| • vb.customize ["modifyvm", :id, "-‐-‐memory", "1024"] • end •end !16
Getting up and running
!17
vagrant up
More options
!18
vagrant suspend
vagrant destroy
vagrant resume
vagrant ssh
Getting up and running
!19
All done! Thank you!
Getting up and running
!20
But how about my software? Nginx? PHP 5.5.1? Solr?
Taking away the hassleProvisioning
!21
Provisioning
!22
Bash
!23
Puppet
!24
Make your restaurant smooth with a ChefChef
!25
Chef
!26
Cookbooks
!27
Utilizing cookbooks•config.vm.provision :chef_solo do |chef| • chef.cookbooks_path = "provision/cookbooks" • chef.add_recipe "wp-‐cli" • chef.add_recipe "wp_site_myproject" • chef.json = { • :mysql => { • :server_debian_password => 'vagrant', • :server_root_password => 'vagrant', • :server_repl_password => 'vagrant' • } • } • end
!28
Vagrant up
!29
The Chef’s best friend for cookbooksLibrarian
!30
Librarian
!31
gem install librarian-‐chef
Create your librarian
!32
librarian-‐chef init
Cheffile
!33
#!/usr/bin/env ruby #^syntax detection site 'http://community.opscode.com/api/v1' !# cookbook 'chef-client' # cookbook 'apache2', '>= 1.0.0' # cookbook 'rvm', # :git => 'https://github.com/fnichol/chef-rvm' # cookbook 'postgresql', # :git => 'https://github.com/findsyou/cookbooks', # :ref => 'postgresql-improvements'
Loading cookbooks
!34
librarian-‐chef install
librarian-‐chef clean
librarian-‐chef update
librarian-‐chef show
When your Chef and Librarian can’t handleKnife
!35
Knife
!36
gem install chef
A new cookbook
•knife cookbook create mybook -‐o ./mycookbooks !37
attributes Default configurationsdefinitions exposed functions
files resource fileslibraries reuseable libraries
metadata.rb Meta informationproviders defines actionsrecipes runnable scripts
resources runs providerstemplates views-like
Metadata.rb
!38
name 'wp-‐cli' maintainer 'Martin de Keijzer' maintainer_email '[email protected]' license 'LGPL V3' description 'Installs/Configures wp-‐cli' long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) version '0.1.0' !depends "curl" depends "git" depends "php" depends "mysql" depends "database"
attributes/default.rb
•default['wp']['wpcli-‐dir'] = '/usr/share/wp-‐cli' •default['wp']['wpcli-‐version'] = '@stable' •default['wp']['wpcli-‐link'] = '/usr/bin/wp'
!39
•Filename must match the recipe name •‘default’ is a special name
recipes/default.rb•# Cookbook Name:: wp-‐cli •# More comments..... •include_recipe 'git' •# More prerequisites !•# create wpcli dir •directory node['wp']['wpcli-‐dir'] do • recursive true •end !•
!40
recipes/default.rb•# download installer •remote_file "#{node['wp']['wpcli-‐dir']}/installer.sh" do • source 'http://wp-‐cli.org/installer.sh' • mode 0755 • action :create_if_missing •end !•
!41
recipes/default.rb•bin_dir = ::File.join(node['wp']['wpcli-‐dir'], 'bin', 'wp') !•# run installer •bash 'install wp-‐cli' do • code './installer.sh' • cwd node['wp']['wpcli-‐dir'] • environment 'INSTALL_DIR' => node['wp']['wpcli-‐dir'], • 'VERSION' => node['wp']['wpcli-‐version'] • creates bin_dir •end •
!42
recipes/default.rb•# link wp bin •link node['wp']['wpcli-‐link'] do • to bin_dir •end if node['wp']['wpcli-‐link']
!43
Cookbook done
!44
Congratulations you’ve taken the first baby steps
in creating a reusable cookbook!
Bonus: templates/default•# redirect met zonder www naar www.<%= @params[:server_name] %> •<VirtualHost *:80> • ServerName <%= @params[:server_name] %> • Redirect / http://www.<%= @params[:server_name] %>/ •</VirtualHost>
!45
Usage from a recipe
•web_app "mysite" do • template "mytemplate.conf.erb" • docroot node[:mysite][:dir] • server_name node[:mysite][:server_name] •end
!46
What have we learned?Conclusion
!47
Conclusion
!48
•Developers require: ‣Virtualbox or VMWare ‣Vagrant
•Team leads / Devops require: ‣All of the above ‣Chef + Knife ‣ Librarian ‣ Enough Server OS experience to cook up the best
environments
QUESTIONS
!49