Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Source to Deployment with Gradle & Docker

Source to Deployment with Gradle & Docker

Integrate docker with Gradle to create a fully automated delivery pipeline

John Engelman

July 31, 2015
Tweet

More Decks by John Engelman

Other Decks in Technology

Transcript

  1. SOURCE TO
    DEPLOYMENT WITH
    GRADLE & DOCKER

    View Slide

  2. 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

    View Slide

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

    View Slide

  4. 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

    View Slide

  5. WHAT GRADLE IS NOT!

    View Slide

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

    View Slide

  7. 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

    View Slide

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

    View Slide

  9. 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 {

    View Slide

  10. /
    / 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
    }

    View Slide

  11. PLUGIN COMPOSITION
    Gradle plugins can react to other plugins

    View Slide

  12. 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
    }
    }

    View Slide

  13. WHAT IS DOCKER?
    Application Container
    Isolated process
    Portable Packaging

    View Slide

  14. 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

    View Slide

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

    View Slide

  16. DOCKER IMAGES & CONTAINERS

    View Slide

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

    View Slide

  18. 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.)

    View Slide

  19. DOCKER & CONTINUOUS
    DEPLOYMENT

    View Slide

  20. 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

    View Slide

  21. BUILD PIPELINES

    View Slide



























































  22. │ │ 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 │ │ │
    │ └






































    ┘ │


























































    View Slide

  23. KEY COMPONENTS

    View Slide

  24. Gradle Application Plugin
    Gradle Docker Plugin
    Boot2Docker*

    View Slide

  25. BASIC CONTINUOUS INTEGRATION

    View Slide

  26. 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
    }

    View Slide

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

    View Slide

  28. 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
    "

    View Slide

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

    View Slide

  30. CONFIGURING GRADLE &
    BOOT2DOCKER

    View Slide

  31. 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
    '
    )
    }

    View Slide

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

    View Slide














  33. ┐ ┌












    ┐ ┌













    │ 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 │













    ┘ └












    ┘ └













    View Slide

  34. DOCKER MACHINE

    View Slide

  35. $ 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
    >

    View Slide

  36. $ $
    (
    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
    >
    )

    View Slide

  37. DEPLOYING DOCKER CONTAINERS

    View Slide

  38. DOCKER SECURITY

    View Slide

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

    View Slide