Slide 1

Slide 1 text

SOURCE TO DEPLOYMENT WITH GRADLE & DOCKER

Slide 2

Slide 2 text

WHO AM I John Engelman Chief Software Technologist Team Member Gradle plugin author and contributor DevOps aficionado @ j o h n r e n g e l m a n Ratpack github.com/johrengelman

Slide 3

Slide 3 text

TOPICS 1. Gradle Intro 2. Docker Intro 3. Continuous Integration w/ Gradle 4. Packing An App w/ Docker & Gradle 5. Continuous Deployment w/ Docker

Slide 4

Slide 4 text

WHAT IS GRADLE? 1. Expressive, declarative, & maintainable build language 2. Dependency Resolver & Manager 3. Build Task Scheduler & Executor 4. Build By Convention Gradle is an opinionated framework on top of an unopinionated toolkit - Szczepan Faber

Slide 5

Slide 5 text

WHAT GRADLE IS NOT!

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

CORE GRADLE FEATURES 1. Build-By-Convention w/ Flexibility 2. Project & Build Groovy DSL 3. Support for Ivy & Maven Dependencies 4. Multi-Project Builds 5. Easy to add custom logic 6. 1st class integration w/ Ant builds 7. Extensive public API and plugin ecosystem 8. Task UP-TO-DATE checking

Slide 8

Slide 8 text

GRADLE IS FLEXIBLE Just because it is written in Java doesn't mean project must be Java

Slide 9

Slide 9 text

a p p l y p l u g i n : ' c o m . m o o w o r k . g r u n t ' n p m I n s t a l l . i n p u t s . f i l e ' p a c k a g e . j s o n ' i n s t a l l G r u n t . d e p e n d s O n ' n p m I n s t a l l ' i n s t a l l G r u n t . i n p u t s . f i l e f i l e ( ' G r u n t f i l e . j s ' ) g r u n t _ b o w e r I n s t a l l . d e p e n d s O n ' i n s t a l l G r u n t ' g r u n t _ b o w e r I n s t a l l . i n p u t s . f i l e f i l e ( ' b o w e r . j s o n ' ) / / A d d i n g d e p e n d e n c i e s s o g r u n t a n d N P M g e t i n s t a l l e d [ g r u n t _ b u i l d , g r u n t _ t e s t , g r u n t _ c l e a n ] . e a c h { g t a s k - > g t a s k . d e p e n d s O n ' g r u n t _ b o w e r I n s t a l l ' } g r u n t _ b u i l d . i n p u t s . d i r f i l e ( ' a p p ' ) g r u n t _ b u i l d . o u t p u t s . d i r f i l e ( ' d i s t ' ) a s s e m b l e . d e p e n d s O n g r u n t _ b u i l d b u i l d . d e p e n d s O n a s s e m b l e t e s t . d e p e n d s O n g r u n t _ t e s t t a s k r u n ( d e s c r i p t i o n : ' B u i l d a n d r u n t h e a p p l i c a t i o n l o c a l l y . ' , g r o u p : a r g s = [ ' s e r v e ' ] } n o d e {

Slide 10

Slide 10 text

/ / V e r s i o n o f n o d e t o u s e . v e r s i o n = ' 0 . 1 2 . 2 ' / / V e r s i o n o f n p m t o u s e . n p m V e r s i o n = ' 2 . 7 . 5 ' / / E n a b l e d t h e a u t o m a t i c d o w n l o a d . F a l s e i s t h e d e f a u l t ( f o r n o w ) . d o w n l o a d = t r u e }

Slide 11

Slide 11 text

PLUGIN COMPOSITION Gradle plugins can react to other plugins

Slide 12

Slide 12 text

v o i d a p p l y ( P r o j e c t p r o j e c t ) { p r o j e c t . p l u g i n s . w i t h T y p e ( J a v a P l u g i n ) { / / D o s t u f f t o J a v a p r o j e c t s } p r o j e c t . p l u g i n s . w i t h T y p e ( G r o o v y P l u g i n ) { / / D o e x t r a s t u f f t o G r o o v y p r o j e c t s } }

Slide 13

Slide 13 text

