SlideShare una empresa de Scribd logo
1 de 23
Descargar para leer sin conexión
© 2017 CloudBees, Inc. All Rights Reserved. 1
+
DevOps
© 2017 CloudBees, Inc. All Rights Reserved. 2
Docker + Jenkins Use Cases
• Run Jenkins with Docker (or other container)
• Run Jenkins Masters as Docker Containers
• Run Jenkins Agents as Docker Containers
• Use Jenkins to Manage Your Docker SDLC
• Use Jenkins for End-to-End Container Orchestration
▸ Build Docker Images with Jenkins
▸ Run Docker Containers with Jenkins for:
- build
- test
- deploy
▸ Push Docker Images to registries with Jenkins
▸ Deploy Docker based applications with Jenkins
• Not Deploying Apps with Docker? You should still use Docker for build and test
© 2017 CloudBees, Inc. All Rights Reserved. 3
Run Jenkins Masters with Docker
• High-Availability via Container Orchestration and Cluster
Fault-tolerance
• Use or Extend Existing Jenkins Docker Images
• Both OSS and CloudBees master images are available on Docker Hub
• Baked-In extension points provide easy customization
• Easier and Faster Provisioning of Jenkins Masters
• Containers spin up fast and can make better utilization of underlying
resources
• Easier Upgrades
• A Dockerfile lends itself to config-as-code
▸ Add/update plugins
▸ Add/update Jenkins configuration
© 2017 CloudBees, Inc. All Rights Reserved. 4
• Add Additional Plugins
• Skip the Setup Wizard
• Requires security configuration to skip initial authentication via install token
• Otherwise, just pass in an additional JAVA_OPT
• Optimize JVM Settings
• Keep it Small and more Secure, Use Alpine
• Jenkins Alpine is 170MB vs Jenkins Debian 360MB*
• 19 vs 36 vulnerable components*
RUN /usr/local/bin/install-plugins.sh blueocean:1.5.0 slack:2.3
ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false
Custom Master Images: FROM jenkins:2.107.2-alpine
ENV JAVA_OPTS -server -XX:+AlwaysPreTouch XX:+UseConcMarkSweepGC
© 2017 CloudBees, Inc. All Rights Reserved. 5
Run Jenkins Agents with Docker
• Easier Management of Jenkins Tools
• maven:3.3.1-jdk8 OR maven:3.3.9-jdk9 OR …
• Or a Custom Agent Dockerfile right next to your Jenkinsfile
▸ Managed as code in source control
▸ Use Jenkins to manage these images
• Easy Enablement of Ephemeral Agents
• Spin up and down on demand in seconds instead of minutes (or longer)
• Config-as-code for Agents with Dockerfile
• Manage your agent configuration as Dockerfiles in source control
▸ Offload tool management to individual teams/users
• Use Jenkins to actually build and test the Docker image you use to build and
test applications
© 2017 CloudBees, Inc. All Rights Reserved. 6
Custom Docker Images for Jenkins Agents with lots of tools
• https://hub.docker.com/r/cloudbees/jnlp-slave-with-java-build-tools/
• The ‘Kitchen Sink’ of Docker Jenkins Agents
▸ Common tools: openssh-client, unzip, wget, curl, git
▸ AWS CLI: aws-cli/1.11.41
▸ Azure CLI: 0.10.8
▸ Bower: 1.8.0
▸ Cloud Foundry CLI (latest) at /usr/local/bin/cf: 6.23.1
▸ Firefox at /usr/bin/firefox: 50.1.0
▸ Firefox Geckodriver at /usr/bin/geckodriver: v0.13.0
▸ gcc (latest): 5.4.0
▸ Grunt CLI: 1.2.0
▸ Gulp: 3.9.1
▸ Java: OpenJDK 8 (latest): 1.8.0_111
▸ JMeter (3.1) located in /opt/jmeter/
▸ Kubernetes CLI at /usr/local/bin/kubectl: 1.5.2
▸ Make (latest): 4.1
▸ Maven located in /usr/share/maven/: 3.3.9
▸ MySQL Client: 5.7.17
▸ Node.js at /usr/bin/nodejs: 6.9.4
▸ Npm at /usr/bin/npm: 3.10.10
▸ Open Shift V3 CLI at /usr/local/bin/oc: 1.3.0
▸ Python/2.7.12
▸ Selenium at /opt/selenium/selenium-server-standalone.jar: 2.53
▸ XVFB: 2:1.18.4
© 2017 CloudBees, Inc. All Rights Reserved. 7
Better Yet, Don’t Use Monolithic Custom Images
Remember: A container a day keeps the monolith away
• Get Out of the CI/CD Tool Management Business
• Let Teams Manage Their Own Tools
• Allows use of same tools on laptops as are used by Jenkins
• Just about every tool imaginable is available, including a number of Docker
Hub Official Repositories
▸ Just a small sampling: fsharp, gcc, golang, gradle, groovy, haskell, java, maven, node,
perl, php, python, ruby, swift, ...
• Don’t/Can’t Use Docker Hub - No Problem
• Use a private Docker registry
• Let engineers build their own images - use Dockerfiles from Official images as
templates, have Dockerfiles in source code repos
• Use Jenkins to automate the process of building scanning and testing CI/CD
Docker images
© 2017 CloudBees, Inc. All Rights Reserved. 8
Three Basic Kinds of Docker Enabled Agents
• Static Docker Hosts - an agent (VM, EC2
instance, etc) that is running the Docker
daemon
• DIND (Docker in Docker) Agents - a
Docker container running a Docker daemon
• DOD (Docker on Docker) - a Docker
container that maps the parent host’s Docker
socket
© 2017 CloudBees, Inc. All Rights Reserved. 9
Static Docker Hosts as Agents
• Pros
• May perform better than other approaches as this approach does not
rely on spinning up additional Job specific containers
• Possibly easier to manage secure Docker access
• Could use a cluster with Jenkins Swarm plugin or CloudBees JNLP
Cloud to easily provision more capacity
• Cons
• More Jenkins administrative overhead than other approaches
▸ Must spin up a new physical Node when additional capacity is needed
▸ Requires a dedicated Node for a finite number of executors
• If not using cluster, could be inefficient use of resources
• Without some type of sharing mechanism, must be dedicated to
individual Masters
© 2017 CloudBees, Inc. All Rights Reserved. 10
DIND (Docker in Docker) Containers as Agents
• Pros
• Dynamic and ephemeral DIND based agents would allow for very
secure ephemeral workspaces
• Easier to dynamically utilize/test with multiple Docker versions
• Easier to contain cluster shared resources
• Cons
• DIND agents must be run in –privileged mode
▸ Security implications
• Images for Job specific containers will not be shared across DIND
agents, even on same host1
• Ephemeral workspaces will not be shared across job runs
▸ Mount external volume from host or network mount to DIND agent
and through to any images run inside DIND agent2
© 2017 CloudBees, Inc. All Rights Reserved. 11
DOD (Docker on Docker) - Mapping the Docker Socket
• Pros
• Docker images/layers used within agent will be shared across DOD
agents on same host
• Easier to share data between jobs by mapping volumes to host -
dependency cache, job workspace, etc.
• Cons
• Requires mounting the Docker socket of the host - security
implications
• Docker client on the agent should match host version
• Running Docker process from these agents in a clustered
environment (Mesos, Kubernetes, Docker Swarm) will result in
un-tracked/un-managed resources
• Must explictly map agent workspace to host or else Docker Pipeline
Plugin won’t work
© 2017 CloudBees, Inc. All Rights Reserved. 12
There Is Another Way
1. Use a Container Orchestrations Service - such as Kubernetes (k8s) - to
manage your Jenkins agents
2. The Jenkins Kubernetes Plugin allows running agents in k8s pods that
offer a number of features to manage containerized CI/CD:
i. limit compute resources for containers
ii. control security sensitive aspects for pod creation
3. For build and push of Docker images there are some interesting
possibilities on the horizon for standalone, daemon-less, unprivileged
Dockerfile and OCI compatible container image builder:
i. img - can’t run in a container without some major work-arounds - yet
ii. buildah - must use privileged volumes
iii. kaniko - must run as root in the container
© 2017 CloudBees, Inc. All Rights Reserved. 13
Restrictive k8s
PodSecurityPolicy
for Jenkins Agents
apiVersion: extensions/v1beta1
kind: PodSecurityPolicy
metadata:
name: restricted
spec:
privileged: false
fsGroup:
rule: RunAsAny
runAsUser:
rule: MustRunAsNonRoot
seLinux:
rule: RunAsAny
supplementalGroups:
rule: RunAsAny
volumes:
- 'emptyDir'
- 'secret'
- 'downwardAPI'
- 'configMap'
- 'persistentVolumeClaim'
- 'projected'
hostPID: false
hostIPC: false
hostNetwork: false
allowPrivilegeEscalation: false
© 2017 CloudBees, Inc. All Rights Reserved. 14
Docker as Agents Dos and Don’ts
• DON’T - USE DOCKER IN DOCKER (DIND)
• EXCEPT for specific use cases - like testing different versions of Docker
• DIND agents must be run in –privileged mode
• Caching is difficult to implement
• DO - Use Official Images
• Docker Hub provides hundreds of official images that are automatically scanned
for vulnerabilities
• Don’t pull directly from Docker Hub, proxy Docker Hub using a private registry
• Scan images for vulnerabilities
• DO - Use Docker (containers), even if it is just a tool for CI
• DO - Use a container orchestration service to manage CI/CD
infrastructure
© 2017 CloudBees, Inc. All Rights Reserved. 15
Docker in Pipeline
• Docker Pipeline Plugin
• Provides several utility Pipeline Variables to simplify the use of Docker in
Pipeline jobs
▸ docker.image(‘golang:1.7’).inside() { sh ‘go build -v -o
go-demo’ }
• Pipeline Shared Libraries
• Wrap complex steps in a reusable parameterized component
• Declarative Pipeline
• Embraces Docker Pipeline and makes Docker a top level feature
▸ agent { docker label ‘golang:1.7’ } }
• Use Docker Compose with sh step
▸ sh ‘docker-compose run --rm unit’
© 2017 CloudBees, Inc. All Rights Reserved. 16
Jenkins Kubernetes Agents
• Kurbernetes Plugin
• Provides the ability to run job specific containers in k8s Pods
podTemplate(label: 'kubernetes',
containers: [
containerTemplate(name: 'maven', image:
'maven:3.5.2-jdk-8-alpine', ttyEnabled: true, command: 'cat')
]) {
stage('Dummy') {
node('kubernetes') {
container('maven') {
sh 'mvn --version'
}
}
}
}
© 2017 CloudBees, Inc. All Rights Reserved. 17
An Opinionated View for Using Docker Agents
• Use One Agent Type: a Docker Enabled Agent (Think DOND or DIND)
• Use Plain Vanilla Docker Images in your Pipeline Jobs
• A developer should use the same Docker image to build on their laptop as is used by
Jenkins - not some specialized Jenkins only agent image
• Why have Java in a Docker image being used for a Go build?
• Use the Docker Pipeline Plugin docker.image().inside(){} Step with Care
• Attempts to make it easier to use Docker from a Jenkins agent by mapping volumes
and user/group ids - many times results in issues that are hard to diagnose
• Also, be careful with Declarative syntax as agent { docker { image ‘maven’} } } is
generating the Docker Pipeline inside syntax behind the scenes
• Technically, you don’t need Jenkins Plugins to use Jenkins & Docker
© 2017 CloudBees, Inc. All Rights Reserved. 18
Use Docker LABELS with your Jenkins Builds
Pass in things like commit SHAs as a label so you know exactly what
application commit triggered a specific Docker image build
Jenkinsfile:
sh "COMMIT_SHA=$(git rev-parse HEAD | tr -d 'n') docker-compose run --name
go-demo-unit unit-cache"
Dockerfile:
ARG COMMIT_SHA
LABEL beedemo.commit.sha=$COMMIT_SHA
Take a look at:
https://github.com/vfarcic/docker-jenkins-slave-dind/blob/master/Dockerfile
© 2017 CloudBees, Inc. All Rights Reserved. 19
SDLC with Docker and Jenkins
1. Start with Dockerfiles in source control
2. Create your own base images
a. Docker only needs to load the common layers once, and they are cached
3. Use your own DIND image to build your images
a. isolates Docker version from CI/CD platform
4. Store application data outside of the application container - container
5. Run a security scan on newly built images (and of course any external
images you may be using)
6. Provide pre-prod Docker registries for pre-prod testing
a. Tools like Artifactory support multiple registries
b. Only allow secure, tested Docker images in production Docker registry
7. Use additional Docker images to test your image
8. I forget what 8 was for
What’s Next
© 2017 CloudBees, Inc. All Rights Reserved. 21
Jenkins X
• Cloud Native Jenkins
• Commit to Deploy managed by Jenkins X on
Kubernetes
•
© 2017 CloudBees, Inc. All Rights Reserved. 22
Ephemeral Jenkins Masters
Pros
• The Jenkins home directory becomes throw-away
• Fault-tolerance of individual Jenkins masters is a thing of the past
• Many of the ‘Cons’ force best practices
Cons
• Even a light-weight Docker based Jenkins instance takes several minutes to start-up
• Build history/statistics must be managed externally (same goes for artifacts)
• More complex to set-up and manage
• config-as-code for master plugins and configuration
• ensuring individual teams/users have masters when they need them
© 2017 CloudBees, Inc. All Rights Reserved. 23
Docker + Jenkins Resources
• https://github.com/jenkinsci/docker
• https://github.com/jenkinsci/kubernetes-plugin
• Using Docker-in-Docker for your CI or testing environment? Think twice.
• https://jenkins.io/solutions/docker/
• https://jenkins.io/doc/book/pipeline/syntax/#agent see docker section
• https://jenkins.io/doc/pipeline/steps/docker-workflow/
• Some useful Docker Agents:
• Jenkins Swarm Agent
• DIND Docker Compose Agent

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Continuous Delivery with Jenkins & Kubernetes @ Sky
Continuous Delivery with Jenkins & Kubernetes @ SkyContinuous Delivery with Jenkins & Kubernetes @ Sky
Continuous Delivery with Jenkins & Kubernetes @ Sky
 
