Lightweight and reproducible environments
                  with

Vagrant & Puppet
                   & Java
About me

•Hendrik Ebbers
•Lead of development at SIC GmbH in
 Dortmund, Germany
•Lead of JUG Dortmund
•DataFX, JFXtras Contributor
                                     @hendrikEbbers
                                   www.guigarage.com
                               hendrik.ebbers@web.de
Content

•Virtualization
•Vagrant
•Puppet
•Java Vagrant-Binding API
Virtualization
Evolution of VMs
                  achines
       Vir tual M




                            VM temp
Machines                            lates   automated VM
                                               creation
Antipattern by
   example
By only u sing VMs we can
rebuild any customer
system
For ea ch new customer
the b est matching VM is
copied. S o no initial setup
is needed!
Why  not deploy all linux
64bit customer
installat ions on one server
VM?
Because we  copy the VMs on
our Laptop s when we travel
to the Custo mer. And we only
need the system for one
Customer then.
So you   have a virtualized
                            r
Serve r for every Custome
                          rk
whe re all developers wo
on?
No only one de veloper works on
                              s
one VM.  If a developer start
                           e
workin g for a customer h
simp ly copies the VM of
another developer.
e rs
        l op
    e ve
D

           A

           B

           C

           D

           E
                                              Custom
                                                     ers
                      1   2   3   4   5   6
One month
  later...
Some
       one u
 Eclips        pdated
        e can'         our S
               t use         VN.
anymo                 it
      re
Oh, it took m
               e 15 minutes
to update Ec
             lipse and the
SVN plugin
And this was only the
  first of 50 VMs!!!
Automated VM creation
             Vagrant
                               Java



                       Virtu
                            alBox



    Puppet
                                      Chef
Vagrant
Vagrant

                                         Vagrant


•configure virtual machines by script




                                                     manage
                                       create
•create new instances on the fly
•manage the VM lifecycle
                                                VM
Vagrant

                                add template VM to
                                      Vagrant
 $ vagrant box add lucid32 http://
 files.vagrantup.com/lucid32.box

 $ vagrant init lucid32            creates VM
                               configuration-script
 $ vagrant up
                start the virtual
                    machine
Vagrant


•build on top of VirtualBox
•written in Ruby
                    access by shell &
                          Ruby
Vagrant                            Ubuntu
                                           Lucid
                                   32- & 64
                                            -bit


•provides 2 template boxes by default
•simple config-files                 it´s just Ruby

    Vagrant::Config.run do |config|
      config.vm.box = "lucid32"
    end
                                      see great Vagrant
                                       documentation

•easy ssh connection, shared folder, etc.
Demo
Puppet
Puppet


•configure your machines (nodes) by script
•install and configure software & services
Puppet

 class apache {
   exec { 'apt-get update':
     command => '/usr/bin/apt-get update'
   }
   package { "apache2":
     ensure => present,             Ap ache2 is installed
   }                                & started on node
   service { "apache2":
     ensure => running,
     require => Package["apache2"],
   }
 }
 include apache
Puppet


•package individual components in modules
•many online documentations & books out
 there
Vagrant
  &
Puppet
Vagrant & Puppet


•define your VM with Vagrant & configure it
 with Puppet
•Puppet is pre-installed on Vagrant boxes
Vagrant & Puppet
                                         Vagrantfile


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                               ppet script
                            path to Pu
Demo
Vagrant-
Binding
                  manage
    co nfigure &
        VMs   in Java
Vagrant-Binding


•Java Wrapper around Vagrant
•create & start VMs at runtime
•only VirtualBox is required
Vagrant-Binding


•Builder APIs
•JUnit support
•Puppet support
Builder API

VagrantVmConfig vmConfig = new VagrantVmConfigBuilder()
! ! ! ! .withLucid32Box()
! ! ! ! .withName("myLittleVm")              builder API for VM
! ! ! ! .withHostOnlyIp("192.168.50.4")
! ! ! ! .build();
                                               also builder API
VagrantEnvironment environment = ...;          available
environment.up();       manage VM lifecycle
! ! !
environment.getVm(0).createConnection().execute("touch /tmp1");

environment.destroy();                  ssh connection
Demo
JUnit support

                                            st not reachable?
@Test
public void testJdbc() {         what if ho

    dbHandler = new MySql(ip, db, user, pwd);

    dbHandler.createMyTable();
                                      what if table already
    dbHandler.insertRow();            exists?

    assertEquals(1, dbHandler.getRowCount());

    dbHandler.close();                parallel proces
                                                      ses?
}
JUnit support

@Rule      JUnit annotation          manage VM lifecycle
public VagrantTestRule testRule =
       new VagrantTestRule(createConfig());


public static VagrantConfiguration createConfig() {
   //Configure VM with MySQL-Server & static ip
}              use builder API for VM spec
                                           ification




 create VM      start VM     run UnitTest    destroy VM
Demo
Puppet Forge access
File moduleFolder = new File("...");


PuppetForgeClient client = new PuppetForgeClient();
! !
! !
List<PuppetForgeModuleDescription> allDescriptions =
! client.findModules("mongodb");      search
! !

for(PuppetForgeModuleDescription desc : allDescriptions) {
! System.out.println("Installing " + desc.getFullName());
! PuppetForgeModule module = client.findModule(desc);
! client.installToModulesDir(moduleFolder, module);
}
                                 module at
                      install as
                             runtime
Demo
Vagrant-Binding

                             fork me
                                     on github




  https://github.com/guigarage/vagrant-binding
Roadmap
 • Remove VirtualBox as dependency (VMWare
   & AWS support)

 • Chef support

 • Simpler management of Environments

 • Better Builder APIs

 • Create Vagrant boxes at runtime
