Top Banner
Orchestrating Continuous Delivery DOCKER AND JENKINS.
77

Jenkins Docker

Jan 12, 2017

Download

Technology

Alex Soto
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Jenkins Docker

OrchestratingContinuousDelivery

D O C K E R A N D J E N K I N S .

Page 2: Jenkins Docker

A L E X S O T O B - L O R D O F T H E J A R S . C O M

alexsotoblordofthejars

Page 3: Jenkins Docker

S O F T W A R E I S E A T I N GT H E W O R L D

alexsotoblordofthejars

Page 4: Jenkins Docker

alexsotoblordofthejars

Page 5: Jenkins Docker

alexsotoblordofthejars

Page 6: Jenkins Docker

alexsotoblordofthejars

Page 7: Jenkins Docker

alexsotoblordofthejars

Page 8: Jenkins Docker

alexsotoblordofthejars

Page 9: Jenkins Docker

alexsotoblordofthejars

Page 10: Jenkins Docker

alexsotoblordofthejars

Page 11: Jenkins Docker

Faster

alexsotoblordofthejars

Page 12: Jenkins Docker

Faster

Sooner

alexsotoblordofthejars

Page 13: Jenkins Docker

Faster

SoonerBetter

alexsotoblordofthejars

Page 14: Jenkins Docker

K E Y I S A U T O M A T I O N

alexsotoblordofthejars

Page 15: Jenkins Docker

alexsotoblordofthejars

Page 16: Jenkins Docker

alexsotoblordofthejars

Page 17: Jenkins Docker

alexsotoblordofthejars

Page 18: Jenkins Docker

S P E E D + F R I C T I O N = H E A T

alexsotoblordofthejars

Page 19: Jenkins Docker

G O - G O - G O

alexsotoblordofthejars

Page 20: Jenkins Docker

C O N T A I N E R S C O D I F YO S C O N F I G

alexsotoblordofthejars

Page 21: Jenkins Docker

alexsotoblordofthejars

Page 22: Jenkins Docker

$dockerrun$dockerrun--tiubuntutiubuntu::12.1012.10bashbash

[[a2ba2b]]aptapt--getgetupdateupdate

[[a2ba2b]]aptapt--getgetinstallcurlinstallcurl

[[a2ba2b]]exitexit

$dockercommit$dockercommit--mm"curlinstalled""curlinstalled"a2busernamea2busername//imageimage

$dockerbuild$dockerbuild..

H O W I B U I L D A D O C K E R I M A G E ?

alexsotoblordofthejars

Page 23: Jenkins Docker
Page 24: Jenkins Docker

J E N K I N S : D O C K E R A N D C DDockerHubNotification: triggersdownstreamjobswhenataggedcontainerispushedtoDockerHub

alexsotoblordofthejars

Page 25: Jenkins Docker

J E N K I N S : D O C K E R A N D C DDockerHubNotification: triggersdownstreamjobswhenataggedcontainerispushedtoDockerHub

DockerTraceability: identifieswhichbuildpushedaparticularcontainer,displaysonJenkinsbuildspage

alexsotoblordofthejars

Page 26: Jenkins Docker

J E N K I N S : D O C K E R A N D C DDockerHubNotification: triggersdownstreamjobswhenataggedcontainerispushedtoDockerHub

DockerTraceability: identifieswhichbuildpushedaparticularcontainer,displaysonJenkinsbuildspage

DockerCustomBuildEnvironment: specifiescustomizedbuildenvironmentsasDockercontainers

alexsotoblordofthejars

Page 27: Jenkins Docker

J E N K I N S : D O C K E R A N D C DDockerHubNotification: triggersdownstreamjobswhenataggedcontainerispushedtoDockerHub

DockerTraceability: identifieswhichbuildpushedaparticularcontainer,displaysonJenkinsbuildspage

DockerCustomBuildEnvironment: specifiescustomizedbuildenvironmentsasDockercontainers

Docker: useadockerhosttodynamicallyprovisionaslave,runasinglebuild,thentear-down

alexsotoblordofthejars

Page 28: Jenkins Docker

J E N K I N S : D O C K E R A N D C DDockerHubNotification: triggersdownstreamjobswhenataggedcontainerispushedtoDockerHub

DockerTraceability: identifieswhichbuildpushedaparticularcontainer,displaysonJenkinsbuildspage

