davidcurrie / codeone2018

Jenkins/Kube/Helm demo for Code One 2018
https://oracle.rainfocus.com/widget/oracle/oow18/catalogcodeone18?search=DEV5364
1 stars 1 forks source link

Issues with the script on AWS cluster #1

Open hitesh1907nayyar opened 6 years ago

hitesh1907nayyar commented 6 years ago

Hi David,

I was trying to implement your script in aws eks cluster using kaniko. Can you please let me know what changes needs to be done for below lines of code for aws eks if I want to use Docker Hub


 stage ('Docker') {

        container ('kaniko') {

            def registryIp = sh(script: 'getent hosts registry.kube-system | awk \'{ print $1 ; exit }\'', returnStdout: true).trim()

            repository = "${registryIp}:80/hello"

            sh "executor -f `pwd`/Dockerfile -c `pwd` -d ${repository}:${commitId} --skip-tls-verify --insecure"

        }

davidcurrie commented 6 years ago

So, I haven't tried this but you should be able to drop the registryIp part, repository should just be your Docker Hub repository, and then the tricky bit is providing your credentials. Carlos has an example of mounting them in via a volume here: https://github.com/jenkinsci/kubernetes-plugin/blob/master/examples/kaniko.groovy

hitesh1907nayyar commented 6 years ago

Hi David, Can you please explain the meaning of this line ? What does pwd mean over here ?

sh "executor -f pwd/Dockerfile -c pwd -d ${repository}:${commitId} --skip-tls-verify --insecure"

davidcurrie commented 6 years ago

It's executing pwd to find the name of the current working directory. I guess backticks are old-hat. In modern bash it would read:

sh "executor -f $(pwd)/Dockerfile -c $(pwd) -d ${repository}:${commitId} --skip-tls-verify --insecure"
hitesh1907nayyar commented 6 years ago

Hi David,

I modified the script as below. I am getting below error:

2018/11/21 10:14:38 Unable to read "/home/jenkins/.docker/config.json": open /home/jenkins/.docker/config.json: no such file or directory error pushing image: failed to push to destination index.docker.io/****/kaniko:3: unsupported status code 401; body:

Can you please help over here ?

def label = "codeone-${UUID.randomUUID().toString()}" podTemplate( name: 'codeone', label: label, inheritFrom: 'default', containers: [ containerTemplate( name: 'golang', image: 'golang:1.11-alpine', ttyEnabled: true, command: 'cat' ), containerTemplate( name: 'kaniko', image: 'dcurrie/kaniko:alpine', ttyEnabled: true, command: 'cat' ), containerTemplate( name: 'helm', image: 'lachlanevenson/k8s-helm:v2.11.0', ttyEnabled: true, command: 'cat' ) ] ) { node(label) { def commitId stage ('Extract') { commitId = checkout(scm).GIT_COMMIT.take(8) } stage ('Build') { container ('golang') { sh 'CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o main .' } } def repository stage ('Docker') { container ('kaniko') { withCredentials([[$class: 'UsernamePasswordMultiBinding', credentialsId: '123456', usernameVariable: 'DOCKER_HUB_USER', passwordVariable: 'DOCKER_HUB_PASSWORD']]){ sh "executor -f pwd/Dockerfile -c pwd -d ${env.DOCKER_HUB_USER}/kaniko:${env.BUILD_NUMBER} --skip-tls-verify --insecure" } } } stage ('Deploy') { container ('helm') { sh """helm init --client-only --skip-refresh helm upgrade --install --wait --set image.repository=${repository},image.tag=${commitId} hello hello""" } } } }

davidcurrie commented 6 years ago

Here's my modified Jenkinsfile to push the image to Docker Hub: https://github.com/davidcurrie/codeone2018/blob/dockerhub/Jenkinsfile

Where I've set up my credentials with:

kubectl create secret docker-registry regcred --docker-server=index.docker.io --docker-username=dcurrie --docker-password=xxxxx --docker-email=yyyy