Successfully reported this slideshow.
Your SlideShare is downloading. ×

Vagrant Binding JayDay 2013

Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad
Ad

Check these out next

1 of 66 Ad

More Related Content

Slideshows for you (20)

Viewers also liked (16)

Advertisement

Similar to Vagrant Binding JayDay 2013 (20)

Advertisement

Recently uploaded (20)

Vagrant Binding JayDay 2013

  1. 1. Lightweight and reproducible environments with Vagrant & Puppet & Java
  2. 2. About me •Hendrik Ebbers •Lead of JUG Dortmund •Senior Java Architect at GmbH in Dortmund, Germany •DataFX, ControlsFX,AquaFX, MarvinFX,Vagrant-Binding @hendrikEbbers www.guigarage.com hendrik.ebbers@web.de Let´s talk about this one...
  3. 3. Content •Virtualization •Vagrant •Puppet •Chef •JavaVagrant-Binding API
  4. 4. Virtualization
  5. 5. Machines Virtual Machines VM templates automated VM creation Evolution of VMs
  6. 6. Antipattern by example
  7. 7. By only using VMs we can rebuild any customer system
  8. 8. For each new customer the best matching VM is copied. So no initial setup is needed!
  9. 9. Why not deploy all linux 64bit customer installations on one server VM?
  10. 10. Because we copy the VMs on our Laptops when we travel to the Customer. And we only need the system for one Customer then.
  11. 11. So you have a virtualized Server for every Customer where all developers work on?
  12. 12. No! Only one developer works on one VM. If a developer starts working for a customer he simply copies the VM of another developer or customer.
  13. 13. D evelopers Customers A B C D E 1 2 3 4 5 6
  14. 14. One month later...
  15. 15. Someone updated our SVN. Eclipse can't use it anymore
  16. 16. Oh, it took me 15 minutesto update Eclipse and theSVN plugin
  17. 17. And this was only the first of 50 VMs!!!
  18. 18. Automated VM creation Vagrant VirtualBox Puppet Chef Java
  19. 19. •Don‘t repeat yourself •„Infrastructure-As-Code“ Automated VM creation Devs & Ops havetime for other stuff
  20. 20. Vagrant
  21. 21. Vagrant •configure virtual machines by script •create new instances on the fly •manage theVM lifecycle Vagrant VM create managelifecycle http://www.vagrantup.com
  22. 22. $ vagrant box add lucid32 http:// files.vagrantup.com/lucid32.box $ vagrant init lucid32 $ vagrant up Vagrant add template VM to Vagrant creates VM configuration-script start the virtual machine
  23. 23. Vagrant •build on top of VirtualBox •written in Ruby access by shell & Ruby
  24. 24. Vagrant •provides 2 template boxes by default •simple config-files •easy ssh connection, shared folder, etc. Vagrant::Config.run do |config| config.vm.box = "lucid32" end Ubuntu Lucid 32- & 64-bit it´s just Ruby see great Vagrant documentation
  25. 25. Vagrant 1.1.x •Released this spring •PlugIn API •New Providers Vagrant::Config.run do |config| config.vm.box = "lucid32" end Vagrant.configure("1") „1“ for Vagrant 1.0.x „2“ for Vagrant 1.1.x
  26. 26. Provider & Provisioner •PlugIn API for Providers •Virtual Box,AWS,VMWare Fusion •PlugIn API for Provisioners •Shell, Puppet, Chef,Ansible
  27. 27. Demo
  28. 28. Puppet
  29. 29. Puppet •configure your machines (nodes) by script •install and configure software & services https://puppetlabs.com
  30. 30. Puppet class apache { exec { 'apt-get update': command => '/usr/bin/apt-get update' } package { "apache2": ensure => present, } service { "apache2": ensure => running, require => Package["apache2"], } } include apache Apache2 is installed & started on node
  31. 31. Puppet •package individual components in modules •many online documentations & books out there
  32. 32. Vagrant & Puppet
  33. 33. Vagrant & Puppet •define yourVM withVagrant & configure it with Puppet •Puppet is pre-installed onVagrant boxes Vagrant defines the box Puppet defines the content
  34. 34. Vagrant & Puppet Vagrant::Config.run do |config| config.vm.box = "lucid32" config.vm.provision :puppet do |puppet| puppet.manifests_path = "manifests" puppet.manifest_file = "my_manifest.pp" end end path to Puppet script Vagrantfile
  35. 35. Chef
  36. 36. Chef •Just another Provisioner •Similar to Puppet (at the first look) conventions •Modules = recipes •Module collection = cookbook
  37. 37. Chef config.vm.provision :chef_solo do |chef| chef.cookbooks_path = "my_cookbooks" chef.add_recipe "apache2" chef.json = { :apache => { :site_enabled => true } } end end path to cookbooks use this recipe configure
  38. 38. Vagrant & Chef
  39. 39. Vagrant & Chef •define yourVM withVagrant & configure it with Chef •Chef is pre-installed onVagrant boxes just like Puppet
  40. 40. Demo
  41. 41. Vagrant- Binding configure & manage VMs in Java
  42. 42. Vagrant-Binding •Java Wrapper aroundVagrant •create & startVMs at runtime •onlyVirtualBox is required Let´s have a look
  43. 43. Vagrant-Binding •Builder APIs •JUnit support •Puppet support
  44. 44. Builder API VagrantVmConfig vmConfig = new VagrantVmConfigBuilder() ! ! ! ! .withLucid32Box() ! ! ! ! .withName("myLittleVm") ! ! ! ! .withHostOnlyIp("192.168.50.4") ! ! ! ! .build(); VagrantEnvironment environment = ...; environment.up(); ! ! ! environment.getVm(0).createConnection().execute("touch /tmp1"); environment.destroy(); also builder API available builder API for VM manage VM lifecycle ssh connection
  45. 45. Demo
  46. 46. JUnit support @Test public void testJdbc() { MySql dbHandler = new MySql(ip, db, user, pwd); dbHandler.createMyTable(); dbHandler.insertRow(); assertEquals(1, dbHandler.getRowCount()); dbHandler.clearAndClose(); } what if table already exists? what if host not reachable? parallel processes?
  47. 47. JUnit support @Rule public VagrantTestRule testRule = new VagrantTestRule(createConfig()); public static VagrantConfiguration createConfig() { //Configure VM with MySQL-Server & static ip } @Test public void testJdbc() {...} create VM start VM run UnitTest destroy VM default JUnit annotation manage VM lifecycle use builder API for VM specification use the VM
  48. 48. Demo
  49. 49. QA Portal •Manage all test machines withVagrant & Puppet •Manage lifecycle with Java Super App Nightly Build with MySQL Default installation of the App with MySQL DB Server Super App Nightly Build with Oracle DB Default installation of the App with Oracle DB Server Super App Nightly Build without Database Use this to check the default Errors in UI at startup state: down state: running started by: John state: down Mockup
  50. 50. Workflow example Create VM- Definition Upload to portal Add Link to Jenkins-Job User starts QA Create & configure VM use Trigger Jenkins build use feedback Test the nightly build let´s find some bugs deploy the nightly destroy VM in portal just a click in the portal
  51. 51. Vagrant-Binding https://github.com/guigarage/vagrant-binding fork me on github
  52. 52. Roadmap •RemoveVirtualBox as dependency (VMWare & AWS support) •Chef support •Simpler management of Environments •Better Builder APIs •CreateVagrant boxes at runtime
  53. 53. Puppet Forge
  54. 54. Puppet Forge access •Puppet provied a Repo for default modules •REST API Let´s use this
  55. 55. Puppet Forge access File moduleFolder = new File("..."); PuppetForgeClient client = new PuppetForgeClient(); ! ! ! ! List<PuppetForgeModuleDescription> allDescriptions = ! client.findModules("mongodb"); ! ! for(PuppetForgeModuleDescription desc : allDescriptions) { ! System.out.println("Installing " + desc.getFullName()); ! PuppetForgeModule module = client.findModule(desc); ! client.installToModulesDir(moduleFolder, module); } search install as module at runtime
  56. 56. Demo
  57. 57. Veewee
  58. 58. Veewee •Build newVM definitions •Provides > 100 OS templates •Customize the definition •Export toVM definition asVagrant Box
  59. 59. Veewee templates
  60. 60. Veewee $ bundle exec veewee vbox templates | grep -i ubuntu $ bundle exec veewee vbox define 'mybuntubox' 'ubuntu-12.10-server-amd64' $ bundle exec veewee vbox build 'mybuntubox' list all ubuntu templates define new VM for Virtual Box build VM for Virtual Box
  61. 61. Veewee $ bundle exec veewee vbox export 'myubuntubox' $ vagrant box add 'myubuntubox' 'myubuntubox.box' Vagrant.configure("2") do |config| config.vm.box = "myubuntubox" end Export VM instance as box add box to Vagrant use VM template in Vagrantfile
  62. 62. Vagrant-Binding 2.0
  63. 63. Vagrant-Binding 2.0 •Support of Vagrant 1.1.x •Virtual Box and AWS Provider API •Veewee wrapper •Better Chef and Puppet API •Basic Java / Groovy Provisioner API
  64. 64. Thanks for watching @hendrikEbbers www.guigarage.com hendrik.ebbers@web.de

×