Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with the script on AWS cluster #1

Open
hitesh1907nayyar opened this issue Nov 20, 2018 · 5 comments
Open

Issues with the script on AWS cluster #1

hitesh1907nayyar opened this issue Nov 20, 2018 · 5 comments

Comments

@hitesh1907nayyar
Copy link

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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
Copy link
Author

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants