Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Consistent Local Development with Vagrant & Chef

Consistent Local Development with Vagrant & Chef

A high level overview of some of these fantastic tools, and some examples of how we've been using them to improve local development environments at the office.

Lew Goettner

July 18, 2012
Tweet

More Decks by Lew Goettner

Other Decks in Technology

Transcript

  1. about me Also, these are additional notes where I felt

    the slide needed a little explanation for Speaker Deck.
  2. PHP WordPress ColdFusion Windows Ubuntu/Red Hat MSSQL MySQL Ruby My

    primary focus, and our mixed bag of technologies.
  3. Supporting non-technical users Slower adoption of new technology Legacy systems

    There is always room for a better way! When you’re stuck in the middle..
  4. “I’ll just run it locally.” - Developer the progression... Except,

    I don’t really want on this crap running my machine all the time.
  5. “I’ll run it in a VM!” - Developer the progression...

    But configuring all this stuff isn’t all that fun.
  6. “I’ll run it in a chef-configured VM!” - Developer the

    progression... Now my biggest gripe is the time it takes to install the OS.
  7. “I’ll run it in a chef-configured VM, based on a

    post-install snapshot.” - Developer the progression... Now we’re talking!
  8. “Why don’t we all start using this?” - Boss /

    Coworker / Intern the progression...
  9. “Vagrant uses Oracle’s VirtualBox to build configurable, lightweight, and portable

    virtual machines dynamically.” - http://vagrantup.com
  10. % vagrant box add precise32 \ http://files.vagrantup.com/precise32.box % vagrant init

    precise32 % vagrant up It’s a URL! So, create your own, and distribute via internet/intranet.
  11. % vagrant box add precise32 \ http://files.vagrantup.com/precise32.box % vagrant init

    precise32 % vagrant up Drops a “Vagrantfile” into the current directory.
  12. It’s just a text file Ruby DSL for configuring your

    VM(s) (no ruby skills required) Vagrantfile
  13. “I’m not impressed.” -Developer Well, there’s some powerful stuff there,

    but maybe you’ve already been doing your own version of this with VMWare, snapshots, etc.
  14. “Chef is an open-source systems integration framework built specifically for

    automating the cloud.” -http://www.opscode.com/chef/
  15. Declarative: What, not how Idempotent: Only take action if required

    Convergent: Takes care of itself Configuration Management
  16. You configure systems with Chef by writing self-documenting code. This

    code is lists of Resources that configure the system to do its job. Declarative Resources
  17. Chef Resources have Providers that take idempotent action to configure

    the resource, but only if it needs to change. Idempotent Actions
  18. INFO: Processing package[apache2] action install (apache2::default line 20) DEBUG: package[apache2]

    checking package status for apache2 DEBUG: package[apache2] current version is 2.2.20-1ubuntu1.1 DEBUG: package[apache2] candidate version is 2.2.20-1ubuntu1.1 DEBUG: package[apache2] is already installed - nothing to do
  19. Chef runs on the system, configuring the Node. In Chef,

    a single run should completely configure the system. Convergent Nodes
  20. Recipes are collected in Cookbooks along with associated components like

    config files or libraries. Continuing the Metaphor
  21. package "ntp" do action :install end template "/etc/ntp.conf" do source

    "ntp.conf.erb" owner "root" group "root" mode 0644 notifies :restart, resources(:service => node[:ntp][:service]) end service node[:ntp][:service] do action :start end
  22. package "ntp" do action :install end template "/etc/ntp.conf" do source

    "ntp.conf.erb" owner "root" group "root" mode 0644 notifies :restart, resources(:service => node[:ntp][:service]) end service node[:ntp][:service] do action :start end Resource to Install Resource to Configure Resource to Start
  23. template "/etc/ntp.conf" do source "ntp.conf.erb" owner "root" group "root" mode

    0644 notifies :restart, resources(:service => node[:ntp] [:service]) end Configure the Package
  24. ntp.conf.erb <% node[:ntp][:servers].each do |ntpserver| -%> server <%= ntpserver %>

    iburst restrict <%= ntpserver %> nomodify notrap noquery <% end -%> A snippet from the ntp.conf.erb template
  25. name "ntp_client" description "Keep the clock in sync on these

    boxes" run_list( "recipe[ntp::default]" ) default_attributes( "ntp" => { "servers" => ["timeserver1.upenn.edu", "timeserver2.upenn.edu"] } ) ntp_client.rb
  26. Server: “Test Box” Role: “ntp_client” Role: “ntp_client” Recipe: “ntp::default” Attributes:

    “ntp.servers” Recipe: “ntp::default” Resource: “package” Installs Software Resource: “template” Builds Config (using Attributes) Resource: “services” Starts Service
  27. Server Role Recipe Resource Resource Resource Role Recipe Resource Resource

    Resource Resource Recipe Resource Recipe Recipe Resource Resource Resource Resource Resource Resource Resource Getting powerful, right?
  28. % chef-client From 0 to configured.. And it’s likely that

    your nodes would be setup to run that for you!
  29. “Eclipse & Plugin X, Y, & Z are better then

    unicorn riding sharks!” - Developer B The Holy Wars Ok, maybe developers don’t actually talk like this..
  30. “Let’s talk this thing to death in IRC!!” - Both

    Developers The Holy Wars Very likely.
  31. Vagrantfile config.vm.share_folder "web", "/var/www", "~/my-site" config.vm.forward_port 80, 8080 Mapping folders

    into the running VM solves the problem. Use what you’d like. Additionally, you never actually have to log into the running VM.
  32. % vagrant destroy Despite all I’ve mentioned to this point,

    this may actually be my favorite vagrant command.
  33. vagrant destroy Blow away the VM. But what’s left? Everything

    required to recreate it at will! Save space, fix problems, tinker at will.
  34. Developer - Before Local Dev? Don’t want it on all

    the time. 1 VM? Mixing Libraries, Dependencies, etc. Multiple VMs: Painful to manage, large footprint
  35. Organization - Before Fixed/shared dev? Developers like different tools Onboarding?

    Long time from hire to productivity Mismatched Envs: Leads to problems in production
  36. Organization - After Providing consistent local development leads to smoother

    deployments, drastically shortens on-boarding time, and puts no regulations on developer tools.
  37. How things fall apart.. 4: Download the two zip files

    that are part of "Cumulative Hot fix 2" Note: Actual Directions!!
  38. How things fall apart.. 4a: Unzip one file, move a

    jar to a specific location, copy *.jar from the /lib folder to one place, copy *.properties from the /lib folder to another place Note: Actual Directions!!
  39. How things fall apart.. 4b: Unzip the other file replacing

    some of your webroot contents Note: Actual Directions!!
  40. How things fall apart.. 5: Download the latest hotfix, unzip,

    and move a .jar to a specific location Note: Actual Directions!!
  41. How things fall apart.. Not pictured: 5-10 More Steps There’s

    SSL stuff, data sources, mapping shared libraries, etc.
  42. Homer Liwag [CC-BY-SA-3.0-2.5-2.0-1.0 (www.creativecommons.org/licenses/by-sa/3.0)], via Wikimedia Commons Ok, no actual

    magic, but when I was tasked with making some changes to one of our legacy systems, I wanted to do it without having to go through the previously described process.
  43. Chef + Vagrant = ❤ Chef+Vagrant setup leads to Collaborative

    effort/forking leads to ColdFusion9 cookbook + internal repos Ended up working with coworkers from other groups to get this setup.
  44. @Training: OS Consistency? 1/2 Windows 1/2 Mac It was time

    for a training, so I surveyed the room to get a feel for the state of people’s dev setups. I don’t think these results would be uncommon in many large organizations.
  45. Tiny Victories! We’ve had some new employees use this process,

    and additionally, have been working toward getting some of the larger projects into this type of setup.
  46. Bundler : Gems :: Librarian : Cookbooks Remember These? If

    you’re familiar with the ruby bundler, you’ll understand librarian immediately.
  47. Cheffile # This branch looks nice! cookbook 'wordpress', :git =>

    'https://github.com/lewg/wordpress', :ref => 'all-the-things' Or from a specific branch of a git repo.
  48. “VCS or GTFU” - Mark Jaquith I saw Mark give

    a presentation a while back with a slide like this, and agreed with the sentiment, so I put it in a previous version of this presentation.
  49. “DVCS or GTFU” - Lew But I wanted to enhance

    it slightly. Unfortunately when I mentioned it to him...
  50. “VCS or GTFO” - Mark Jaquith Sorry about that! The

    correct quote. But I was curious, so I took it to the internet.
  51. Grow the F*ck Up Used when adults are acting like

    kids. - urbandictionary.com GTFU Turns out it means something!
  52. “DVCS or GTFU” - Lew So, it’s a little harsher

    then I would have gone with, but I feel like I’m stuck with it at this point. Also...
  53. “Modern version control systems make these setups insanely easy to

    distribute and modify.” - Lew What I’m trying to say.. And you should be using them if you can.
  54. The Famous 5-Minute Installation Which is great, if you’re running

    a blog. Once you start venturing into CMS territory, you’re adding a ton of stuff.
  55. The Not-so-Famous Full Stack Install Web Server DB Server Plugins

    Custom Theme Matching Matching So it ends up looking more like this.
  56. “Everybody is using it.” Goal: Provide easy to use directions

    to setup a dev environment for non- developers.
  57. What’s it do? Creates a new Ubuntu 12.04 VM Installs

    and configures all server software Apache, PHP, MySQL, Apt, Subversion Downloads & Installs WordPress
  58. What’s it do? Creates a new Ubuntu 12.04 VM Installs

    and configures all server software Apache, PHP, MySQL, Apt, Subversion Downloads & Installs WordPress
  59. What’s it do? Creates a new Ubuntu 12.04 VM Installs

    and configures all server software Apache, PHP, MySQL, Apt, Subversion Downloads & Installs WordPress
  60. What’s it do? Installs 30 wordpress.org plugins Installs 3 paid

    plugins via mapped folder Maps in custom theme folder (own repo)
  61. What’s it do? Installs 30 wordpress.org plugins Installs 3 paid

    plugins via mapped folders Maps in custom theme folder (own repo)
  62. What’s it do? Installs 30 wordpress.org plugins Installs 3 paid

    plugins via mapped folder Maps in custom theme folder (own repo)
  63. What does it REALLY do? Takes a complicated and time

    consuming process, and reduces it to a few minutes.
  64. Build your Production Boxes with Chef Test your Production Cookbooks

    in Vagrant Vagrant to Demo New Features or Software Move to -dev with chef- solo or chef-server Once you start, at any point, you find yourself in this loop.
  65. Apt or Yum cache / Local or Datacenter Host your

    own base boxes Put files into your private Vagrant repos Cache all the things
  66. Vagrant http://vagrantup.com @mitchellh VeeWee https://github.com/jedi4ever/veewee Git http://git-scm.com/ Ruby http://www.ruby-lang.org/ Chef

    http://opscode.com @opscode https://github.com/opscode https://github.com/opscode-cookbooks Librarian https://github.com/applicationsonline/librarian My Github Stuff https://github.com/lewg/