Top Banner
Cooking up the best in OS’s Martin de Keijzer 17-08-2013, Borsele Nederland - PHPBenelux Summer BBQ The environment restaurant
50

The Environment Restaurant

May 06, 2015

Download

Documents

Build quick development environments with Vagrant and Chef
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: The Environment Restaurant

Cooking up the best in OS’s

Martin de Keijzer17-08-2013, Borsele Nederland - PHPBenelux Summer BBQ

The environment restaurant

Page 2: The Environment Restaurant

A.K.A. Who the hell are you?Introduction

!2

Page 3: The Environment Restaurant

About me

•Martin de Keijzer •Dutch web developer

!3

@Martin1982

PHPBenelux Board Member

Working for Ibuildings

http://www.martindekeijzer.nl

Page 4: The Environment Restaurant

!4

Devs

No PHP in this talk....

Page 5: The Environment Restaurant

Ways to developDev environments

!5

Page 6: The Environment Restaurant

Central server

!6

•Everyone has the same environment

•Code can be tested immediately by PM’s

•Developers don’t need to install stuff

Page 7: The Environment Restaurant

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)

Page 8: The Environment Restaurant

Local server

!8

•Everyone has an environment to break

•Deployment tests are easily done by one developer

•Developer freedom of software

Page 9: The Environment Restaurant

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

Page 10: The Environment Restaurant

The homeless love restaurantsVagrant

!10

Page 11: The Environment Restaurant

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

Page 12: The Environment Restaurant

Versionable environment

!12

•Steep learning curve to make it really functional

We’ll fix this.... today!

Page 13: The Environment Restaurant

Prerequisites

!13

OR

VirtualBox (free)

VMWare (commercial)

Page 14: The Environment Restaurant

Prerequisites

!14http://www.vagrantup.com

Page 15: The Environment Restaurant

Getting started

!15

vagrant  init

Create a basic vagrant file

Page 16: The Environment Restaurant

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

Page 17: The Environment Restaurant

Getting up and running

!17

vagrant  up

Page 18: The Environment Restaurant

More options

!18

vagrant  suspend

vagrant  destroy

vagrant  resume

vagrant  ssh

Page 19: The Environment Restaurant

Getting up and running

!19

All done! Thank you!

Page 20: The Environment Restaurant

Getting up and running

!20

But how about my software? Nginx? PHP 5.5.1? Solr?

Page 21: The Environment Restaurant

Taking away the hassleProvisioning

!21

Page 22: The Environment Restaurant

Provisioning

!22

Page 23: The Environment Restaurant

Bash

!23

Page 24: The Environment Restaurant

Puppet

!24

Page 25: The Environment Restaurant

Make your restaurant smooth with a ChefChef

!25

Page 26: The Environment Restaurant

Chef

!26

Page 27: The Environment Restaurant

Cookbooks

!27

Page 28: The Environment Restaurant

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

Page 29: The Environment Restaurant

Vagrant up

!29

Page 30: The Environment Restaurant

The Chef’s best friend for cookbooksLibrarian

!30

Page 31: The Environment Restaurant

Librarian

!31

gem  install  librarian-­‐chef

Page 32: The Environment Restaurant

Create your librarian

!32

librarian-­‐chef  init

Page 33: The Environment Restaurant

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'

Page 34: The Environment Restaurant

Loading cookbooks

!34

librarian-­‐chef  install

librarian-­‐chef  clean

librarian-­‐chef  update

librarian-­‐chef  show

Page 35: The Environment Restaurant

When your Chef and Librarian can’t handleKnife

!35

Page 36: The Environment Restaurant

Knife

!36

gem  install  chef

Page 37: The Environment Restaurant

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

Page 38: The Environment Restaurant

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"

Page 39: The Environment Restaurant

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

Page 40: The Environment Restaurant

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

Page 41: The Environment Restaurant

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

Page 42: The Environment Restaurant

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

Page 43: The Environment Restaurant

recipes/default.rb•#  link  wp  bin  •link  node['wp']['wpcli-­‐link']  do  •    to  bin_dir  •end  if  node['wp']['wpcli-­‐link']

!43

Page 44: The Environment Restaurant

Cookbook done

!44

Congratulations you’ve taken the first baby steps

in creating a reusable cookbook!

Page 45: The Environment Restaurant

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

Page 46: The Environment Restaurant

Usage from a recipe

•web_app  "mysite"  do  •    template  "mytemplate.conf.erb"  •    docroot  node[:mysite][:dir]  •    server_name  node[:mysite][:server_name]  •end

!46

Page 47: The Environment Restaurant

What have we learned?Conclusion

!47

Page 48: The Environment Restaurant

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

Page 49: The Environment Restaurant

QUESTIONS

!49

Page 50: The Environment Restaurant

Bon appetit

[email protected]@Martin1982

Thank you for listening