The Environment Restaurant

556 views

Published on

Build quick development environments with Vagrant and Chef

0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
556
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
7
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

The Environment Restaurant

  1. 1. The environment restaurant Cooking up the best in OS’s Martin de Keijzer 17-08-2013, Borsele Nederland - PHPBenelux Summer BBQ
  2. 2. Introduction A.K.A. Who the hell are you? !2
  3. 3. About me •Martin de Keijzer •Dutch web developer Working for Ibuildings PHPBenelux Board Member @Martin1982 http://www.martindekeijzer.nl !3
  4. 4. No PHP in this talk.... Devs !4
  5. 5. Dev environments Ways to develop !5
  6. 6. Central server • Everyone has the same environment • Code can be tested immediately by PM’s • Developers don’t need to install stuff !6
  7. 7. Central server • 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) !7
  8. 8. Local server • Everyone has an environment to break • Deployment tests are easily done by one developer • Developer freedom of software !8
  9. 9. Local server • Developers can install unsupported software • Every developer needs time to setup an environment • An environmentdependent change can still break the code !9
  10. 10. Vagrant The homeless love restaurants !10
  11. 11. Versionable environment • 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 !11
  12. 12. Versionable environment • Steep learning curve to make it really functional We’ll fix this.... today! !12
  13. 13. Prerequisites OR VirtualBox (free) VMWare (commercial) !13
  14. 14. Prerequisites http://www.vagrantup.com !14
  15. 15. Getting started vagrant  init Create a basic vagrant file !15
  16. 16. 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
  17. 17. Getting up and running vagrant  up !17
  18. 18. More options vagrant  suspend vagrant  resume vagrant  destroy vagrant  ssh !18
  19. 19. Getting up and running All done! Thank you! !19
  20. 20. Getting up and running But how about my software?
 Nginx? PHP 5.5.1? Solr? !20
  21. 21. Provisioning Taking away the hassle !21
  22. 22. Provisioning !22
  23. 23. Bash !23
  24. 24. Puppet !24
  25. 25. Chef Make your restaurant smooth with a Chef !25
  26. 26. Chef !26
  27. 27. Cookbooks !27
  28. 28. 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
  29. 29. Vagrant up !29
  30. 30. Librarian The Chef’s best friend for cookbooks !30
  31. 31. Librarian gem  install  librarian-­‐chef !31
  32. 32. Create your librarian librarian-­‐chef  init !32
  33. 33. Cheffile #!/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' !33
  34. 34. Loading cookbooks librarian-­‐chef  install librarian-­‐chef  update librarian-­‐chef  clean librarian-­‐chef  show !34
  35. 35. Knife When your Chef and Librarian can’t handle !35
  36. 36. Knife gem  install  chef !36
  37. 37. A new cookbook attributes definitions files libraries metadata.rb providers recipes resources templates Default configurations exposed functions resource files reuseable libraries Meta information defines actions runnable scripts runs providers views-like •knife  cookbook  create  mybook  -­‐o  ./ mycookbooks !37
  38. 38. Metadata.rb name                          'wp-­‐cli'   maintainer              'Martin  de  Keijzer'   maintainer_email  'mdkeijzer@ibuildings.nl'   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" !38
  39. 39. attributes/default.rb •default['wp']['wpcli-­‐dir']  =  '/usr/share/wp-­‐cli'   •default['wp']['wpcli-­‐version']  =  '@stable'   •default['wp']['wpcli-­‐link']  =  '/usr/bin/wp' •Filename must match the recipe name •‘default’ is a special name !39
  40. 40. 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
  41. 41. 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
  42. 42. 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
  43. 43. recipes/default.rb •#  link  wp  bin   •link  node['wp']['wpcli-­‐link']  do   •    to  bin_dir   •end  if  node['wp']['wpcli-­‐link'] !43
  44. 44. Cookbook done Congratulations you’ve taken the first baby steps in creating a reusable cookbook! !44
  45. 45. 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
  46. 46. Usage from a recipe •web_app  "mysite"  do   •    template  "mytemplate.conf.erb"   •    docroot  node[:mysite][:dir]   •    server_name  node[:mysite][:server_name]   •end !46
  47. 47. Conclusion What have we learned? !47
  48. 48. Conclusion •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 !48
  49. 49. QUESTIONS !49
  50. 50. Thank you for listening Bon appetit mdkeijzer@ibuildings.nl @Martin1982

×