Groovy in the Cloud
Dan Woods
@danveloper
Code: h(ps://github.com/danveloper/groovy-in-the-cloud
Senior So(ware
Engineer
Working on Cloud &
DevOps Tooling
Wrote some of this while at Ne0lix
h"ps://spinnaker.io
O'Reilly Author,
2016
Learning Ratpack
Support your community.
All royal(es for Learning Ratpack go directly to Gr8Ladies
h"p://gr8ladies.org
How does Groovy fit in the cloud?
Groovy is present at every layer of
your project's lifecycle.
Microservices: Groovy community
has a lot to offer.
Build and packaging: Gradle is the
best, most flexible build tool.
Automa'ng and ensuring builds:
Groovy + Jenkins = !.
Managing cloud infrastructure:
Spinnaker
Automa'ng server tasks: Groovy
scripts + sshoogr!
At the end of the day, Groovy is
Java, so anything Java can do,
Groovy can do -- and simpler!
Groovy can act in mu.ple roles: as a powerful, dynamic scrip.ng
tool or as a fully compiled programming language.
Groovy can also be sta/cally compiled!
Agenda
• Groovy microservices with Ratpack
• Immutable infrastructure
• Gradle OS Package Plugin
• Gradle + Docker
• sshoogr
• Jenkins Job DSL
• Spinnaker
Microservices with Groovy and Ratpack
@Grab('io.ratpack:ratpack-groovy:1.4.0-rc-1')
import static ratpack.groovy.Groovy.ratpack
import static ratpack.jackson.Jackson.json
ratpack {
handlers {
get {
render(json([message: "Hello World!"]))
}
}
}
Immutable Infrastructure
The process by which a new server image is created for every new
version of your code.
Gradle OS Package Plugin
buildscript {
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 {
// ...
}
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")
}
Gradle Docker Plugin
buildscript {
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 "daniel.p.woods@gmail.com"'
}
}
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
:dockerBuildImage
Building 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
---> 264282a59a95
Step 2 : MAINTAINER Dan Woods "daniel.p.woods@gmail.com"
---> Using cache
---> 46c65408f762
Step 3 : ADD docker-plugin-1.0.0.tar /
---> Using cache
---> 41dc34567fae
Step 4 : ENTRYPOINT /docker-plugin-1.0.0/bin/docker-plugin
---> Using cache
---> fad9ba971b19
Step 5 : EXPOSE 5050
---> Running in 0bd76fcb5e15
---> 43b2d30640e2
Removing intermediate container 0bd76fcb5e15
Successfully built 43b2d30640e2
Created image with ID '43b2d30640e2'.
BUILD SUCCESSFUL
Total time: 10.974 secs
Serverless Compu-ng
No persistent server, quick func2ons that do one single thing very well
Serverless is a great choice for super lightweight microservices that
ingest some data, process it, and respond quickly.
AWS Lambda
h"ps://aws.amazon.com/lambda/
Groovy Lambda Demo
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"
}
sshoogr Demo
Jenkins Job DSL
h"ps://github.com/jenkinsci/job-dsl-plugin
Provides a means to describe your
Jenkins Jobs
Allows your build configura2ons to
be under source control
Ensures that if your Jenkins CI
system crashes, you can quickly and
safely recover
Wri$en in Groovy, so you can do
any programma5c processing you
want when configuring your builds!
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')
}
}
Spinnaker
Con$nuous delivery/deployment
pla4orm from Ne4lix
Wri$en in Groovy with Spring Boot
Highly extensible pla0orm for
managing your cloud footprint
Easy to build plugins and adjust
na1ve func1onality by incorpora1ng
Groovy modules
Ques%ons?

