lightweight and reproducible environments with vagrant and puppet

23
Lightweight and reproducible environments with Vagrant & Puppet & Java

Upload: hendrik-ebbers

Post on 06-May-2015

2.765 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Lightweight and reproducible environments with vagrant and Puppet

Lightweight and reproducible environments with

Vagrant & Puppet& Java

Page 2: Lightweight and reproducible environments with vagrant and Puppet

About me

•Hendrik Ebbers

•Lead of development at SIC GmbH in Dortmund, Germany

•Lead of JUG Dortmund@hendrikEbbers

[email protected]

Page 3: Lightweight and reproducible environments with vagrant and Puppet

Content

•Vagrant

•Puppet

•Java Vagrant-Binding API

Page 4: Lightweight and reproducible environments with vagrant and Puppet

Vagrant

Page 5: Lightweight and reproducible environments with vagrant and Puppet

Vagrant

•configure virtual machines by script

•create new instances on the fly

•manage the VM lifecycle

Vagrant

VM

crea

te

man

age

lifec

ycle

Page 6: Lightweight and reproducible environments with vagrant and Puppet

$ vagrant box add lucid32 http://files.vagrantup.com/lucid32.box

$ vagrant init lucid32

$ vagrant up

Vagrantadd template VM to Vagrant

creates VM configuration-script

start the virtual machine

Page 7: Lightweight and reproducible environments with vagrant and Puppet

Vagrant

•build on top of VirtualBox

•written in Ruby

access by shell & Ruby

Page 8: Lightweight and reproducible environments with vagrant and Puppet

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

Page 9: Lightweight and reproducible environments with vagrant and Puppet

Puppet

Page 10: Lightweight and reproducible environments with vagrant and Puppet

Puppet

•configure your machines (nodes) by script

•install and configure software & services

Page 11: Lightweight and reproducible environments with vagrant and Puppet

Puppetclass 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

Page 12: Lightweight and reproducible environments with vagrant and Puppet

Puppet

•package individual components in modules

•many online documentations & books out there

Page 13: Lightweight and reproducible environments with vagrant and Puppet

Vagrant&

Puppet

Page 14: Lightweight and reproducible environments with vagrant and Puppet

Vagrant & Puppet

•define your VM with Vagrant & configure it with Puppet

•Puppet is pre-installed on Vagrant boxes

Page 15: Lightweight and reproducible environments with vagrant and Puppet

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" endend path to Puppet script

Vagrantfile

Page 16: Lightweight and reproducible environments with vagrant and Puppet

Vagrant-Binding

configure & manage

VMs in Java

Page 17: Lightweight and reproducible environments with vagrant and Puppet

Vagrant-Binding

•Java Wrapper around Vagrant

•create & start VMs at runtime

•only VirtualBox is required

Page 18: Lightweight and reproducible environments with vagrant and Puppet

Vagrant-Binding

•Builder APIs

•JUnit support

•Puppet support

Page 19: Lightweight and reproducible environments with vagrant and Puppet

Builder APIVagrantVmConfig 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

Page 20: Lightweight and reproducible environments with vagrant and Puppet

JUnit support@Testpublic void testJdbc() {

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

dbHandler.createMyTable();

dbHandler.insertRow();

assertEquals(1, dbHandler.getRowCount());

dbHandler.close();}

what if table already exists?

what if host not reachable?

parallel processes?

Page 21: Lightweight and reproducible environments with vagrant and Puppet

JUnit support

@Rulepublic VagrantTestRule testRule = new VagrantTestRule(createConfig());

public static VagrantConfiguration createConfig() { //Configure VM with MySQL-Server & static ip}

create VM start VM run UnitTest destroy VM

JUnit annotation manage VM lifecycle

use builder API for VM specification

Page 22: Lightweight and reproducible environments with vagrant and Puppet

Vagrant-Binding

https://github.com/guigarage/vagrant-binding

fork me on github

Page 23: Lightweight and reproducible environments with vagrant and Puppet

Thanks for

watching@hendrikEbbers

[email protected]