DockerCustomBuildEnvironment: specifiescustomizedbuildenvironmentsasDockercontainers

Docker: useadockerhosttodynamicallyprovisionaslave,runasinglebuild,thentear-down

BuildandPublish: buildsprojectsthathaveaDockerfileandpushestheresultanttaggedimagetoDockerHub

alexsotoblordofthejars

Page 29: Jenkins Docker

B U I L D , T E S T , & D E P L O Y D O C K E R I M A G E SF R O M J E N K I N S

alexsotoblordofthejars

Page 30: Jenkins Docker

D O C K E R H U B N O T I F I C A T I O N P L U G I N

alexsotoblordofthejars

Page 31: Jenkins Docker

alexsotoblordofthejars

Page 32: Jenkins Docker

alexsotoblordofthejars

Page 33: Jenkins Docker

D O C K E R T R A C E A B I L I T Y P L U G I N

alexsotoblordofthejars

Page 34: Jenkins Docker

alexsotoblordofthejars

Page 35: Jenkins Docker

alexsotoblordofthejars

Page 36: Jenkins Docker

alexsotoblordofthejars

Page 37: Jenkins Docker

D O C K E R P L U G I N

alexsotoblordofthejars

Page 38: Jenkins Docker

alexsotoblordofthejars

Page 39: Jenkins Docker

D O C K E R C U S T O M B U I L D E N V I R O N M E N TP L U G I N

alexsotoblordofthejars

Page 40: Jenkins Docker

alexsotoblordofthejars

Page 41: Jenkins Docker

alexsotoblordofthejars

Page 42: Jenkins Docker

B U I L D A N D P U B L I S H P L U G I N

alexsotoblordofthejars

Page 43: Jenkins Docker

alexsotoblordofthejars

Page 44: Jenkins Docker

alexsotoblordofthejars

Page 45: Jenkins Docker

alexsotoblordofthejars

Page 46: Jenkins Docker

N O M O R E B U I L DJ O B S / U P / D O W N S T R E A M S P L E A S E ! ! ! !

alexsotoblordofthejars

Page 47: Jenkins Docker

ContinuousDeliveryasCode

P I P E L I N E P L U G I N

alexsotoblordofthejars

Page 48: Jenkins Docker

F E A T U R E S O F P I P E L I N E P L U G I NConfigurationinSourceRepositories

Page 49: Jenkins Docker

F E A T U R E S O F P I P E L I N E P L U G I NConfigurationinSourceRepositories

Lessclick-and-type,morecode

Page 50: Jenkins Docker

F E A T U R E S O F P I P E L I N E P L U G I NConfigurationinSourceRepositories

Lessclick-and-type,morecodeFromsimpletocomplex

Page 51: Jenkins Docker

F E A T U R E S O F P I P E L I N E P L U G I NConfigurationinSourceRepositories

Lessclick-and-type,morecodeFromsimpletocomplex

SurvivesJenkinsrestarts&connectionlosses($)

Page 52: Jenkins Docker

F E A T U R E S O F P I P E L I N E P L U G I NConfigurationinSourceRepositories

Lessclick-and-type,morecodeFromsimpletocomplex

SurvivesJenkinsrestarts&connectionlosses($)ReusableDefinitions

Page 53: Jenkins Docker

F E A T U R E S O F P I P E L I N E P L U G I NConfigurationinSourceRepositories

Lessclick-and-type,morecodeFromsimpletocomplex

SurvivesJenkinsrestarts&connectionlosses($)ReusableDefinitions

Buildhistory/trendsegregatedperbranches

Page 54: Jenkins Docker

F E A T U R E S O F P I P E L I N E P L U G I NConfigurationinSourceRepositories

Lessclick-and-type,morecodeFromsimpletocomplex

SurvivesJenkinsrestarts&connectionlosses($)ReusableDefinitions

Buildhistory/trendsegregatedperbranchesUI($->OSS)

Page 55: Jenkins Docker
Page 56: Jenkins Docker

stagestage'compileAndUnit''compileAndUnit'

