Download - 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Transcript
Page 1: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Your Jenkins Platform,Why it’s ImportantCyrille Le Clerc

Director of Product @ CloudBees

© 2016 CloudBees, Inc. All Rights Reserved

Page 2: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Agenda

• Jenkins platform bird’s eye view• Dockerizing Jenkins? What? Why? How? Masters & Agents• Setting up a Dockerized build environment

–Tools–Credentials and configuration settings

•Managing Docker images• The Role of Docker registries• Architecture of a Dockerized Jenkins Platform• Conclusion: How to Start

© 2016 CloudBees, Inc. All Rights Reserved

Page 3: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Jenkins Platform Bird’s Eye View

• Jenkins master

• Build agents

• Source code repository

• Artifact repository

• Deployment servers

© 2016 CloudBees, Inc. All Rights Reserved

Jenkins Platform

Jenkins Master …

Jenkins Agent

Jenkins Agent

Artifact Repositories

Page 4: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Jenkins Platform – Master & Build Agents

• Jenkins master

• Build agents

© 2016 CloudBees, Inc. All Rights Reserved

Artifact Repositories

Jenkins Platform

Jenkins Master …

Jenkins Agent

Jenkins Agent

Page 5: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Jenkins Platform – Build Agents

Requirements

• Operating Systems (Ubuntu…)

• Software (Firefox…)

© 2016 CloudBees, Inc. All Rights Reserved Jenkins Platform

Jenkins Master

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

• Credentials and config files

Page 6: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Masters

© 2016 CloudBees, Inc. All Rights Reserved

Page 7: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Masters

Benefits

© 2016 CloudBees, Inc. All Rights Reserved

Jenkins Platform

Jenkins Master …

Jenkins Agent

Jenkins Agent

Page 8: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Masters

Benefits

© 2016 CloudBees, Inc. All Rights Reserved

Jenkins Platform

Linux Host

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Agents

Page 9: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Masters

Benefits

• Better density

• Scale-out with smaller masters

© 2016 CloudBees, Inc. All Rights Reserved

Jenkins Platform

Linux Host

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Agents

Page 10: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Masters

Challenges

• Configuration Management of

smaller masters

• Management of Docker containers

© 2016 CloudBees, Inc. All Rights Reserved

Jenkins Platform

Linux Host

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Agents

Page 11: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Build Agents

© 2016 CloudBees, Inc. All Rights Reserved

Page 12: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Build Agents

© 2016 CloudBees, Inc. All Rights Reserved Jenkins Platform

Jenkins Master

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

How?

• Install a Docker Engine on each

existing Linux build agent

• Replace existing build agents by

agents running as Docker containers

Page 13: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Agents – Docker Engine

© 2016 CloudBees, Inc. All Rights Reserved

How?

• Install a Docker Engine on each

existing Linux build agent

Jenkins Platform

Jenkins Masters

Jenkins Agent

Jenkins Agent

…docker.image('maven:3.3.9').inside {sh 'mvn clean package'

}

Page 14: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Agents – Docker Engine

Benefits

• Simple & iterative approach to Dockerize

© 2016 CloudBees, Inc. All Rights Reserved

Jenkins Platform

Jenkins Masters

Jenkins Agent

Jenkins Agent

Page 15: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Agents – Docker Agents

© 2016 CloudBees, Inc. All Rights Reserved

How?

• Replace existing Linux build agents by Linux

servers with a “Docker ‘orchestration’ service”

Standalone Docker engines, Swarm, Kubernetes, Mesos, Amazon ECS

• User the associated Jenkins Docker Cloud Plugin

Jenkins Platform

Linux Host

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Masters

Page 16: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Agents – Docker Agents

Challenges

Need to choose a ‘Docker orchestration service’

Plugin maturity

• Docker image complexity: require “JNLP Agent” plumbing

• Docker image mgmt: by the Jenkins admin, not by the users

• Workspace: caching and browsing

• Jenkins not yet optimized for Dockerized agents

© 2016 CloudBees, Inc. All Rights ReservedJenkins Platform

Linux Host

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Masters

Page 17: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Agents – Docker Agents

Benefits

• Ease of mgmt of the infra … once installed

• Scalability

• Build isolation and multi tenancy

© 2016 CloudBees, Inc. All Rights ReservedJenkins Platform

Linux Host

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Masters

Page 18: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing Agents – Docker Agents

Implementations

• Kubernetes

• Mesos

• Amazon ECS

• Docker Swarm

© 2016 CloudBees, Inc. All Rights Reserved

Page 19: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Dockerizing with CloudBees Private SaaS Edition

CloudBees Jenkins Platform Private SaaS Edition

• On Demand Jenkins masters

• On Demand build agents

© 2016 CloudBees, Inc. All Rights Reserved

CloudBees Jenkins PlatformPrivate SaaS Edition

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Master

Jenkins Agent

Jenkins Agent

Jenkins Agent

Jenkins Agent

Page 20: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Customizing Build AgentsTools, credentials, configuration files

© 2016 CloudBees, Inc. All Rights Reserved

Page 21: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Customizing Agents: Tools

Why?• General purpose & reusable build agents

What? • Compilers and build : Java, CMake, NodeJS• Deployment: Terraform, Packer, AWS CLI…

© 2016 CloudBees, Inc. All Rights Reserved

Terraform

Page 22: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Customizing Agents: Tools

How?• Until now: Jenkins tool installers

Benefits• Zero admin• Composability of installers• No licensing issue

Challenges• Fragility of the installers

© 2016 CloudBees, Inc. All Rights Reserved

Page 23: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Customizing Agents: Tools

How?• Docker enabled agents: Docker Image

Benefits• No more fragility• Everything available on DockerHub

