Open hitesh1907nayyar opened 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
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"
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"
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"""
}
}
}
}
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
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