Groovy in the Cloud

  • 1.
    Groovy in theCloud Dan Woods @danveloper Code: h(ps://github.com/danveloper/groovy-in-the-cloud
  • 2.
    Senior So(ware Engineer Working onCloud & DevOps Tooling
  • 3.
    Wrote some ofthis while at Ne0lix h"ps://spinnaker.io
  • 4.
  • 5.
    Support your community. Allroyal(es for Learning Ratpack go directly to Gr8Ladies h"p://gr8ladies.org
  • 6.
    How does Groovyfit in the cloud?
  • 7.
    Groovy is presentat every layer of your project's lifecycle.
  • 8.
  • 9.
    Build and packaging:Gradle is the best, most flexible build tool.
  • 10.
    Automa'ng and ensuringbuilds: Groovy + Jenkins = !.
  • 11.
  • 12.
    Automa'ng server tasks:Groovy scripts + sshoogr!
  • 13.
    At the endof the day, Groovy is Java, so anything Java can do, Groovy can do -- and simpler!
  • 14.
    Groovy can actin mu.ple roles: as a powerful, dynamic scrip.ng tool or as a fully compiled programming language.
  • 15.
    Groovy can alsobe sta/cally compiled!
  • 16.
    Agenda • Groovy microserviceswith Ratpack • Immutable infrastructure • Gradle OS Package Plugin • Gradle + Docker • sshoogr • Jenkins Job DSL • Spinnaker
  • 17.
    Microservices with Groovyand Ratpack @Grab('io.ratpack:ratpack-groovy:1.4.0-rc-1') import static ratpack.groovy.Groovy.ratpack import static ratpack.jackson.Jackson.json ratpack { handlers { get { render(json([message: "Hello World!"])) } } }
  • 18.
    Immutable Infrastructure The processby which a new server image is created for every new version of your code.
  • 20.
    Gradle OS PackagePlugin buildscript { 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 { // ... }
  • 21.
    Gradle OS PackagePlugin 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") }
  • 22.
    Gradle Docker Plugin buildscript{ 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 "daniel.p.woods@gmail.com"' } }
  • 23.
    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 :dockerBuildImage Building 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 ---> 264282a59a95 Step 2 : MAINTAINER Dan Woods "daniel.p.woods@gmail.com" ---> Using cache ---> 46c65408f762 Step 3 : ADD docker-plugin-1.0.0.tar / ---> Using cache ---> 41dc34567fae Step 4 : ENTRYPOINT /docker-plugin-1.0.0/bin/docker-plugin ---> Using cache ---> fad9ba971b19 Step 5 : EXPOSE 5050 ---> Running in 0bd76fcb5e15 ---> 43b2d30640e2 Removing intermediate container 0bd76fcb5e15 Successfully built 43b2d30640e2 Created image with ID '43b2d30640e2'. BUILD SUCCESSFUL Total time: 10.974 secs
  • 24.
    Serverless Compu-ng No persistentserver, quick func2ons that do one single thing very well
  • 25.
    Serverless is agreat choice for super lightweight microservices that ingest some data, process it, and respond quickly.
  • 26.
  • 27.
  • 28.
    sshoogr @Grab('com.aestasit.infrastructure.sshoogr:sshoogr:0.9.25') import com.aestasit.infrastructure.ssh.dsl.* import com.aestasit.infrastructure.ssh.* defengine = 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" }
  • 29.
  • 30.
  • 31.
    Provides a meansto describe your Jenkins Jobs
  • 32.
    Allows your buildconfigura2ons to be under source control
  • 33.
    Ensures that ifyour Jenkins CI system crashes, you can quickly and safely recover
  • 34.
    Wri$en in Groovy,so you can do any programma5c processing you want when configuring your builds!
  • 35.
    Jenkins Job DSL defgitUrl = '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') } }
  • 36.
  • 37.
  • 38.
    Wri$en in Groovywith Spring Boot
  • 39.
    Highly extensible pla0ormfor managing your cloud footprint
  • 42.
    Easy to buildplugins and adjust na1ve func1onality by incorpora1ng Groovy modules
  • 43.