From 2c4a81513ed4099fdd9d99e442be9c10d3df8ba0 Mon Sep 17 00:00:00 2001 From: raffis Date: Tue, 4 May 2021 08:57:34 +0200 Subject: [PATCH] Use kaniko instead dind DK-1985 (#4) * use kaniko instead dind * remove unsec flag * mkdir folder --- Jenkinsfile | 40 +++++++--------------------------------- 1 file changed, 7 insertions(+), 33 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index d51835e..0ebcf20 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,8 +9,9 @@ podTemplate(label: 'k8skafka-controller', ttyEnabled: true ), containerTemplate( - name: 'docker', - image: 'docker:latest', + name: 'kaniko', + command: '/busybox/cat', + image: 'gcr.io/kaniko-project/executor:debug', ttyEnabled: true ), containerTemplate( @@ -21,17 +22,13 @@ podTemplate(label: 'k8skafka-controller', ), ], volumes: [ - hostPathVolume(mountPath: '/var/run/docker.sock', hostPath: '/var/run/docker.sock'), + secretVolume(secretName: 'dockerauth', mountPath: '/root/dockerauth') ] ) { node ('k8skafka-controller') { ansiColor("xterm") { stage('checkout') { checkout(scm) - - container('docker') { - dockerAuth() - } } stage("build") { @@ -56,9 +53,9 @@ podTemplate(label: 'k8skafka-controller', version = "$major.$minor.$patch$group" - container('docker') { - sh "docker build . -t nexus.doodle.com:5000/devops/k8skafka-controller:${env.TAG_NAME}" - sh "docker push nexus.doodle.com:5000/devops/k8skafka-controller:${env.TAG_NAME}" + container(name: 'kaniko', shell: '/busybox/sh') { + sh "cp /root/dockerauth/.dockerconfigjson /kaniko/.docker/config.json" + sh "/kaniko/executor -f `pwd`/Dockerfile -c `pwd` --destination='nexus.doodle.com:5000/devops/k8skafka-controller:${env.TAG_NAME}'" } container('helm') { @@ -69,7 +66,6 @@ podTemplate(label: 'k8skafka-controller', sh "mkdir chart/k8skafka-controller/crds" sh "cp config/crd/bases/* chart/k8skafka-controller/crds" sh "helm package chart/k8skafka-controller" - } container('golang') { @@ -86,28 +82,6 @@ podTemplate(label: 'k8skafka-controller', } } -void dockerAuth() { - // nexus repository - withCredentials([[ - $class : 'UsernamePasswordMultiBinding', - credentialsId : 'nexus', - usernameVariable: 'NEXUS_USER', - passwordVariable: 'NEXUS_PASSWORD' - ]]) { - sh "docker login nexus.doodle.com:5000 -u ${env.NEXUS_USER} -p ${env.NEXUS_PASSWORD}" - } - - // docker hub - withCredentials([[ - $class : 'UsernamePasswordMultiBinding', - credentialsId : 'dockerhub', - usernameVariable: 'DOCKERHUB_USER', - passwordVariable: 'DOCKERHUB_PASSWORD' - ]]) { - sh "docker login -u ${env.DOCKERHUB_USER} -p ${env.DOCKERHUB_PASSWORD}" - } -} - def bumpImageVersion(String version) { echo "Update image tag" def valuesFile = "./chart/k8skafka-controller/values.yaml"