source to deployment with gradle & … am i john engelman chief software technologist team...

39
SOURCE TO DEPLOYMENT WITH GRADLE & DOCKER

Upload: vanduong

Post on 18-Mar-2018

226 views

Category:

Documents


4 download

TRANSCRIPT

Page 1: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

SOURCE TODEPLOYMENT WITHGRADLE & DOCKER

Page 2: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

WHO AM IJohn Engelman

Chief Software Technologist Team Member

Gradle plugin author and contributorDevOps aficionado@johnrengelman

Ratpack

github.com/johrengelman

Page 3: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

TOPICS1. Gradle Intro2. Docker Intro3. Continuous Integration w/ Gradle4. Packing An App w/ Docker & Gradle5. Continuous Deployment w/ Docker

Page 4: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

WHAT IS GRADLE?

1. Expressive, declarative, & maintainable build language2. Dependency Resolver & Manager3. Build Task Scheduler & Executor4. Build By Convention

Gradle is an opinionated framework on topof an unopinionated toolkit

- Szczepan Faber

Page 5: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

WHAT GRADLE IS NOT!

Page 6: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

It is NOT Groovy Ant!(That tool exists -> )GANT

Page 7: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

CORE GRADLE FEATURES

1. Build-By-Convention w/ Flexibility2. Project & Build Groovy DSL3. Support for Ivy & Maven Dependencies4. Multi-Project Builds5. Easy to add custom logic6. 1st class integration w/ Ant builds7. Extensive public API and plugin ecosystem8. Task UP-TO-DATE checking

Page 8: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

GRADLE IS FLEXIBLEJust because it is written in Java

doesn't mean project must be Java

Page 9: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

apply plugin: 'com.moowork.grunt'

npmInstall.inputs.file 'package.json'

installGrunt.dependsOn 'npmInstall'installGrunt.inputs.file file('Gruntfile.js')

grunt_bowerInstall.dependsOn 'installGrunt'grunt_bowerInstall.inputs.file file('bower.json')

// Adding dependencies so grunt and NPM get installed[ grunt_build, grunt_test, grunt_clean ].each{ gtask -> gtask.dependsOn 'grunt_bowerInstall'}

grunt_build.inputs.dir file('app')grunt_build.outputs.dir file('dist')

assemble.dependsOn grunt_buildbuild.dependsOn assemble

test.dependsOn grunt_test

task run(description: 'Build and run the application locally.', group: args = [ 'serve' ]}

node { // Version of node to use.

Page 10: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

// Version of node to use.

version = '0.12.2'

// Version of npm to use. npmVersion = '2.7.5'

// Enabled the automatic download. False is the default (for now). download = true}

Page 11: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

PLUGIN COMPOSITIONGradle plugins can react to other plugins

Page 12: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

void apply(Project project) { project.plugins.withType(JavaPlugin) { // Do stuff to Java projects } project.plugins.withType(GroovyPlugin) { // Do extra stuff to Groovy projects }}

Page 13: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

WHAT IS DOCKER?Application ContainerIsolated processPortable Packaging

Page 14: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

WHY IS THIS GOOD?Abstracts application language & build chainWrite once, run anywhere (*)Define OS level dependencies into application packageEliminate "works on my machine"Increase resource utilization of machines

Page 15: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DOCKER CONTAINERS VS.

VIRTUAL MACHINESSmaller distribution

Share the OSPackage only the necessities

Isolate each processProcess specific user space, network stack, & filesystem

Page 16: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DOCKER IMAGES & CONTAINERS

Page 17: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DOCKER IMAGEA docker image is:

A read-only virtual file system...Comprised of layers...With atomic changes to the previous (parent) layer...

Page 18: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DOCKER CONTAINERA docker container is:

A process...With a read-write layer...On top of a image...And additional meta-data (env vars, networking config,etc.)

Page 19: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DOCKER & CONTINUOUSDEPLOYMENT

Page 20: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

Docker is a useful tool for continuous applicationdeployment.

Define the entire deployable from the ground upOn commit, only need to build upwards from the 1stchanged layerDeploy only the changed layers to the server

Page 21: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

BUILD PIPELINES

Page 22: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

┌────┬───────────────────┬───────────────────────────────┐│ │ Gradle │ ││ └───────────────────┘ ││ ││ ││┌────────────┐ ┌────────────┐ │││ Source │ │ Test │ │││ │───>│ │ ││└────────────┘ └────────────┘ ││ │ ││ ┌─────────┼────────────────────────────┐ ││ │ ⌵ │ ││ │ ┌────────────┐ ┌────────────┐ │ ││ │ │ Package │ │ Deploy │ │ ││ │ │ │────>│ │ │ ││ │ └────────────┘ └────────────┘ │ ││ │ │ ││ │ ┌───────────────────┐ │ ││ │ │ Docker │ │ ││ └──────┴───────────────────┴───────────┘ │└────────────────────────────────────────────────────────┘

Page 23: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

KEY COMPONENTS

Page 25: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

BASIC CONTINUOUS INTEGRATION

Page 26: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

apply plugin: 'java'

repositories { jcenter()}

dependencies { // Add dependencies here}

Page 27: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

$ gradle build

Page 28: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

APPLICATION DISTRIBUTIONSapply plugin: 'application'

mainClassName = "sample.MyApplication"

Page 29: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

$ gradle distTar

Page 30: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

CONFIGURING GRADLE &BOOT2DOCKER

Page 31: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

plugins { id "com.bmuschko.docker-java-application" version "2.4"}

docker { url = 'https://192.168.59.103:2376' certPath = new File( System.properties['user.home'], '.boot2docker/certs/boot2docker-vm' )}

Page 32: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

$ gradle dockerBuildImage

Page 33: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

┌────────────┐ ┌────────────┐ ┌────────────┐│ Gradle │ │Docker Java │ REST │ Docker ││ │───>│ API │──────>│ Daemon │└────────────┘ └────────────┘ └────────────┘

Page 34: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DOCKER MACHINE

Page 35: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

$ docker-machine create \ --driver amazonec2 \ --amazonec2-vpc-id <vpc_id> \ <machine_name>

Page 36: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

$ $(docker-machine env <machine_name>)

Page 37: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DEPLOYING DOCKER CONTAINERS

Page 38: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

DOCKER SECURITY

Page 39: SOURCE TO DEPLOYMENT WITH GRADLE & … AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @johnrengelman Ratpack github.com/johrengelman

CONCERNS

Docker daemon runs as rootGradle-Docker integration is unauthenticated