jenkins docker

Post on 12-Jan-2017

33.172 Views

Category:

Technology

1 Downloads

Preview:

Click to see full reader

TRANSCRIPT

OrchestratingContinuousDelivery

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

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

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

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

Faster

alexsotoblordofthejars

Faster

Sooner

alexsotoblordofthejars

Faster

SoonerBetter

alexsotoblordofthejars

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

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

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

alexsotoblordofthejars

G O - G O - G O

alexsotoblordofthejars

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

alexsotoblordofthejars

alexsotoblordofthejars

$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

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

alexsotoblordofthejars

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

DockerTraceability: identifieswhichbuildpushedaparticularcontainer,displaysonJenkinsbuildspage

alexsotoblordofthejars

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

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

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

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

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

alexsotoblordofthejars

alexsotoblordofthejars

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

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

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

alexsotoblordofthejars

alexsotoblordofthejars

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

alexsotoblordofthejars

alexsotoblordofthejars

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

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

alexsotoblordofthejars

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

ContinuousDeliveryasCode

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

alexsotoblordofthejars

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

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

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

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

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

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

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)

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

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

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

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

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'git@github.com:lordofthejars/busybox.git''git@github.com: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

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

alexsotoblordofthejars

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

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

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::"foo@bar.com""foo@bar.com"

]]

}}

J E N K I N S F I L E

alexsotoblordofthejars

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

alexsotoblordofthejars

C O N C L U S I O N SAutomationistheKey

alexsotoblordofthejars

C O N C L U S I O N SAutomationistheKey

DockerSimplifiesEnvironmentProblems

alexsotoblordofthejars

C O N C L U S I O N SAutomationistheKey

DockerSimplifiesEnvironmentProblemsJenkinsisReadyForDockerandCD

alexsotoblordofthejars

C O N C L U S I O N SAutomationistheKey

DockerSimplifiesEnvironmentProblemsJenkinsisReadyForDockerandCDPiplelineasCodegivesyouFreedom

alexsotoblordofthejars

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

alexsotoblordofthejars

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

C L O U D B E E S

J E N K I N S

Itisnotnecessarytochange.

Survivalisnotmandatory.

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

alexsotoblordofthejars

Q U E S T I O N S

alexsotoblordofthejars

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

asotobu@gmail.com

alexsotoblordofthejars

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

top related