Containerized Jenkins master and agents

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Containerized Jenkins master and agents

Daniele Riccucci
Hello,
I recently switched to running Jenkins from host machine to a docker
container (https://hub.docker.com/r/jenkins/jenkins).
I was also using docker agents to build. This is now broken in my
current setup as I'm spinning up a slave container to run pipelines and
issues arise in a situation such as:

pipeline {
     agent { label 'jnlp-agent-docker' }
     // this is the major change as before it was not a container,
     // the label refers to a template with a similar version of
     // https://github.com/jenkinsci/jnlp-agents/ > docker
     stages {
         stage('Build') {
             agent {
                 docker { // could also be dockerfile
                     image "<myimage>"
                 }
             }
             steps {
                 git 'myrepo'
                 sh "build"
                 archiveArtifacts artifacts: 'dist/**/*'
             }
         }
     }
}

The docker plugin (this one >
http://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin) is obviously
unable to mount workspaces in another container and builds fail.
I would like to avoid adding a new template for this and using docker in
docker
(https://support.cloudbees.com/hc/en-us/articles/360001566111-Set-up-a-Docker-in-Docker-Agent-Template)
if possible
(https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/),
but I'll adapt to whatever works.

Is there a correct way to build using containers for jenkins, and the
slaves?

Thank you.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9fb2d785-1b74-c0d4-dd05-4b072e8efe59%40posteo.net.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Containerized Jenkins master and agents

nicolas de loof-2
Hi.

Why do you use some "jnlp-agent-docker" agent as you then switch to another one, based on a docker image ? Why not just use the later for the whole build ?

Le lun. 18 mars 2019 à 07:20, Daniele Riccucci <[hidden email]> a écrit :
Hello,
I recently switched to running Jenkins from host machine to a docker
container (https://hub.docker.com/r/jenkins/jenkins).
I was also using docker agents to build. This is now broken in my
current setup as I'm spinning up a slave container to run pipelines and
issues arise in a situation such as:

pipeline {
     agent { label 'jnlp-agent-docker' }
     // this is the major change as before it was not a container,
     // the label refers to a template with a similar version of
     // https://github.com/jenkinsci/jnlp-agents/ > docker
     stages {
         stage('Build') {
             agent {
                 docker { // could also be dockerfile
                     image "<myimage>"
                 }
             }
             steps {
                 git 'myrepo'
                 sh "build"
                 archiveArtifacts artifacts: 'dist/**/*'
             }
         }
     }
}

The docker plugin (this one >
http://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin) is obviously
unable to mount workspaces in another container and builds fail.
I would like to avoid adding a new template for this and using docker in
docker
(https://support.cloudbees.com/hc/en-us/articles/360001566111-Set-up-a-Docker-in-Docker-Agent-Template)
if possible
(https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/),
but I'll adapt to whatever works.

Is there a correct way to build using containers for jenkins, and the
slaves?

Thank you.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/9fb2d785-1b74-c0d4-dd05-4b072e8efe59%40posteo.net.
For more options, visit https://groups.google.com/d/optout.


--
Nicolas De Loof

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/CANMVJzmAcGFLmMmHd_TOpYHgZ%2Bw4fz%2BinQS3wEfeSrG-fNGDsg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Containerized Jenkins master and agents

Daniele Riccucci
Hello,

thank you for the reply. I did try, however there are a few reasons why
that didn't work for me:

* the jnlp-agent-docker, being based on openjdk at its root, doesn't
have several build tools more readily available on other images

* the agent specifically has the jnlp-slave built-in which eases
communication, most images would require `docker attach`

* the official jenkins/jenkins image doesn't seem to be natively able to
run docker containers, for example the following pipeline:

pipeline {
     agent {
         docker {
             image "golang:1.12-alpine"
         }
     }
     stages {
         stage('Build') {
             steps {
                 git '<myrepo'
                 sh "go get ./..."
                 sh "go build ."
             }
         }
     }
}

fails when it tries to execute the `docker login` command as it's not
present.
This forced me to use the jnlp-agent which *does* have the docker
command and mounts the /run/docker.sock from the host (or connects via TLS)

* such a workaround however does not support launching a second
container and would require a different, customized image for every
pipeline as a "Docker Agent template" configured in Jenkins, which is
very cumbersome

It is very possible I'm missing something or misconfigured my Jenkins
master but this is what I'm experiencing.

Regards,
Daniele

On 18/03/19 08:43, nicolas de loof wrote:

> Hi.
>
> Why do you use some "jnlp-agent-docker" agent as you then switch to
> another one, based on a docker image ? Why not just use the later for
> the whole build ?
>
> Le lun. 18 mars 2019 à 07:20, Daniele Riccucci <[hidden email]
> <mailto:[hidden email]>> a écrit :
>
>     Hello,
>     I recently switched to running Jenkins from host machine to a docker
>     container (https://hub.docker.com/r/jenkins/jenkins).
>     I was also using docker agents to build. This is now broken in my
>     current setup as I'm spinning up a slave container to run pipelines and
>     issues arise in a situation such as:
>
>     pipeline {
>           agent { label 'jnlp-agent-docker' }
>           // this is the major change as before it was not a container,
>           // the label refers to a template with a similar version of
>           // https://github.com/jenkinsci/jnlp-agents/ > docker
>           stages {
>               stage('Build') {
>                   agent {
>                       docker { // could also be dockerfile
>                           image "<myimage>"
>                       }
>                   }
>                   steps {
>                       git 'myrepo'
>                       sh "build"
>                       archiveArtifacts artifacts: 'dist/**/*'
>                   }
>               }
>           }
>     }
>
>     The docker plugin (this one >
>     http://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin) is obviously
>     unable to mount workspaces in another container and builds fail.
>     I would like to avoid adding a new template for this and using
>     docker in
>     docker
>     (https://support.cloudbees.com/hc/en-us/articles/360001566111-Set-up-a-Docker-in-Docker-Agent-Template)
>
>     if possible
>     (https://jpetazzo.github.io/2015/09/03/do-not-use-docker-in-docker-for-ci/),
>
>     but I'll adapt to whatever works.
>
>     Is there a correct way to build using containers for jenkins, and the
>     slaves?
>
>     Thank you.
>
>     --
>     You received this message because you are subscribed to the Google
>     Groups "Jenkins Users" group.
>     To unsubscribe from this group and stop receiving emails from it,
>     send an email to [hidden email]
>     <mailto:jenkinsci-users%[hidden email]>.
>     To view this discussion on the web visit
>     https://groups.google.com/d/msgid/jenkinsci-users/9fb2d785-1b74-c0d4-dd05-4b072e8efe59%40posteo.net.
>     For more options, visit https://groups.google.com/d/optout.
>
>
>
> --
> Nicolas De Loof
>
> --
> You received this message because you are subscribed to the Google
> Groups "Jenkins Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [hidden email]
> <mailto:[hidden email]>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jenkinsci-users/CANMVJzmAcGFLmMmHd_TOpYHgZ%2Bw4fz%2BinQS3wEfeSrG-fNGDsg%40mail.gmail.com 
> <https://groups.google.com/d/msgid/jenkinsci-users/CANMVJzmAcGFLmMmHd_TOpYHgZ%2Bw4fz%2BinQS3wEfeSrG-fNGDsg%40mail.gmail.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Jenkins Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To view this discussion on the web visit https://groups.google.com/d/msgid/jenkinsci-users/1b996b5e-ba29-5c56-e9cf-d281d833b10f%40posteo.net.
For more options, visit https://groups.google.com/d/optout.