WHAT IS DOCKER? Application Container Isolated process Portable Packaging

Slide 14

Slide 14 text

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

Slide 15

Slide 15 text

DOCKER CONTAINERS VS. VIRTUAL MACHINES Smaller distribution Share the OS Package only the necessities Isolate each process Process specific user space, network stack, & filesystem

Slide 16

Slide 16 text

DOCKER IMAGES & CONTAINERS

Slide 17

Slide 17 text

DOCKER IMAGE A docker image is: A read-only virtual file system... Comprised of layers... With atomic changes to the previous (parent) layer...

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

DOCKER & CONTINUOUS DEPLOYMENT

Slide 20

Slide 20 text

Docker is a useful tool for continuous application deployment. Define the entire deployable from the ground up On commit, only need to build upwards from the 1st changed layer Deploy only the changed layers to the server

Slide 21

Slide 21 text

BUILD PIPELINES

Slide 22

Slide 22 text

┌ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │ G r a d l e │ │ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │ │ │ │ │ │ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │ │ S o u r c e │ │ T e s t │ │ │ │ │ ─ ─ ─ > │ │ │ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │ │ │ │ │ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┼ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │ │ ⌵ │ │ │ │ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │ │ │ │ P a c k a g e │ │ D e p l o y │ │ │ │ │ │ │ ─ ─ ─ ─ > │ │ │ │ │ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │ │ │ │ │ │ │ │ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │ │ │ │ D o c k e r │ │ │ │ └ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘

Slide 23

Slide 23 text

KEY COMPONENTS

Slide 24

Slide 24 text

Gradle Application Plugin Gradle Docker Plugin Boot2Docker*

Slide 25

Slide 25 text

BASIC CONTINUOUS INTEGRATION

Slide 26

Slide 26 text

a p p l y p l u g i n : ' j a v a ' r e p o s i t o r i e s { j c e n t e r ( ) } d e p e n d e n c i e s { / / A d d d e p e n d e n c i e s h e r e }

Slide 27

Slide 27 text

$ g r a d l e b u i l d

Slide 28

Slide 28 text

APPLICATION DISTRIBUTIONS a p p l y p l u g i n : ' a p p l i c a t i o n ' m a i n C l a s s N a m e = " s a m p l e . M y A p p l i c a t i o n "

Slide 29

Slide 29 text

$ g r a d l e d i s t T a r

Slide 30

Slide 30 text

CONFIGURING GRADLE & BOOT2DOCKER

Slide 31

Slide 31 text

p l u g i n s { i d " c o m . b m u s c h k o . d o c k e r - j a v a - a p p l i c a t i o n " v e r s i o n " 2 . 4 " } d o c k e r { u r l = ' h t t p s : / / 1 9 2 . 1 6 8 . 5 9 . 1 0 3 : 2 3 7 6 ' c e r t P a t h = n e w F i l e ( S y s t e m . p r o p e r t i e s [ ' u s e r . h o m e ' ] , ' . b o o t 2 d o c k e r / c e r t s / b o o t 2 d o c k e r - v m ' ) }

Slide 32

Slide 32 text

$ g r a d l e d o c k e r B u i l d I m a g e

Slide 33

Slide 33 text

┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ G r a d l e │ │ D o c k e r J a v a │ R E S T │ D o c k e r │ │ │ ─ ─ ─ > │ A P I │ ─ ─ ─ ─ ─ ─ > │ D a e m o n │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘

Slide 34

Slide 34 text

DOCKER MACHINE

Slide 35

Slide 35 text

$ d o c k e r - m a c h i n e c r e a t e \ - - d r i v e r a m a z o n e c 2 \ - - a m a z o n e c 2 - v p c - i d < v p c _ i d > \ < m a c h i n e _ n a m e >

Slide 36

Slide 36 text

$ $ ( d o c k e r - m a c h i n e e n v < m a c h i n e _ n a m e > )

Slide 37

Slide 37 text

DEPLOYING DOCKER CONTAINERS

Slide 38

Slide 38 text

DOCKER SECURITY

Slide 39

Slide 39 text

CONCERNS Docker daemon runs as root Gradle-Docker integration is unauthenticated