nodenode{{

gitbranchgitbranch::'master''master',,urlurl::'https://github.com/lordofthejars/starwars.git''https://github.com/lordofthejars/starwars.git'

gradlegradle'cleantest''cleantest'

stashexcludesstashexcludes::'build/''build/',,includesincludes::'**''**',,namename::'source''source'

stashincludesstashincludes::'build'build//jacocojacoco/*.exec',name:'unitCodeCoverage'/*.exec',name:'unitCodeCoverage'

step([$class:'JUnitResultArchiver',testResults:'**/step([$class:'JUnitResultArchiver',testResults:'**/buildbuild//testtest--resultsresults//**..xml'xml']]))

}}

stagestage'codeQuality''codeQuality'

parallelparallel'pmd''pmd'::{{

nodenode{{

unstashunstash'source''source'

gradlegradle'pmdMain''pmdMain'

stepstep(([[$$classclass::'PmdPublisher''PmdPublisher',,patternpattern::'build/reports/pmd/*.xml''build/reports/pmd/*.xml']]))

}}

}},,'jacoco''jacoco'::{{

nodenode{{

unstashunstash'source''source'

unstashunstash'unitCodeCoverage''unitCodeCoverage'

gradlegradle'jacocoTestReport''jacocoTestReport'

}}

}}

J E N K I N S F I L E ( 1 / 3 )

alexsotoblordofthejars

Page 57: Jenkins Docker

stagestage'assemble-binaries''assemble-binaries'

nodenode(('linux''linux')){{

unstashunstash'source''source'

withEnvwithEnv(([["SOURCE_BUILD_NUMBER=${env.BUILD_NUMBER}""SOURCE_BUILD_NUMBER=${env.BUILD_NUMBER}"]])){{

gradlegradle'assemble''assemble'

}}

}}

inputmessageinputmessage::"DeployApplicationtoQA?""DeployApplicationtoQA?"

stagenamestagename::'DeploytoQA''DeploytoQA',,concurrencyconcurrency::11

nodenode{{

echoecho"ApplicationDeployedtoQA.""ApplicationDeployedtoQA."

}}

J E N K I N S F I L E ( 2 / 3 )

alexsotoblordofthejars

Page 58: Jenkins Docker

gradlegradle==loadload'jenkins/gradle.groovy''jenkins/gradle.groovy'

withCredentialswithCredentials(([[[[$$classclass::'UsernamePasswordMultiBinding''UsernamePasswordMultiBinding',,

credentialsIdcredentialsId::'MyID''MyID',,usernameVariableusernameVariable::'GIT_USERNAME''GIT_USERNAME',,

passwordVariablepasswordVariable::'GIT_PASSWORD''GIT_PASSWORD']]]])){{

shsh"gittag-asome_tag-m'Jenkins'""gittag-asome_tag-m'Jenkins'"

shsh"gitpushhttps://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@--tags""gitpushhttps://${env.GIT_USERNAME}:${env.GIT_PASSWORD}@--tags"

}}

defmvnHometooldefmvnHometool'Maven3.3.3''Maven3.3.3'

shsh"${mvnHome}/bin/mvn-Bverify""${mvnHome}/bin/mvn-Bverify"

J E N K I N S F I L E ( 3 / 3 )

alexsotoblordofthejars

Page 59: Jenkins Docker

D O C K E R P I P E L I N E I N T E G R A T I O N

Page 60: Jenkins Docker

dockerdocker..withRegistrywithRegistry(('https://lordofthejars-docker-continuous_delivery.bintray.io''https://lordofthejars-docker-continuous_delivery.bintray.io',,'d4fc3fa9-39f7-47ea-a57c-795642f90989''d4fc3fa9-39f7-47ea-a57c-795642f90989')){{

gitgit'[email protected]:lordofthejars/busybox.git''[email protected]:lordofthejars/busybox.git'

defnewAppdefnewApp==dockerdocker..buildbuild"lordofthejars-docker-continuous_delivery.bintray.io/lordofthejars/javatest:${env.BUILD_TAG}""lordofthejars-docker-continuous_delivery.bintray.io/lordofthejars/javatest:${env.BUILD_TAG}"

newAppnewApp..pushpush(())

}}

dockerdocker..imageimage(('lordofthejars/javatest''lordofthejars/javatest'))..withRunwithRun{{cc-->>

shsh'./executeTests.sh''./executeTests.sh'

}}

J E N K I N S F I L E ( 1 / 2 )

alexsotoblordofthejars

Page 61: Jenkins Docker

dockerdocker..imageimage(('maven:3.3.3-jdk-8''maven:3.3.3-jdk-8'))..insideinside(('-v~/.m2/repository:/m2repo-u1000:50''-v~/.m2/repository:/m2repo-u1000:50')){{

gitgit'…your-sources…''…your-sources…'

shsh'mvn-Dmaven.repo.local=/m2repocleaninstall''mvn-Dmaven.repo.local=/m2repocleaninstall'

}}

dockerdocker..withServerwithServer(('tcp://swarm.mycorp.com:2376''tcp://swarm.mycorp.com:2376',,'swarm-certs''swarm-certs')){{

dockerdocker..imageimage(('httpd''httpd'))..withRunwithRun(('-p8080:80''-p8080:80')){{cc-->>

shsh"curl-ihttp://${hostIp(c)}:8080/""curl-ihttp://${hostIp(c)}:8080/"

}}

}}

defdefhostIphostIp((containercontainer)){{

shsh"dockerinspect-f{{.Node.Ip}}${container.id}>hostIp""dockerinspect-f{{.Node.Ip}}${container.id}>hostIp"

readFilereadFile(('hostIp''hostIp'))..trimtrim(())

}}

J E N K I N S F I L E ( 2 / 2 )

alexsotoblordofthejars

Page 62: Jenkins Docker

alexsotoblordofthejars

Page 63: Jenkins Docker

D I F F E R E N T W A Y S O F D O I N G S A M ET H I N G S W I T H D S L

alexsotoblordofthejars

Page 64: Jenkins Docker

S I M P L E B U I L D F O R P I P E L I N E P L U G I N

alexsotoblordofthejars

Page 65: Jenkins Docker

simpleBuildsimpleBuild{{

machinemachine=="hi-speed""hi-speed"

dockerdocker=="java:1.9""java:1.9"

envenv==[[

FOOFOO::4242,,

BARBAR::"YASS""YASS"

]]

git_repogit_repo=="https://github.com/cloudbeers/PR-demo""https://github.com/cloudbeers/PR-demo"

before_scriptbefore_script=="echobefore""echobefore"

scriptscript=='echoafter$FOO''echoafter$FOO'

after_scriptafter_script=='echodonenow''echodonenow'

notificationsnotifications==[[

emailemail::"[email protected]""[email protected]"

]]

}}

J E N K I N S F I L E

alexsotoblordofthejars

Page 66: Jenkins Docker

L E T ' S W I N D D O W N

alexsotoblordofthejars

Page 67: Jenkins Docker

C O N C L U S I O N SAutomationistheKey

alexsotoblordofthejars

Page 68: Jenkins Docker

C O N C L U S I O N SAutomationistheKey

DockerSimplifiesEnvironmentProblems

alexsotoblordofthejars

Page 69: Jenkins Docker

C O N C L U S I O N SAutomationistheKey

DockerSimplifiesEnvironmentProblemsJenkinsisReadyForDockerandCD

alexsotoblordofthejars

Page 70: Jenkins Docker

C O N C L U S I O N SAutomationistheKey

DockerSimplifiesEnvironmentProblemsJenkinsisReadyForDockerandCDPiplelineasCodegivesyouFreedom

alexsotoblordofthejars

Page 71: Jenkins Docker

O N L Y O N E P I E C E O F T H E J I G S A W

alexsotoblordofthejars

Page 72: Jenkins Docker

F O L L O W T H E R U L E S , A D A P T T O Y O U RN E E D S

alexsotoblordofthejars

Page 73: Jenkins Docker

C L O U D B E E S

J E N K I N S

Page 74: Jenkins Docker

Itisnotnecessarytochange.

Survivalisnotmandatory.

W . E D W A R D S D E M I N G

alexsotoblordofthejars

Page 75: Jenkins Docker

Q U E S T I O N S

alexsotoblordofthejars

Page 76: Jenkins Docker

http://www.slideshare.net/asotobu/jenkins-docker

[email protected]

alexsotoblordofthejars

Page 77: Jenkins Docker

https://github.com/lordofthejars/starwarshttps://wiki.jenkins-ci.org/display/JENKINS/Pipeline+Plugin

https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Pipeline+Pluginhttps://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Traceability

https://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Build+and+Publish+pluginhttps://wiki.jenkins-ci.org/display/JENKINS/CloudBees+Docker+Hub+Notification

https://wiki.jenkins-ci.org/display/JENKINS/Docker+Pluginhttps://github.com/jenkinsci/simple-build-for-pipeline-plugin