Top Banner
01
104

Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

May 13, 2015

Download

Software

DevConFu

The talk is focused on open-source Groovy/Java libraries that we have developed in order to solve our daily DevOps problems including SSH connectivity, cloud instance management, OS image management and integration testing of Puppet modules with the help of Groovy and Junit.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

01

Page 2: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Groovy DevOps in theCloud

02

Page 3: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

About us03

Page 4: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Luciano Fiandesio

Bio: Developer, speaker, author, kitchen hacker

Company: Aestas/IT (http://aestasit.com)

E-mail: [email protected]

Linkedin: http://www.linkedin.com/in/lucianofiandesio

••••

04

Page 5: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Andrey Adamovich

Bio: Developer, coach, speaker, author

Company: Aestas/IT (http://aestasit.com)

E-mail: [email protected]

Linkedin: http://www.linkedin.com/in/andreyadamovich

••••

05

Page 6: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

What's this presentation about?

Our take on:

DevOps

Software Provisioning

Continuous Integration

Continuous Delivery

••••

06

Page 7: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Technologies

AWS - http://aws.amazon.com

Groovy - http://groovy.codehaus.org

Gradle - http://gradle.org

Jenkins - http://jenkins-ci.org

Puppet - http://puppetlabs.com

•••••

07

Page 8: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Developers +Operations =

?08

Page 9: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Silos

09

Page 10: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Conflicts10

Page 11: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Risk

11

Page 12: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Agile

12

Page 13: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

What is DevOps?

13

Page 14: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

C.A.M.S.

Culture: People over processes and tools. Software is made by and

for people.

Automation: Automation is essential for DevOps to gain quick

feedback.

Measurement: DevOps finds a specific path to measurement. Quality

and shared (or at least aligned) incentives are critical.

Sharing: Creates a culture where people share ideas, processes, and

tools.

14

Page 15: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Though...15

Page 16: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

It's not abouttools!

16

Page 17: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

It's aboutculture and

process!17

Page 18: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

But withouttools...

18

Page 19: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

...it'sdefinitelyharder!

19

Page 20: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

DevOps implyautomation!

20

Page 21: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

DevOps implystructure!

21

Page 22: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Infrastructure as Code

Automate the provisioning and maintenance of servers:

Build from source control

Utilize Open Source tools

Ensure testability

•••

22

Page 23: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Configuration propagation

23

Page 24: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Changes

No Manual Changes!

24

Page 25: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Building an automation toolkit

Automation is key

We are JVM hackers

Fragmented ecosystem

Full-stack approach

••••

25

Page 26: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Tooling

Infrastructure connectivity

Infrastructure provisioning

Infrastructure virtualization

Infrastructure testing

••••

26

Page 27: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Sshoogr

27

Page 28: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Sshoogr Features

Remote command execution

File uploading/downloading

Tunneling

•••

28

Page 29: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Sshoogr Example I

remoteSession {

url = 'user2:654321@localhost:2222'

exec 'rm -rf /tmp/*'

exec 'touch /var/lock/my.pid'

remoteFile('/var/my.conf').text = "enabled=true"

}

01.

02.

03.

04.

05.

06.

29

Page 30: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Sshoogr Example II

remoteSession {

scp {

from { localDir "$buildDir/application" }

into { remoteDir '/var/bea/domain/application' }

}

}

01.

02.

03.

04.

05.

06.

30

Page 31: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Sshoogr Example III

def result = exec(command: '/usr/bin/mycmd',

failOnError: false, showOutput: false)

if (result.exitStatus == 1) {

result.output.eachLine { line ->

if (line.contains('WARNING')) {

throw new RuntimeException("Warning!!!")

}

}

}

01.

02.

03.

04.

05.

06.

07.

08.

09.31

Page 32: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Why Groovy?

Groovy is perfect choice for scripting

Very mature, concise syntax

Extremely easy to produce DSL

We wrote a book about it!

••••

32

Page 33: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Shameless plug

33

Page 34: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet34

Page 35: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Why Puppet?

More mature than competition

Large community

Readable DSL

No need to learn Ruby ;)

••••

35

Page 36: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet example

36

Page 37: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet provisioning

37

Page 38: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet provisioning

38

Page 39: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet provisioning

39

Page 40: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet provisioning

40

Page 41: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet state management

41

Page 42: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet state management

42

Page 43: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet state management

43

Page 44: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet modules

44

Page 45: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet modules

45

Page 46: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Puppet modules

46

Page 47: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Continuous Integration

47

Page 48: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Why Jenkins?

De-facto standard

Stable

There is a plugin for that!

•••

48

Page 49: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gradle49

Page 50: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gradle Example I

task uploadModules << {

remoteSession {

exec 'rm -rf /tmp/repo.zip'

scp {

from { localFile "${buildDir}/repo.zip" }

into { remoteDir "/root" }

}

...

01.

02.

03.

04.

05.

06.

07.

08.

50

Page 51: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gradle Example I

...

exec 'rm -rf /etc/puppet/modules'

exec 'unzip /tmp/repo.zip -d /etc/puppet/modules'

}

}

01.

02.

03.

04.

05.

51

Page 52: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gradle Example II

task puppetApply(dependsOn: uploadModules) << {

remoteSession {

scp {

from { localFile "${buildDir}/setup.pp" }

into { remoteDir "/tmp" }

}

exec 'puppet apply /tmp/setup.pp'

}

}

01.

02.

03.

04.

05.

06.

07.

08.

09.52

Page 53: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Jenkins example

53

Page 54: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

In the meanwhile...

We started developing complex Puppet modules

Modules needs proper testing

...on different platforms

•••

54

Page 55: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Do you test, right?

How to test this stuff?

How to reuse a JUnit approach to testing?

We wanted things to be SIMPLE!

•••

55

Page 56: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PuppetUnit

56

Page 57: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PUnit

Simple testing tool for verifying remote server state

Uses sshoogr and JUnit

Reuse reporting features of JUnit and Jenkins

As simple as ...

••••

57

Page 58: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PUnit Example I

class DerbyInstallTest

extends BasePuppetIntegrationTest {

@Before

void installDerby() {

apply("include derby")

}

...

}

01.

02.

03.

04.

05.

06.

07.

08.

58

Page 59: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PUnit Example II

@Test

def void ensureDerbyRunning() {

command('service derby status > derbystatus.log')

assertTrue fileText("/root/derbystatus.log")

.contains('Derby')

assertTrue fileText("/root/derbystatus.log")

.contains('is running.')

}

01.

02.

03.

04.

05.

06.

07.

08.

59

Page 60: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PUnit Example III

@Test

def void ensureCanConnect() {

Thread.sleep(10000)

uploadScript()

command('/opt/derby/db-derby-10.9.1.0-bin/bin/ij ' +

'testDataScript.sql > derbytest.log')

...

01.

02.

03.

04.

05.

06.

07.

60

Page 61: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PUnit Example III

...

// Check if the log of the insert

// operation contains the word ERROR.

assertFalse(

"The script should return at least one error",

fileText("/root/derbytest.log")

.contains('ERROR')

)

...

01.

02.

03.

04.

05.

06.

07.

08.

09.61

Page 62: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PUnit Example III

...

// Check on data that was inserted into a table.

assertTrue(

"The log should contain a SELECT result",

fileText("/root/derbytest.log")

.contains('Grand Ave.')

)

}

01.

02.

03.

04.

05.

06.

07.

08.

62

Page 63: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

PUnit

63

Page 64: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

session {

tunnel ('127.0.0.1', 8080) { int localPort ->

// Login to Jenkins.

def driver = new HtmlUnitDriver(false)

driver.manage().timeouts().pageLoadTimeout(300, TimeUnit.SECONDS).implicitlyWait(30, TimeUnit.SECONDS)

driver.get("http://127.0.0.1:${localPort}/login")

...

01.

02.

03.04.

05.

06.

07.

08.

09.

64

Page 65: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

...

def input = driver.findElement(By.name('j_username'))

input.sendKeys('john')

input = driver.findElement(By.name('j_password'))

input.sendKeys('123456')

input.submit()

...

01.

02.

03.

04.

05.

06.

07.

65

Page 66: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

...

// Verify login.

def wait = new WebDriverWait(driver, 30)

wait.until ExpectedConditions.presenceOfElementLocated (By.linkText('John Doe'))

...

}

}

01.

02.

03.

04.

05.

06.

07.

66

Page 67: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

session {

tunnel ('127.0.0.1', 80) { int localPort ->

// Initilize repository connection data.

DAVRepositoryFactory.setup()

def url = SVNURL.create('http', null, '127.0.0.1', localPort, 'repos/cafebabe', true)

def repository = SVNRepositoryFactory.create(url)

println "Verifying SVN repository at ${url}"

...

01.

02.

03.04.

05.

06.

07.

08.

09.

67

Page 68: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

...

// Setup credentials.

def authManager = SVNWCUtil.createDefaultAuthenticationManager('joe', '123456')

repository.setAuthenticationManager(authManager)

// Verify repository is at revision 0.

assertEquals 0, repository.getLatestRevision()

...

01.

02.

03.

04.

05.06.

07.

08.

68

Page 69: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

...

// Commit first revision.

ISVNEditor editor = repository.getCommitEditor("Initial commit.", null)

editor.with {

openRoot(-1)

addFile('dummy.txt', null, -1)

applyTextDelta('dummy.txt', null)

def deltaGenerator = new SVNDeltaGenerator()

...

01.

02.

03.

04.

05.

06.

07.

08.

09.69

Page 70: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

...

def checksum = deltaGenerator.sendDelta('dummy.txt', new ByteArrayInputStream("data".getBytes()), editor, true)

closeFile('dummy.txt', checksum)

def commitInfo = closeEdit()

println commitInfo

}

...

01.

02.

03.

04.

05.

06.

07.

70

Page 71: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

More examples

...

// Verify repository is at revision 1 now.

assertEquals 1, repository.getLatestRevision()

}

}

01.

02.

03.

04.05.

06.

71

Page 72: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Nextproblem?

72

Page 73: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Scalability

How do we test on different OS?

How do we run parallel tests on multiple architectures?

How do we avoid selling our houses?

•••

73

Page 74: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Amazon WebServices

74

Page 75: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Elastic Compute Cloud

Mature

Great API

Virtual hardware variety

OS variety

••••

75

Page 76: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gramazon

76

Page 77: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gramazon

Groovy based API for interacting with EC2

Integrates with the rest of the stack

••

77

Page 78: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gramazon Example I

task startInstance(type: StartInstance) {

keyName 'cloud-do'

securityGroup 'cloud-do'

instanceName 'gramazon/cloud-do'

stateFileName 'cloud-do.json'

ami 'ami-6f07e418'

instanceType 't1.micro'

waitForStart true

}

01.

02.

03.

04.

05.

06.

07.

08.

09.78

Page 79: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gramazon Example II

task terminateInstance(type: TerminateInstance) {

stateFileName 'cloud-do.json'

}

01.

02.

03.

79

Page 80: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Imgr

80

Page 81: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Imgr

A tool for building images

Inspired by Packer

••

81

Page 82: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Images?

82

Page 83: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Supports

Shell

Puppet

••

83

Page 84: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Configuration Example

84

Page 85: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

The flow

Start instance(s)

Upload manifests

Run tests

Generate report

Terminate instance(s)

1.

2.

3.

4.

5.

85

Page 86: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Images, manifests, tasks

86

Page 87: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

The big picture

87

Page 88: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Aetomation

88

Page 89: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Conclusions

Reuse your existing Java knowledge

...to build a bridge between DEVs and OPs

Reuse development best practices for OPs

Don't be afraid to try new technologies

Automate!

•••••

89

Page 90: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Readingmaterial

90

Page 91: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Groovy 2 Cookbook

91

Page 92: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

The Phoenix Project

92

Page 93: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Continuous Delivery

93

Page 94: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Release It

94

Page 95: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Programming Amazon EC2

95

Page 96: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Gradle in Action

96

Page 97: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Technologies to follow

Vagrant - http://www.vagrantup.com/

Docker - https://www.docker.io/

Packer - http://www.packer.io/

Qemu - http://wiki.qemu.org/Main_Page

jclouds - http://jclouds.apache.org/

Cloudbees - http://www.cloudbees.com/

••••••

97

Page 98: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

One morething...

98

Page 99: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

It's all OpenSource!

99

Page 100: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Source code

Sshoogr: https://github.com/aestasit/sshoogr

Sshoogr Gradle: https://github.com/aestasit/sshoogr-gradle

PUnit: https://github.com/aestasit/puppet-unit

Gramazon: https://github.com/aestasit/gramazon

Imgr: https://github.com/aestasit/imgr

•••••

100

Page 101: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Seekingcontributors!

101

Page 102: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Questions?102

Page 103: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

Thank you!

103

Page 104: Andrey Adamovich and Luciano Fiandesio - Groovy dev ops in the cloud

104