Challenge• How to combine tools?• Governance of Docker images• Licensing• Compatibility with Docker JNLP Agents?

© 2016 CloudBees, Inc. All Rights Reserved

Page 24: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Customizing Agents: Tools

cloudbees/java-build-tools• Docker image started in January 2016• Combine common build tools• Documented and versioned• Easy to fork• Also available for Docker JNLP Agents

© 2016 CloudBees, Inc. All Rights Reserved

Page 25: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Customizing Agents: Credentials and Config Files

Same principle as for general purpose agents

• Nothing on disk• Jenkins Credentials• Jenkins Config File Provider

© 2016 CloudBees, Inc. All Rights Reserved

Page 26: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld #JenkinsWorld

Customizing Agents: Credentials and Config Files

© 2016 CloudBees, Inc. All Rights Reserved

withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: 'my-secret', passwordVariable: 'MY_PASSWORD', usernameVariable: 'MY_USERNAME']]) {

...}

withCredentials([[$class: 'AmazonWebServicesCredentialsBinding',credentialsId: 'my-aws-iam-credentials']) {

sh 'aws ec2 decribe-instances...'}

sshagent(['my-ssh-key']) {sh 'scp my.war jenkins@my-server:.'

}

Page 27: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Managing Docker Images

© 2016 CloudBees, Inc. All Rights Reserved

Page 28: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Managing Docker Images

• Requirements–Flexibility for the Jenkins users / DEV–“Control” for the Jenkins admins

• Proposal for a Governance model–Shared governance–Dockerfile stored in a Git repo–Jenkins admins: control the base Docker image–Jenkins DEV: choose the tools installed on the Docker image

© 2016 CloudBees, Inc. All Rights Reserved

Page 29: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Managing Docker Images

Challenges with Dockerized agents

• Docker images declared in Jenkins Global Config

• Change the content of the image rather than Jenkins config?

© 2016 CloudBees, Inc. All Rights Reserved

FROM jenkinsci/jnlp-slave

# MavenRUN curl –fsSL http://...ENV MAVEN_HOME /usr/share/maven

Page 30: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

The role of Docker Registries

© 2016 CloudBees, Inc. All Rights Reserved

Page 31: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Docker Registries

• Pull images to customize the build

environment

• Pull images to build images

• Push images created by builds

• Notify Jenkins when images change

© 2016 CloudBees, Inc. All Rights Reserved Jenkins Platform

Jenkins Master

Agents created on demand

Linux Agent

Docker Container Agent

Push Docker images created

by Jenkins builds

Pull Docker

images to customise the build

environment

Pull Docker images to build other

images

notifi

catio

n

pull

pull

push

Trigger builds

on image push

Page 32: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Docker Registries

Start small

Use Docker Hub, use the cloud

© 2016 CloudBees, Inc. All Rights Reserved My Company

Internet

CloudBees Jenkins PlatformMaster

Dockerized Jenkins Agent

hub.docker.com

Push Docker images created

by Jenkins builds

Pull Docker images to customise the build

environment

Pull Docker

images to build other

images

notifi

catio

n

pull

pull

push

Trigger builds

on image push

Page 33: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Docker Registries

Challenges

• Security

• Network

• DockerHub may remove images

© 2016 CloudBees, Inc. All Rights Reserved My Company

Internet

CloudBees Jenkins PlatformMaster

Dockerized Jenkins Agent

hub.docker.com

Push Docker images created

by Jenkins builds

Pull Docker images to customise the build

environment

Pull Docker

images to build other

images

notifi

catio

n

pull

pull

push

Trigger builds

on image push

Page 34: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Docker Registries

Benefits

• No need to chose a software

• Limited management, it’s a SaaS

© 2016 CloudBees, Inc. All Rights Reserved My Company

Internet

CloudBees Jenkins PlatformMaster

Dockerized Jenkins Agent

hub.docker.com

Push Docker images created

by Jenkins builds

Pull Docker images to customise the build

environment

Pull Docker

images to build other

images

notifi

catio

n

pull

pull

push

Trigger builds

on image push

Page 35: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Docker Registries

• If needed, go through proxies

© 2016 CloudBees, Inc. All Rights Reserved

Outbound Proxy

My Company

Internet

JenkinsMaster

Dockerized Jenkins Agent

hub.docker.com

Push Docker images created

by Jenkins builds

Pull Docker images to customise the build

environment

Pull Docker

images to build other

images

notifi

catio

n

pull

pull

push

Trigger builds

on image push

Page 36: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

Docker Registries

Private Docker registry

Benefits

• Registry behind the firewalls

• Network

• Security

Challenges

• Choose a technology

• Manage disk space

© 2016 CloudBees, Inc. All Rights ReservedMy Company

Docker Registry

Image Registry

Internet

JenkinsMaster

Dockerized Jenkins Agent

hub.docker.com

Push Docker images created by Jenkins builds

Pull Docker images to build other images

notification

pull

push

Proxypull-through cached

mirroring

pull

notification

Trigger builds on image push

Pull Docker images to customise

the build environment

pull

Page 37: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

How to start?

© 2016 CloudBees, Inc. All Rights Reserved

Page 38: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World

#JenkinsWorld

How to start

Jenkins infra

• Docker Engine on existing Linux Agents or CloudBees Private SaaS Edition

Docker images• cloudbees/java-build-tools (or cloudbees/jnlp-slave-with-java-build-tools)

Docker Registry• DockerHub

© 2016 CloudBees, Inc. All Rights Reserved

Page 39: 2016-09 - Jenkins World - Dockerizing Jenkins Platform

Jenkins World#JenkinsWorld

© 2016 CloudBees, Inc. All Rights Reserved