Share
Embed
Source to Deployment with Gradle & Docker
Integrate docker with Gradle to create a fully automated delivery pipeline
John Engelman
July 31, 2015
Transcript
39 slides
-
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 -
TOPICS 1. Gradle Intro 2. Docker Intro 3. Continuous Integration
w/ Gradle 4. Packing An App w/ Docker & Gradle 5. Continuous Deployment w/ Docker -
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 -
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 -
GRADLE IS FLEXIBLE Just because it is written in Java
doesn't mean project must be Java -
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 { -
/ / 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 } -
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 } } -
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 -
DOCKER CONTAINERS VS. VIRTUAL MACHINES Smaller distribution Share the OS
Package only the necessities Isolate each process Process specific user space, network stack, & filesystem -
DOCKER IMAGE A docker image is: A read-only virtual file
system... Comprised of layers... With atomic changes to the previous (parent) layer... -
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.) -
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 -
┌ ─ ─ ─ ─ ┬ ─ ─ ─ ─
─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┬ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ │ 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 │ │ │ │ └ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┴ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ -
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 } -
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 " -
$ g r a d l e d i s
t T a r -
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 ' ) } -
$ g r a d l e d o c
k e r B u i l d I m a g e -
┌ ─ ─ ─ ─ ─ ─ ─ ─ ─
─ ─ ─ ┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ ┌ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐ │ 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 │ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ └ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘ -
$ 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 > -
$ $ ( 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 > )