DevOps World | Jenkins World 2018 and The Future of Jenkins
DevOps World | Jenkins World 2018 and The Future of JenkinsDevOps World | Jenkins World 2018 and The Future of Jenkins
DevOps World | Jenkins World 2018 and The Future of Jenkins
 
How to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker BuildHow to Improve Your Image Builds Using Advance Docker Build
How to Improve Your Image Builds Using Advance Docker Build
 
DockerCon SF 2015: Keynote Day 1
DockerCon SF 2015: Keynote Day 1DockerCon SF 2015: Keynote Day 1
DockerCon SF 2015: Keynote Day 1
 
DockerCon 15 Keynote - Day 2
DockerCon 15 Keynote - Day 2DockerCon 15 Keynote - Day 2
DockerCon 15 Keynote - Day 2
 
A Shift from Monolith to Microservice using Docker
A Shift from Monolith to Microservice using DockerA Shift from Monolith to Microservice using Docker
A Shift from Monolith to Microservice using Docker
 
7 Habits of Highly Effective Jenkins Users
7 Habits of Highly Effective Jenkins Users7 Habits of Highly Effective Jenkins Users
7 Habits of Highly Effective Jenkins Users
 
Analyze This! CloudBees Jenkins Cluster Operations and Analytics
Analyze This! CloudBees Jenkins Cluster Operations and AnalyticsAnalyze This! CloudBees Jenkins Cluster Operations and Analytics
Analyze This! CloudBees Jenkins Cluster Operations and Analytics
 
