groovy in the cloud

43
Groovy in the Cloud Dan Woods @danveloper Code: h(ps://github.com/danveloper/groovy-in-the-cloud

Upload: daniel-woods

Post on 12-Apr-2017

918 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Groovy in the Cloud

Groovy in the Cloud

Dan Woods @danveloper

Code: h(ps://github.com/danveloper/groovy-in-the-cloud

Page 2: Groovy in the Cloud

Senior So(ware Engineer

Working on Cloud & DevOps Tooling

Page 3: Groovy in the Cloud

Wrote some of this while at Ne0lix

h"ps://spinnaker.io

Page 4: Groovy in the Cloud

O'Reilly Author, 2016

Learning Ratpack

Page 5: Groovy in the Cloud

Support your community.All royal(es for Learning Ratpack go directly to Gr8Ladies

h"p://gr8ladies.org

Page 6: Groovy in the Cloud

How does Groovy fit in the cloud?

Page 7: Groovy in the Cloud

Groovy is present at every layer of your project's lifecycle.

Page 8: Groovy in the Cloud

Microservices: Groovy community has a lot to offer.

Page 9: Groovy in the Cloud

Build and packaging: Gradle is the best, most flexible build tool.

Page 10: Groovy in the Cloud

Automa'ng and ensuring builds: Groovy + Jenkins = !.

Page 11: Groovy in the Cloud

Managing cloud infrastructure: Spinnaker

Page 12: Groovy in the Cloud

Automa'ng server tasks: Groovy scripts + sshoogr!

Page 13: Groovy in the Cloud

At the end of the day, Groovy is Java, so anything Java can do, Groovy can do -- and simpler!

Page 14: Groovy in the Cloud

Groovy can act in mu.ple roles: as a powerful, dynamic scrip.ng tool or as a fully compiled programming language.

Page 15: Groovy in the Cloud

Groovy can also be sta/cally compiled!

Page 16: Groovy in the Cloud

Agenda

• Groovy microservices with Ratpack

• Immutable infrastructure

• Gradle OS Package Plugin

• Gradle + Docker

• sshoogr

• Jenkins Job DSL

• Spinnaker

Page 17: Groovy in the Cloud

Microservices with Groovy and Ratpack

@Grab('io.ratpack:ratpack-groovy:1.4.0-rc-1')

import static ratpack.groovy.Groovy.ratpackimport static ratpack.jackson.Jackson.json

ratpack { handlers { get { render(json([message: "Hello World!"])) } }}

Page 18: Groovy in the Cloud

Immutable Infrastructure

The process by which a new server image is created for every new version of your code.

Page 19: Groovy in the Cloud
Page 20: Groovy in the Cloud

Gradle OS Package Pluginbuildscript { repositories { jcenter() maven { url "https://plugins.gradle.org/m2/" } } dependencies { classpath 'io.ratpack:ratpack-gradle:1.4.0-rc-1' classpath 'gradle.plugin.com.netflix.nebula:gradle-ospackage-plugin:3.6.1' }}

apply plugin: 'io.ratpack.ratpack-groovy'apply plugin: 'nebula.ospackage'

version = "1.0.0"

repositories { jcenter()}

ospackage { // ...}buildDeb { // ...}

Page 21: Groovy in the Cloud

Gradle OS Package Plugin

ospackage { packageName = "myapp" release '3' into "/opt/myapp" from "${project.buildDir}/install/${project.applicationName}" from("osfiles") { into "/" }}

buildDeb { dependsOn installDist //requires("nginx") //requires("mysql-client") preInstall file("scripts/preInstall.sh") postInstall file("scripts/postInstall.sh")}

Page 22: Groovy in the Cloud

Gradle Docker Pluginbuildscript { repositories { jcenter() } dependencies { classpath 'io.ratpack:ratpack-gradle:1.4.0-rc-1' classpath 'com.bmuschko:gradle-docker-plugin:3.0.1' }}

apply plugin: 'io.ratpack.ratpack-groovy'apply plugin: 'com.bmuschko.docker-remote-api'apply plugin: 'com.bmuschko.docker-java-application'

version = "1.0.0"

repositories { jcenter()}

docker { javaApplication { maintainer = 'Dan Woods "[email protected]"' }}

Page 23: Groovy in the Cloud

Gradle Docker Plugin - Build Image$ ./gradlew dockerBuildImage:compileJava UP-TO-DATE:compileGroovy UP-TO-DATE:processResources UP-TO-DATE:classes UP-TO-DATE:jar UP-TO-DATE:startScripts UP-TO-DATE:distTar UP-TO-DATE:dockerCopyDistResources UP-TO-DATE:dockerDistTar:dockerBuildImageBuilding image using context '/Users/danw/Documents/uberconf-2016/groovy-cloud-code/docker-plugin/build/docker'.Using tag 'docker-plugin:1.0.0' for image.Step 1 : FROM java---> 264282a59a95Step 2 : MAINTAINER Dan Woods "[email protected]"---> Using cache---> 46c65408f762Step 3 : ADD docker-plugin-1.0.0.tar /---> Using cache---> 41dc34567faeStep 4 : ENTRYPOINT /docker-plugin-1.0.0/bin/docker-plugin---> Using cache---> fad9ba971b19Step 5 : EXPOSE 5050---> Running in 0bd76fcb5e15---> 43b2d30640e2Removing intermediate container 0bd76fcb5e15Successfully built 43b2d30640e2Created image with ID '43b2d30640e2'.

BUILD SUCCESSFUL

Total time: 10.974 secs

Page 24: Groovy in the Cloud

Serverless Compu-ng

No persistent server, quick func2ons that do one single thing very well

Page 25: Groovy in the Cloud

Serverless is a great choice for super lightweight microservices that ingest some data, process it, and respond quickly.

Page 26: Groovy in the Cloud

AWS Lambda

h"ps://aws.amazon.com/lambda/

Page 27: Groovy in the Cloud

Groovy Lambda Demo

Page 28: Groovy in the Cloud

sshoogr@Grab('com.aestasit.infrastructure.sshoogr:sshoogr:0.9.25')import com.aestasit.infrastructure.ssh.dsl.*import com.aestasit.infrastructure.ssh.*

def engine = new SshDslEngine(new SshOptions(defaultKeyFile: new File("/Users/danw/Downloads/uberconf.pem"), trustUnknownHosts: true))

engine.remoteSession('ubuntu@xxx:22') { exec 'rm -rf /tmp/key*' remoteFile('/tmp/key.foo').text = "mySecretKey=123456"}

Page 29: Groovy in the Cloud

sshoogr Demo

Page 30: Groovy in the Cloud

Jenkins Job DSLh"ps://github.com/jenkinsci/job-dsl-plugin

Page 31: Groovy in the Cloud

Provides a means to describe your Jenkins Jobs

Page 32: Groovy in the Cloud

Allows your build configura2ons to be under source control

Page 33: Groovy in the Cloud

Ensures that if your Jenkins CI system crashes, you can quickly and

safely recover

Page 34: Groovy in the Cloud

Wri$en in Groovy, so you can do any programma5c processing you

want when configuring your builds!

Page 35: Groovy in the Cloud

Jenkins Job DSL

def gitUrl = 'git://github.com/myorg/myapp.git'def allowedUsers = ['dan', 'ben', 'ernest']

job('PROJ-build') { scm { git(gitUrl) } // no trigger authorization { allowedUsers.each { user -> permission('hudson.model.Item.Build', user) } } steps { shell('gradlew clean build') }}

Page 36: Groovy in the Cloud

Spinnaker

Page 37: Groovy in the Cloud

Con$nuous delivery/deployment pla4orm from Ne4lix

Page 38: Groovy in the Cloud

Wri$en in Groovy with Spring Boot

Page 39: Groovy in the Cloud

Highly extensible pla0orm for managing your cloud footprint

Page 40: Groovy in the Cloud
Page 41: Groovy in the Cloud
Page 42: Groovy in the Cloud

Easy to build plugins and adjust na1ve func1onality by incorpora1ng

Groovy modules

Page 43: Groovy in the Cloud

Ques%ons?