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
                                 @hendrikEbbers
                               www.guigarage.com
                           hendrik.ebbers@web.de
Content

•Vagrant
•Puppet
•Java Vagrant-Binding API
Vagrant
Vagrant
                                         Vagrant




                                                     manage lifecycle
•configure virtual machines by script




                                       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
                          by shel l & Ruby
                   access
Vagrant                                  Ubuntu
                                         32- & 64
                                                 Lucid
                                                  -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.
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
   }
   service { "apache2":             & started on node
     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                        path to Puppet script
Vagrant-
Binding
           ure &  manage
    config
       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();        mana ge VM lifecycle
! ! !
environment.getVm(0).createConnection().execute("touch /tmp1");

environment.destroy();                  ssh connection
JUnit support
@Test                            wh at if host not
public void testJdbc() {         reachable?

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

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

    assertEquals(1, dbHandler.getRowCount());

    dbHandler.close();              parallel proces
                                                    ses?
}
JUnit support
             JUnit annotation             manage VM lifecycle
@Rule
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
Vagrant-Binding
                             fork me
                                     on github




  https://github.com/guigarage/vagrant-binding
Thanks
   for
watching
         @hendrikEbbers
       www.guigarage.com
   hendrik.ebbers@web.de

Lightweight and reproducible environments with vagrant and Puppet

  • 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 @hendrikEbbers www.guigarage.com hendrik.ebbers@web.de
  • 3.
  • 4.
  • 5.
    Vagrant Vagrant manage lifecycle •configure virtual machines by script create •create new instances on the fly •manage the VM lifecycle VM
  • 6.
    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
  • 7.
    Vagrant •build on topof VirtualBox •written in Ruby by shel l & Ruby access
  • 8.
    Vagrant Ubuntu 32- & 64 Lucid -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.
  • 9.
  • 10.
    Puppet •configure your machines(nodes) by script •install and configure software & services
  • 11.
    Puppet class apache{ exec { 'apt-get update': command => '/usr/bin/apt-get update' } package { "apache2": ensure => present, Ap ache2 is installed } service { "apache2": & started on node ensure => running, require => Package["apache2"], } } include apache
  • 12.
    Puppet •package individual componentsin modules •many online documentations & books out there
  • 13.
  • 14.
    Vagrant & Puppet •defineyour VM with Vagrant & configure it with Puppet •Puppet is pre-installed on Vagrant boxes
  • 15.
    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 path to Puppet script
  • 16.
    Vagrant- Binding ure & manage config VMs in Java
  • 17.
    Vagrant-Binding •Java Wrapper aroundVagrant •create & start VMs at runtime •only VirtualBox is required
  • 18.
  • 19.
    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(); mana ge VM lifecycle ! ! ! environment.getVm(0).createConnection().execute("touch /tmp1"); environment.destroy(); ssh connection
  • 20.
    JUnit support @Test wh at if host not public void testJdbc() { reachable? dbHandler = new MySql(ip, db, user, pwd); dbHandler.createMyTable(); what if table already exists? dbHandler.insertRow(); assertEquals(1, dbHandler.getRowCount()); dbHandler.close(); parallel proces ses? }
  • 21.
    JUnit support JUnit annotation manage VM lifecycle @Rule 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
  • 22.
    Vagrant-Binding fork me on github https://github.com/guigarage/vagrant-binding
  • 23.
    Thanks for watching @hendrikEbbers www.guigarage.com hendrik.ebbers@web.de