Docker for any type of workload and any IT Infrastructure
Docker for any type of workload and any IT InfrastructureDocker for any type of workload and any IT Infrastructure
Docker for any type of workload and any IT Infrastructure
 
Introduction to Docker - Vellore Institute of Technology
Introduction to Docker - Vellore Institute of TechnologyIntroduction to Docker - Vellore Institute of Technology
Introduction to Docker - Vellore Institute of Technology
 
2016 Docker Palo Alto - CD with ECS and Jenkins
2016 Docker Palo Alto -  CD with ECS and Jenkins2016 Docker Palo Alto -  CD with ECS and Jenkins
2016 Docker Palo Alto - CD with ECS and Jenkins
 
Testing with Docker
Testing with DockerTesting with Docker
Testing with Docker
 
DockerCon SF 2015: Docker in the New York Times Newsroom
DockerCon SF 2015: Docker in the New York Times NewsroomDockerCon SF 2015: Docker in the New York Times Newsroom
DockerCon SF 2015: Docker in the New York Times Newsroom
 
Docker Container As A Service - JAX 2016
Docker Container As A Service - JAX 2016Docker Container As A Service - JAX 2016
Docker Container As A Service - JAX 2016
 
Automate App Container Delivery with CI/CD and DevOps
Automate App Container Delivery with CI/CD and DevOpsAutomate App Container Delivery with CI/CD and DevOps
Automate App Container Delivery with CI/CD and DevOps
 
