66
Lightweight and reproducible environments with Vagrant & Puppet & Java

Vagrant Binding JayDay 2013

Embed Size (px)

Citation preview

Page 1: Vagrant Binding JayDay 2013

Lightweight and reproducible environments with

Vagrant & Puppet& Java

Page 2: Vagrant Binding JayDay 2013

About me

•Hendrik Ebbers

•Lead of JUG Dortmund

•Senior Java Architect at GmbH in Dortmund, Germany

•DataFX, ControlsFX, AquaFX, MarvinFX, Vagrant-Binding

@hendrikEbbers

[email protected]

Let´s talk about this one...

Page 3: Vagrant Binding JayDay 2013

Content

•Virtualization

•Vagrant

•Puppet

•Chef

•Java Vagrant-Binding API

Page 4: Vagrant Binding JayDay 2013

Virtualization

Page 5: Vagrant Binding JayDay 2013

Machines

Virtual Machines

VM templates automated VM creation

Evolution of VMs

Page 6: Vagrant Binding JayDay 2013

Antipattern by example

Page 7: Vagrant Binding JayDay 2013

By only using VMs we

can rebuild any customer

system

Page 8: Vagrant Binding JayDay 2013

For each new customer the

best matching VM is copied.

So no initial setup is needed!

Page 9: Vagrant Binding JayDay 2013

Why not deploy all

linux 64bit customer

installations on one

server VM?

Page 10: Vagrant Binding JayDay 2013

Because we copy the VMs on

our Laptops when we travel

to the Customer. And we

only need the system for one

Customer then.

Page 11: Vagrant Binding JayDay 2013

So you have a

virtualized Server for

every Customer where

all developers work on?

Page 12: Vagrant Binding JayDay 2013

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.

Page 13: Vagrant Binding JayDay 2013
Page 14: Vagrant Binding JayDay 2013

Devel

opers

Customers

A

B

C

D

E

1 2 3 4 5 6

Page 15: Vagrant Binding JayDay 2013

One month later...

Page 16: Vagrant Binding JayDay 2013

Someone updated our SVN.Eclipse can't use it anymore

Page 17: Vagrant Binding JayDay 2013

Oh, it took me 15 minutes to update Eclipse and the SVN plugin

Page 18: Vagrant Binding JayDay 2013

And this was only the first of 50 VMs!!!

Page 19: Vagrant Binding JayDay 2013
Page 20: Vagrant Binding JayDay 2013

Automated VM creationVagrant

VirtualBox

Puppet

Chef

Java

Page 21: Vagrant Binding JayDay 2013

•Don‘t repeat yourself

•„Infrastructure-As-Code“

Automated VM creation

Devs & Ops have time for other stuff

Page 22: Vagrant Binding JayDay 2013

Vagrant

Page 24: Vagrant Binding JayDay 2013

$ 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

Page 25: Vagrant Binding JayDay 2013

Vagrant

•build on top of VirtualBox

•written in Ruby

access by shell &

Ruby

Page 26: Vagrant Binding JayDay 2013

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 27: Vagrant Binding JayDay 2013

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

Page 28: Vagrant Binding JayDay 2013

Provider & Provisioner

•PlugIn API for Providers

•Virtual Box, AWS, VMWare Fusion

•PlugIn API for Provisioners

•Shell, Puppet, Chef, Ansible

Page 29: Vagrant Binding JayDay 2013

Demo

Page 30: Vagrant Binding JayDay 2013

Puppet

Page 32: Vagrant Binding JayDay 2013

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

Page 33: Vagrant Binding JayDay 2013

Puppet

•package individual components in modules

•many online documentations & books out there

Page 34: Vagrant Binding JayDay 2013

Vagrant&

Puppet

Page 35: Vagrant Binding JayDay 2013

Vagrant & Puppet

•define your VM with Vagrant & configure it with Puppet

•Puppet is pre-installed on Vagrant boxes

Vagrant defines the box

Puppet defines the content

Page 36: Vagrant Binding JayDay 2013

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 37: Vagrant Binding JayDay 2013

Chef

Page 38: Vagrant Binding JayDay 2013

Chef

•Just another Provisioner

•Similar to Puppet (at the first look)

conventions

•Modules = recipes

•Module collection = cookbook

Page 39: Vagrant Binding JayDay 2013

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

Page 40: Vagrant Binding JayDay 2013

Vagrant&

Chef

Page 41: Vagrant Binding JayDay 2013

Vagrant & Chef

•define your VM with Vagrant & configure it with Chef

•Chef is pre-installed on Vagrant boxes

just like Puppet

Page 42: Vagrant Binding JayDay 2013

Demo

Page 43: Vagrant Binding JayDay 2013

Vagrant-Binding

configure & manage

VMs in Java

Page 44: Vagrant Binding JayDay 2013

Vagrant-Binding

•Java Wrapper around Vagrant

•create & start VMs at runtime

•only VirtualBox is required

Let´s have a look

Page 45: Vagrant Binding JayDay 2013

Vagrant-Binding

•Builder APIs

•JUnit support

•Puppet support

Page 46: Vagrant Binding JayDay 2013

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

Page 47: Vagrant Binding JayDay 2013

Demo

Page 48: Vagrant Binding JayDay 2013

JUnit support

@Testpublic 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?

Page 49: Vagrant Binding JayDay 2013

JUnit support

@Rulepublic 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

Page 50: Vagrant Binding JayDay 2013

Demo

Page 51: Vagrant Binding JayDay 2013

QA Portal

•Manage all test machines with Vagrant & Puppet

•Manage lifecycle with Java

Super App Nightly Build with MySQLDefault installation of the App with MySQL DB Server

Super App Nightly Build with Oracle DBDefault installation of the App with Oracle DB Server

Super App Nightly Build without DatabaseUse this to check the default Errors in UI at startup

state: down

state: runningstarted by: John

state: down

Mockup

Page 52: Vagrant Binding JayDay 2013

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

Page 53: Vagrant Binding JayDay 2013

Vagrant-Binding

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

fork me on github

Page 54: Vagrant Binding JayDay 2013

Roadmap

•Remove VirtualBox as dependency (VMWare & AWS support)

•Chef support

•Simpler management of Environments

•Better Builder APIs

•Create Vagrant boxes at runtime

Page 55: Vagrant Binding JayDay 2013

Puppet Forge

Page 56: Vagrant Binding JayDay 2013

Puppet Forge access

•Puppet provied a Repo for default modules

•REST APILet´s use this

Page 57: Vagrant Binding JayDay 2013

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

Page 58: Vagrant Binding JayDay 2013

Demo

Page 59: Vagrant Binding JayDay 2013

Veewee

Page 60: Vagrant Binding JayDay 2013

Veewee

•Build new VM definitions

•Provides > 100 OS templates

•Customize the definition

•Export to VM definition as Vagrant Box

Page 61: Vagrant Binding JayDay 2013

Veewee templates

Page 62: Vagrant Binding JayDay 2013

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

Page 63: Vagrant Binding JayDay 2013

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

Page 64: Vagrant Binding JayDay 2013

Vagrant-Binding 2.0

Page 65: Vagrant Binding JayDay 2013

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

Page 66: Vagrant Binding JayDay 2013

Thanks for

watching@hendrikEbbers

[email protected]