groovy in the cloud
TRANSCRIPT
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.ratpackimport 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 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 { // ...}
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 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]"' }}
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
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 DSLh"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?