Continuous Delivery of Infrastructure with Jenkins
This is a guest post by Jenkins World speaker R Tyler Croy, infrastructure maintainer for the Jenkins project. |
I don’t think I have ever met a tools, infrastructure, or operations team that did not have a ton of work to do. The Jenkins project’s infrastructure "team" is no different; too much work, not enough time. In lieu of hiring more people, which isn’t always an option, I have found heavy automation and continuous delivery pipelines to be two solutions within reach of the over-worked infrastructure team.
As a big believer in the concept of "Infrastructure as Code", I have been, slowly but surely, moving the project’s infrastructure from manual tasks to code, whether implemented in our Puppet code-base, Docker containers, or even as machine specifications with Packer. The more of our infrastructure that is code, the more we can apply continuous delivery practices to consistently and reliably build, test and deliver our infrastructure.
This approach integrates nicely with Jenkins Pipeline, allowing us to also define our continuous delivery pipelines themselves as code. For example, by sanity-checking our BIND zone files:
node('docker') {
def dockerImage = 'rtyler/jenkins-infra-builder'
checkout scm
docker.image(dockerImage).inside {
sh "/usr/sbin/named-checkzone jenkins-ci.org dist/profile/files/bind/jenkins-ci.org.zone"
sh "/usr/sbin/named-checkzone jenkins.io dist/profile/files/bind/jenkins.io.zone"
}
}
Or delivering our Docker containers automatically to
Docker Hub
, with a Jenkinsfile
such as:
node('docker') {
checkout scm
/* Get our abbreviated SHA-1 to uniquely identify this build */
def shortCommit = sh(script: 'git rev-parse HEAD', returnStdout: true).take(6)
stage 'Build ircbot' {
withEnv(["JAVA_HOME=${tool 'jdk8'}", "PATH+MVN=${tool 'mvn'}/bin"]) }
sh 'make bot'
}
}
def whale
stage 'Build container' {
whale = docker.build("jenkinsciinfra/ircbot:build${shortCommit}")
}
stage 'Deploy container' {
/* Push to Docker Hub */
whale.push()
}
}
In my talk at Jenkins World (September 14th, 3:00 - 3:45pm in Exhibit Hall A-1) I will discuss these Jenkinsfiles along with some of the strategies, patterns and code used with the Jenkins project’s open source infrastructure to get the most out of the team’s limited time.
R Tyler will be
presenting
more about continuous delivery of infrastructure at
Jenkins World
in September. Register with the code |