Skip to content

Instantly share code, notes, and snippets.

@staylorx
Created December 13, 2017 18:46
Show Gist options
  • Save staylorx/a3b47de948272344c441fd0d64922f3f to your computer and use it in GitHub Desktop.
Save staylorx/a3b47de948272344c441fd0d64922f3f to your computer and use it in GitHub Desktop.
Example docker image builder with Clair test for jenkins
#!/usr/bin/env groovy
//Dockerfile including Clair check.
//Steve.Taylor@cu.edu DEC-2017
node('docker') {
def docker_registry="nexus.mydomain.err:5000"
def clair_endpoint="https://nexus.mydomain.err:6060"
def image_name="uis-cam/endpoint-heartbeat"
def es_version="6.0.0"
def full_image_name = "${docker_registry}/${image_name}:${es_version}"
def heartbeat
stage('Preparation') {
deleteDir()
git 'https://stash.cu.edu/scm/mdw/docker-endpoint-heartbeat.git'
}
stage('Build Heartbeat') {
dir('./') {
heartbeat = docker.build(image_name,"--file Dockerfile .")
}
}
stage('Clair Test') {
sh 'wget -nv -O klar http://artifactory.prod.cu.edu/artifactory/ext-archive-local/optiopay/klar/1.5/klar-1.5-linux-amd64'
sh 'chmod u+x klar'
def statusCode = sh script:"CLAIR_ADDR=${clair_endpoint} ./klar ${full_image_name}", returnStatus:true
if (statusCode!=0) {
currentBuild.result = 'FAILURE'
error "Docker Image did not pass Clair testing."
}
}
stage('Push images') {
//credentials from the CAM DEV Jenkins
docker.withRegistry("https://${docker_registry}", 'registry-credential') {
heartbeat.push("${es_version}")
heartbeat.push("latest")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment