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 e •create new instances on the fly t a e r c •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 e h i n m a c a l r t u e v i t h t a r t s
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 s e e g r e a t V a g r a n t d o c u m e n t a t i o n •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": Apache2 is installed ensure => present, } & 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 V a g r a n t f i l e 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 i p t s c r e t u p p o P h t p a t
Vagrant- Binding e g a n a m & e r u g i f n o c a v a J n i s M V
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() builder API for VM � � � � .withName("myLittleVm") � � � � .withHostOnlyIp("192.168.50.4") � � � � .build(); a l s o b u i l d e r A P I a v a i l a b l e VagrantEnvironment environment = ...; manage VM lifecycle environment.up(); � � � environment.getVm(0).createConnection().execute("touch /tmp1"); i o n e c t o n n h c s s environment.destroy();
JUnit support what if host not @Test reachable? public void testJdbc() { dbHandler = new MySql(ip, db, user, pwd); what if table dbHandler.createMyTable(); already exists? dbHandler.insertRow(); assertEquals(1, dbHandler.getRowCount()); p a r a l l e l p dbHandler.close(); r o c e s s e s ? }
JUnit support JUnit annotation e y c l f e c M l i e V n a g m a @Rule public VagrantTestRule testRule = new VagrantTestRule(createConfig()); public static VagrantConfiguration createConfig() { //Configure VM with MySQL-Server & static ip } use builder API for VM specification 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
Recommend
More recommend