Cloud Native CI/CD with Jenkins X and Knative Pipelines
Cloud Native CI/CD with Jenkins X and Knative PipelinesCloud Native CI/CD with Jenkins X and Knative Pipelines
Cloud Native CI/CD with Jenkins X and Knative Pipelines
 
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment ModelUsing Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
Using Docker Hub at Scale to Support Micro Focus' Delivery and Deployment Model
 
Jenkins X intro (from google app dev conference)
Jenkins X intro (from google app dev conference)Jenkins X intro (from google app dev conference)
Jenkins X intro (from google app dev conference)
 
DCEU 18: Use Cases and Practical Solutions for Docker Container Storage on Sw...
DCEU 18: Use Cases and Practical Solutions for Docker Container Storage on Sw...DCEU 18: Use Cases and Practical Solutions for Docker Container Storage on Sw...
DCEU 18: Use Cases and Practical Solutions for Docker Container Storage on Sw...
 
Docker, the Future of DevOps
Docker, the Future of DevOpsDocker, the Future of DevOps
Docker, the Future of DevOps
 

Similar a Docker + jenkins in the enterprise (3)

Securing Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad MeetupSecuring Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad Meetup
Kumar Ashwin
 
IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...
IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...
IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...
IBM France Lab
 
Docker - Portable Deployment
Docker - Portable DeploymentDocker - Portable Deployment
Docker - Portable Deployment
javaonfly
 