Thanks
   for
watching
           @hendrikEbbers
         www.guigarage.com
     hendrik.ebbers@web.de

Vagrant-Binding JUG Dortmund

  • 1.
    Lightweight and reproducibleenvironments with Vagrant & Puppet & Java
  • 2.
    About me •Hendrik Ebbers •Leadof development at SIC GmbH in Dortmund, Germany •Lead of JUG Dortmund •DataFX, JFXtras Contributor @hendrikEbbers www.guigarage.com hendrik.ebbers@web.de
  • 3.
  • 4.
  • 5.
    Evolution of VMs achines Vir tual M VM temp Machines lates automated VM creation
  • 6.
  • 7.
    By only using VMs we can rebuild any customer system
  • 8.
    For ea chnew customer the b est matching VM is copied. S o no initial setup is needed!
  • 9.
    Why notdeploy all linux 64bit customer installat ions on one server VM?
  • 10.
    Because we copy the VMs on our Laptop s when we travel to the Custo mer. And we only need the system for one Customer then.
  • 11.
    So you have a virtualized r Serve r for every Custome rk whe re all developers wo on?
  • 12.
    No only onede veloper works on s one VM. If a developer start e workin g for a customer h simp ly copies the VM of another developer.
  • 14.
    e rs l op e ve D A B C D E Custom ers 1 2 3 4 5 6
  • 15.
    One month later...
  • 16.
    Some one u Eclips pdated e can' our S t use VN. anymo it re
  • 17.
    Oh, it tookm e 15 minutes to update Ec lipse and the SVN plugin
  • 18.
    And this wasonly the first of 50 VMs!!!
  • 20.
    Automated VM creation Vagrant Java Virtu alBox Puppet Chef
  • 21.
  • 22.
    Vagrant Vagrant •configure virtual machines by script manage create •create new instances on the fly •manage the VM lifecycle VM
  • 23.
    Vagrant add template VM to Vagrant $ vagrant box add lucid32 http:// files.vagrantup.com/lucid32.box $ vagrant init lucid32 creates VM configuration-script $ vagrant up start the virtual machine
  • 24.
    Vagrant •build on topof VirtualBox •written in Ruby access by shell & Ruby
  • 25.
    Vagrant Ubuntu Lucid 32- & 64 -bit •provides 2 template boxes by default •simple config-files it´s just Ruby Vagrant::Config.run do |config| config.vm.box = "lucid32" end see great Vagrant documentation •easy ssh connection, shared folder, etc.
  • 26.
  • 27.
  • 28.
    Puppet •configure your machines(nodes) by script •install and configure software & services
  • 29.
    Puppet class apache{ exec { 'apt-get update': command => '/usr/bin/apt-get update' } package { "apache2": ensure => present, Ap ache2 is installed } & started on node service { "apache2": ensure => running, require => Package["apache2"], } } include apache
  • 30.
    Puppet •package individual componentsin modules •many online documentations & books out there
  • 31.
  • 32.
    Vagrant & Puppet •defineyour VM with Vagrant & configure it with Puppet •Puppet is pre-installed on Vagrant boxes
  • 33.
    Vagrant & Puppet Vagrantfile 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 ppet script path to Pu
  • 34.
  • 35.
    Vagrant- Binding manage co nfigure & VMs in Java
  • 36.
    Vagrant-Binding •Java Wrapper aroundVagrant •create & start VMs at runtime •only VirtualBox is required
  • 37.
  • 38.
    Builder API VagrantVmConfig vmConfig= new VagrantVmConfigBuilder() ! ! ! ! .withLucid32Box() ! ! ! ! .withName("myLittleVm") builder API for VM ! ! ! ! .withHostOnlyIp("192.168.50.4") ! ! ! ! .build(); also builder API VagrantEnvironment environment = ...; available environment.up(); manage VM lifecycle ! ! ! environment.getVm(0).createConnection().execute("touch /tmp1"); environment.destroy(); ssh connection
  • 39.
  • 40.
    JUnit support st not reachable? @Test public void testJdbc() { what if ho dbHandler = new MySql(ip, db, user, pwd); dbHandler.createMyTable(); what if table already dbHandler.insertRow(); exists? assertEquals(1, dbHandler.getRowCount()); dbHandler.close(); parallel proces ses? }
  • 41.
    JUnit support @Rule JUnit annotation manage VM lifecycle public VagrantTestRule testRule = new VagrantTestRule(createConfig()); public static VagrantConfiguration createConfig() { //Configure VM with MySQL-Server & static ip } use builder API for VM spec ification create VM start VM run UnitTest destroy VM
  • 42.
  • 43.
    Puppet Forge access FilemoduleFolder = new File("..."); PuppetForgeClient client = new PuppetForgeClient(); ! ! ! ! List<PuppetForgeModuleDescription> allDescriptions = ! client.findModules("mongodb"); search ! ! for(PuppetForgeModuleDescription desc : allDescriptions) { ! System.out.println("Installing " + desc.getFullName()); ! PuppetForgeModule module = client.findModule(desc); ! client.installToModulesDir(moduleFolder, module); } module at install as runtime
  • 44.
  • 45.
    Vagrant-Binding fork me on github https://github.com/guigarage/vagrant-binding
  • 46.
    Roadmap • RemoveVirtualBox as dependency (VMWare & AWS support) • Chef support • Simpler management of Environments • Better Builder APIs • Create Vagrant boxes at runtime
  • 47.
    Thanks for watching @hendrikEbbers www.guigarage.com hendrik.ebbers@web.de