From 4ed32cf67c09392ad0f51b83ca9461c2a111e164 Mon Sep 17 00:00:00 2001 From: Jonathan Chauncey Date: Tue, 2 Jan 2018 15:19:55 -0500 Subject: [PATCH 1/2] Add jenkins/Jenkinsfile.azure.kubernetes which is used to build the hyperkube image and upload it into acr. --- jenkins/Jenkinsfile.azure.kubernetes | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 jenkins/Jenkinsfile.azure.kubernetes diff --git a/jenkins/Jenkinsfile.azure.kubernetes b/jenkins/Jenkinsfile.azure.kubernetes new file mode 100644 index 0000000000..408a503a61 --- /dev/null +++ b/jenkins/Jenkinsfile.azure.kubernetes @@ -0,0 +1,66 @@ +node(env.NODE? env.NODE : 'slave8') { + withCredentials([ + [$class: 'UsernamePasswordMultiBinding', credentialsId: "7a3620b2-9937-4a08-9551-ca3d0e84c503", usernameVariable: 'REGISTRY_USERNAME', passwordVariable: 'REGISTRY_PASSWORD'], + [$class: 'UsernamePasswordMultiBinding', credentialsId: '3b482378-9b9a-4784-b890-940b9bf0b234', usernameVariable: 'CLIENT_ID', passwordVariable: 'CLIENT_SECRET'], + [$class: 'StringBinding', credentialsId: "2b734a0f-fb1a-4c62-8022-f4804fbd5cc9", variable: "SUBSCRIPTION_ID"], + [$class: 'StringBinding', credentialsId: "94b2285f-1066-4fe2-9f6d-074649a50783", variable: "TENANT_ID"], + ]) { + timestamps { + wrap([$class: 'AnsiColorBuildWrapper', 'colorMapName': 'XTerm']) { + + stage('Prepare') { + deleteDir() + checkout scm + } + + img = docker.image("quay.io/deis/go-dev:${GO_DEV_TAG}") + img.inside("-u root -v /var/run/docker.sock:/var/run/docker.sock") { + env.CLIENT_ID = "${CLIENT_ID}" + env.CLIENT_SECRET = "${CLIENT_SECRET}" + env.TENANT_ID = "${TENANT_ID}" + env.SUBSCRIPTION_ID = "${SUBSCRIPTION_ID}" + + env.BUILD_FROM = "${BUILD_FROM}" + env.REGISTRY_USERNAME = "${REGISTRY_USERNAME}" + env.REGISTRY_PASSWORD = "${REGISTRY_PASSWORD}" + env.BUILD_NUMBER = "${BUILD_NUMBER}" + env.TAG = "${TAG}" + + stage('Login to azure') { + sh("az login --username ${CLIENT_ID} --password ${CLIENT_SECRET} --tenant ${TENANT_ID} --service-principal") + sh("az account show") + tag_count = sh(returnStdout: true, script: "az acr repository show-tags --username ${REGISTRY_USERNAME} --password ${REGISTRY_PASSWORD} --name ${REGISTRY_USERNAME} --repository hyperkube | jq '.[] | match(\"${BUILD_FROM}.azure.*\") | .string' | wc -l").toString().trim() + } + + if ("${TAG}" != "") { + tag = "${TAG}" + } else { + tag = "${BUILD_FROM}.azure.${tag_count}" + } + + stage('Clone azure/kubernetes and checkout') { + sh("git clone https://github.com/${BUILD_REPO} /go/src/github.com/kubernetes/kubernetes") + sh("cd /go/src/github.com/kubernetes/kubernetes && git checkout ${BUILD_FROM}") + } + + stage('Build Binaries') { + sh("cd /go/src/github.com/kubernetes/kubernetes && build/run.sh make cross KUBE_FASTBUILD=true ARCH=amd64") + } + + stage('Build Image') { + sh("cd /go/src/github.com/kubernetes/kubernetes/cluster/images/hyperkube && make VERSION=${tag}") + } + + stage('Tag and Publish Image') { + sh("docker login -u ${REGISTRY_USERNAME} -p ${REGISTRY_PASSWORD} ${REGISTRY_USERNAME}.azurecr.io") + + // We retag the gcr image from hyperkube-amd64 to just hyperkube since we can use image tags for separate architectures + sh("cd /go/src/github.com/kubernetes/kubernetes && docker tag gcr.io/google-containers/hyperkube-amd64:${tag} ${REGISTRY_USERNAME}.azurecr.io/hyperkube:${tag}") + sh("cd /go/src/github.com/kubernetes/kubernetes && docker push ${REGISTRY_USERNAME}.azurecr.io/hyperkube:${tag}") + } + } + } + } + + } +} \ No newline at end of file From 12d7fc5a8143866f34c3c6a21b003eb96960b68b Mon Sep 17 00:00:00 2001 From: Jonathan Chauncey Date: Mon, 8 Jan 2018 16:13:38 -0500 Subject: [PATCH 2/2] make sure this can run on all slaves not just slave8 --- jenkins/Jenkinsfile.azure.kubernetes | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/jenkins/Jenkinsfile.azure.kubernetes b/jenkins/Jenkinsfile.azure.kubernetes index 408a503a61..fec5eb9d83 100644 --- a/jenkins/Jenkinsfile.azure.kubernetes +++ b/jenkins/Jenkinsfile.azure.kubernetes @@ -1,4 +1,4 @@ -node(env.NODE? env.NODE : 'slave8') { +node(env.NODE? env.NODE : 'slave') { withCredentials([ [$class: 'UsernamePasswordMultiBinding', credentialsId: "7a3620b2-9937-4a08-9551-ca3d0e84c503", usernameVariable: 'REGISTRY_USERNAME', passwordVariable: 'REGISTRY_PASSWORD'], [$class: 'UsernamePasswordMultiBinding', credentialsId: '3b482378-9b9a-4784-b890-940b9bf0b234', usernameVariable: 'CLIENT_ID', passwordVariable: 'CLIENT_SECRET'],