Similar a Docker + jenkins in the enterprise (3) (20)

DCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development PipelineDCEU 18: Building Your Development Pipeline
DCEU 18: Building Your Development Pipeline
 
Securing Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad MeetupSecuring Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad Meetup
 
Securing Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad MeetupSecuring Containers From Day One | null Ahmedabad Meetup
Securing Containers From Day One | null Ahmedabad Meetup
 
Docker Indy Meetup - An Opinionated View of Building Docker Images and Pipelines
Docker Indy Meetup - An Opinionated View of Building Docker Images and PipelinesDocker Indy Meetup - An Opinionated View of Building Docker Images and Pipelines
Docker Indy Meetup - An Opinionated View of Building Docker Images and Pipelines
 
Containers docker-docker hub-azureacr-azure aci
Containers docker-docker hub-azureacr-azure aciContainers docker-docker hub-azureacr-azure aci
Containers docker-docker hub-azureacr-azure aci
 
[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101[@NaukriEngineering] Docker 101
[@NaukriEngineering] Docker 101
 
Docker quick start
Docker quick startDocker quick start
Docker quick start
 
IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...
IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...
IBM Bluemix Paris Meetup #14 - Le Village by CA - 20160413 - Introduction à D...
 
Docker at MoneyBird
Docker at MoneyBirdDocker at MoneyBird
Docker at MoneyBird
 
Michigan IT Symposium 2017 - Container BOF
Michigan IT Symposium 2017 - Container BOFMichigan IT Symposium 2017 - Container BOF
Michigan IT Symposium 2017 - Container BOF
 
ExpoQA 2017 Docker and CI
ExpoQA 2017 Docker and CIExpoQA 2017 Docker and CI
ExpoQA 2017 Docker and CI
 
Docker & ci
Docker & ciDocker & ci
Docker & ci
 
Introduction to Containers & Diving a little deeper into the benefits of Con...
 Introduction to Containers & Diving a little deeper into the benefits of Con... Introduction to Containers & Diving a little deeper into the benefits of Con...
Introduction to Containers & Diving a little deeper into the benefits of Con...
 
Preparing your dockerised application for production deployment
Preparing your dockerised application for production deploymentPreparing your dockerised application for production deployment
Preparing your dockerised application for production deployment
 
IBM Container Service Overview
IBM Container Service OverviewIBM Container Service Overview
IBM Container Service Overview
 
Docker and Puppet for Continuous Integration
Docker and Puppet for Continuous IntegrationDocker and Puppet for Continuous Integration
Docker and Puppet for Continuous Integration
 
ContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small businessContainerDayVietnam2016: Dockerize a small business
ContainerDayVietnam2016: Dockerize a small business
 
Docker - Portable Deployment
Docker - Portable DeploymentDocker - Portable Deployment
Docker - Portable Deployment
 
Docker from A to Z, including Swarm and OCCS
Docker from A to Z, including Swarm and OCCSDocker from A to Z, including Swarm and OCCS
Docker from A to Z, including Swarm and OCCS
 
docker : how to deploy Digital Experience in a container drinking a cup of co...
docker : how to deploy Digital Experience in a container drinking a cup of co...docker : how to deploy Digital Experience in a container drinking a cup of co...
docker : how to deploy Digital Experience in a container drinking a cup of co...
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 

Docker + jenkins in the enterprise (3)

  • 1. © 2017 CloudBees, Inc. All Rights Reserved. 1 + DevOps
  • 2. © 2017 CloudBees, Inc. All Rights Reserved. 2 Docker + Jenkins Use Cases • Run Jenkins with Docker (or other container) • Run Jenkins Masters as Docker Containers • Run Jenkins Agents as Docker Containers • Use Jenkins to Manage Your Docker SDLC • Use Jenkins for End-to-End Container Orchestration ▸ Build Docker Images with Jenkins ▸ Run Docker Containers with Jenkins for: - build - test - deploy ▸ Push Docker Images to registries with Jenkins ▸ Deploy Docker based applications with Jenkins • Not Deploying Apps with Docker? You should still use Docker for build and test
  • 3. © 2017 CloudBees, Inc. All Rights Reserved. 3 Run Jenkins Masters with Docker • High-Availability via Container Orchestration and Cluster Fault-tolerance • Use or Extend Existing Jenkins Docker Images • Both OSS and CloudBees master images are available on Docker Hub • Baked-In extension points provide easy customization • Easier and Faster Provisioning of Jenkins Masters • Containers spin up fast and can make better utilization of underlying resources • Easier Upgrades • A Dockerfile lends itself to config-as-code ▸ Add/update plugins ▸ Add/update Jenkins configuration
  • 4. © 2017 CloudBees, Inc. All Rights Reserved. 4 • Add Additional Plugins • Skip the Setup Wizard • Requires security configuration to skip initial authentication via install token • Otherwise, just pass in an additional JAVA_OPT • Optimize JVM Settings • Keep it Small and more Secure, Use Alpine • Jenkins Alpine is 170MB vs Jenkins Debian 360MB* • 19 vs 36 vulnerable components* RUN /usr/local/bin/install-plugins.sh blueocean:1.5.0 slack:2.3 ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false Custom Master Images: FROM jenkins:2.107.2-alpine ENV JAVA_OPTS -server -XX:+AlwaysPreTouch XX:+UseConcMarkSweepGC
  • 5. © 2017 CloudBees, Inc. All Rights Reserved. 5 Run Jenkins Agents with Docker • Easier Management of Jenkins Tools • maven:3.3.1-jdk8 OR maven:3.3.9-jdk9 OR … • Or a Custom Agent Dockerfile right next to your Jenkinsfile ▸ Managed as code in source control ▸ Use Jenkins to manage these images • Easy Enablement of Ephemeral Agents • Spin up and down on demand in seconds instead of minutes (or longer) • Config-as-code for Agents with Dockerfile • Manage your agent configuration as Dockerfiles in source control ▸ Offload tool management to individual teams/users • Use Jenkins to actually build and test the Docker image you use to build and test applications
  • 6. © 2017 CloudBees, Inc. All Rights Reserved. 6 Custom Docker Images for Jenkins Agents with lots of tools • https://hub.docker.com/r/cloudbees/jnlp-slave-with-java-build-tools/ • The ‘Kitchen Sink’ of Docker Jenkins Agents ▸ Common tools: openssh-client, unzip, wget, curl, git ▸ AWS CLI: aws-cli/1.11.41 ▸ Azure CLI: 0.10.8 ▸ Bower: 1.8.0 ▸ Cloud Foundry CLI (latest) at /usr/local/bin/cf: 6.23.1 ▸ Firefox at /usr/bin/firefox: 50.1.0 ▸ Firefox Geckodriver at /usr/bin/geckodriver: v0.13.0 ▸ gcc (latest): 5.4.0 ▸ Grunt CLI: 1.2.0 ▸ Gulp: 3.9.1 ▸ Java: OpenJDK 8 (latest): 1.8.0_111 ▸ JMeter (3.1) located in /opt/jmeter/ ▸ Kubernetes CLI at /usr/local/bin/kubectl: 1.5.2 ▸ Make (latest): 4.1 ▸ Maven located in /usr/share/maven/: 3.3.9 ▸ MySQL Client: 5.7.17 ▸ Node.js at /usr/bin/nodejs: 6.9.4 ▸ Npm at /usr/bin/npm: 3.10.10 ▸ Open Shift V3 CLI at /usr/local/bin/oc: 1.3.0 ▸ Python/2.7.12 ▸ Selenium at /opt/selenium/selenium-server-standalone.jar: 2.53 ▸ XVFB: 2:1.18.4
  • 7. © 2017 CloudBees, Inc. All Rights Reserved. 7 Better Yet, Don’t Use Monolithic Custom Images Remember: A container a day keeps the monolith away • Get Out of the CI/CD Tool Management Business • Let Teams Manage Their Own Tools • Allows use of same tools on laptops as are used by Jenkins • Just about every tool imaginable is available, including a number of Docker Hub Official Repositories ▸ Just a small sampling: fsharp, gcc, golang, gradle, groovy, haskell, java, maven, node, perl, php, python, ruby, swift, ... • Don’t/Can’t Use Docker Hub - No Problem • Use a private Docker registry • Let engineers build their own images - use Dockerfiles from Official images as templates, have Dockerfiles in source code repos • Use Jenkins to automate the process of building scanning and testing CI/CD Docker images
  • 8. © 2017 CloudBees, Inc. All Rights Reserved. 8 Three Basic Kinds of Docker Enabled Agents • Static Docker Hosts - an agent (VM, EC2 instance, etc) that is running the Docker daemon • DIND (Docker in Docker) Agents - a Docker container running a Docker daemon • DOD (Docker on Docker) - a Docker container that maps the parent host’s Docker socket
  • 9. © 2017 CloudBees, Inc. All Rights Reserved. 9 Static Docker Hosts as Agents • Pros • May perform better than other approaches as this approach does not rely on spinning up additional Job specific containers • Possibly easier to manage secure Docker access • Could use a cluster with Jenkins Swarm plugin or CloudBees JNLP Cloud to easily provision more capacity • Cons • More Jenkins administrative overhead than other approaches ▸ Must spin up a new physical Node when additional capacity is needed ▸ Requires a dedicated Node for a finite number of executors • If not using cluster, could be inefficient use of resources • Without some type of sharing mechanism, must be dedicated to individual Masters
  • 10. © 2017 CloudBees, Inc. All Rights Reserved. 10 DIND (Docker in Docker) Containers as Agents • Pros • Dynamic and ephemeral DIND based agents would allow for very secure ephemeral workspaces • Easier to dynamically utilize/test with multiple Docker versions • Easier to contain cluster shared resources • Cons • DIND agents must be run in –privileged mode ▸ Security implications • Images for Job specific containers will not be shared across DIND agents, even on same host1 • Ephemeral workspaces will not be shared across job runs ▸ Mount external volume from host or network mount to DIND agent and through to any images run inside DIND agent2
  • 11. © 2017 CloudBees, Inc. All Rights Reserved. 11 DOD (Docker on Docker) - Mapping the Docker Socket • Pros • Docker images/layers used within agent will be shared across DOD agents on same host • Easier to share data between jobs by mapping volumes to host - dependency cache, job workspace, etc. • Cons • Requires mounting the Docker socket of the host - security implications • Docker client on the agent should match host version • Running Docker process from these agents in a clustered environment (Mesos, Kubernetes, Docker Swarm) will result in un-tracked/un-managed resources • Must explictly map agent workspace to host or else Docker Pipeline Plugin won’t work
  • 12. © 2017 CloudBees, Inc. All Rights Reserved. 12 There Is Another Way 1. Use a Container Orchestrations Service - such as Kubernetes (k8s) - to manage your Jenkins agents 2. The Jenkins Kubernetes Plugin allows running agents in k8s pods that offer a number of features to manage containerized CI/CD: i. limit compute resources for containers ii. control security sensitive aspects for pod creation 3. For build and push of Docker images there are some interesting possibilities on the horizon for standalone, daemon-less, unprivileged Dockerfile and OCI compatible container image builder: i. img - can’t run in a container without some major work-arounds - yet ii. buildah - must use privileged volumes iii. kaniko - must run as root in the container
  • 13. © 2017 CloudBees, Inc. All Rights Reserved. 13 Restrictive k8s PodSecurityPolicy for Jenkins Agents apiVersion: extensions/v1beta1 kind: PodSecurityPolicy metadata: name: restricted spec: privileged: false fsGroup: rule: RunAsAny runAsUser: rule: MustRunAsNonRoot seLinux: rule: RunAsAny supplementalGroups: rule: RunAsAny volumes: - 'emptyDir' - 'secret' - 'downwardAPI' - 'configMap' - 'persistentVolumeClaim' - 'projected' hostPID: false hostIPC: false hostNetwork: false allowPrivilegeEscalation: false
  • 14. © 2017 CloudBees, Inc. All Rights Reserved. 14 Docker as Agents Dos and Don’ts • DON’T - USE DOCKER IN DOCKER (DIND) • EXCEPT for specific use cases - like testing different versions of Docker • DIND agents must be run in –privileged mode • Caching is difficult to implement • DO - Use Official Images • Docker Hub provides hundreds of official images that are automatically scanned for vulnerabilities • Don’t pull directly from Docker Hub, proxy Docker Hub using a private registry • Scan images for vulnerabilities • DO - Use Docker (containers), even if it is just a tool for CI • DO - Use a container orchestration service to manage CI/CD infrastructure
  • 15. © 2017 CloudBees, Inc. All Rights Reserved. 15 Docker in Pipeline • Docker Pipeline Plugin • Provides several utility Pipeline Variables to simplify the use of Docker in Pipeline jobs ▸ docker.image(‘golang:1.7’).inside() { sh ‘go build -v -o go-demo’ } • Pipeline Shared Libraries • Wrap complex steps in a reusable parameterized component • Declarative Pipeline • Embraces Docker Pipeline and makes Docker a top level feature ▸ agent { docker label ‘golang:1.7’ } } • Use Docker Compose with sh step ▸ sh ‘docker-compose run --rm unit’
  • 16. © 2017 CloudBees, Inc. All Rights Reserved. 16 Jenkins Kubernetes Agents • Kurbernetes Plugin • Provides the ability to run job specific containers in k8s Pods podTemplate(label: 'kubernetes', containers: [ containerTemplate(name: 'maven', image: 'maven:3.5.2-jdk-8-alpine', ttyEnabled: true, command: 'cat') ]) { stage('Dummy') { node('kubernetes') { container('maven') { sh 'mvn --version' } } } }
  • 17. © 2017 CloudBees, Inc. All Rights Reserved. 17 An Opinionated View for Using Docker Agents • Use One Agent Type: a Docker Enabled Agent (Think DOND or DIND) • Use Plain Vanilla Docker Images in your Pipeline Jobs • A developer should use the same Docker image to build on their laptop as is used by Jenkins - not some specialized Jenkins only agent image • Why have Java in a Docker image being used for a Go build? • Use the Docker Pipeline Plugin docker.image().inside(){} Step with Care • Attempts to make it easier to use Docker from a Jenkins agent by mapping volumes and user/group ids - many times results in issues that are hard to diagnose • Also, be careful with Declarative syntax as agent { docker { image ‘maven’} } } is generating the Docker Pipeline inside syntax behind the scenes • Technically, you don’t need Jenkins Plugins to use Jenkins & Docker
  • 18. © 2017 CloudBees, Inc. All Rights Reserved. 18 Use Docker LABELS with your Jenkins Builds Pass in things like commit SHAs as a label so you know exactly what application commit triggered a specific Docker image build Jenkinsfile: sh "COMMIT_SHA=$(git rev-parse HEAD | tr -d 'n') docker-compose run --name go-demo-unit unit-cache" Dockerfile: ARG COMMIT_SHA LABEL beedemo.commit.sha=$COMMIT_SHA Take a look at: https://github.com/vfarcic/docker-jenkins-slave-dind/blob/master/Dockerfile
  • 19. © 2017 CloudBees, Inc. All Rights Reserved. 19 SDLC with Docker and Jenkins 1. Start with Dockerfiles in source control 2. Create your own base images a. Docker only needs to load the common layers once, and they are cached 3. Use your own DIND image to build your images a. isolates Docker version from CI/CD platform 4. Store application data outside of the application container - container 5. Run a security scan on newly built images (and of course any external images you may be using) 6. Provide pre-prod Docker registries for pre-prod testing a. Tools like Artifactory support multiple registries b. Only allow secure, tested Docker images in production Docker registry 7. Use additional Docker images to test your image 8. I forget what 8 was for
  • 21. © 2017 CloudBees, Inc. All Rights Reserved. 21 Jenkins X • Cloud Native Jenkins • Commit to Deploy managed by Jenkins X on Kubernetes •
  • 22. © 2017 CloudBees, Inc. All Rights Reserved. 22 Ephemeral Jenkins Masters Pros • The Jenkins home directory becomes throw-away • Fault-tolerance of individual Jenkins masters is a thing of the past • Many of the ‘Cons’ force best practices Cons • Even a light-weight Docker based Jenkins instance takes several minutes to start-up • Build history/statistics must be managed externally (same goes for artifacts) • More complex to set-up and manage • config-as-code for master plugins and configuration • ensuring individual teams/users have masters when they need them
  • 23. © 2017 CloudBees, Inc. All Rights Reserved. 23 Docker + Jenkins Resources • https://github.com/jenkinsci/docker • https://github.com/jenkinsci/kubernetes-plugin • Using Docker-in-Docker for your CI or testing environment? Think twice. • https://jenkins.io/solutions/docker/ • https://jenkins.io/doc/book/pipeline/syntax/#agent see docker section • https://jenkins.io/doc/pipeline/steps/docker-workflow/ • Some useful Docker Agents: • Jenkins Swarm Agent • DIND Docker Compose Agent