Un jenkins amélioré avec docker mesos et marathon à Devoxx 2015

  • Published on
    15-Jul-2015

  • View
    351

  • Download
    2

Embed Size (px)

Transcript

  • @jlrigau#containerized_jenkins

    Un Jenkins amlior avec Docker, Mesos et Marathon

    Expert Continuous Delivery Coach DevOps

    @ Xebia IT Architects

    jlrigau@jlrigau

  • Objectifs

  • @jlrigau#containerized_jenkins

    Objectifs

    Simplifier la gestion de Jenkins en le conteneurisant avec Docker et en le dployant au sein dun cluster Mesos avec le framework Marathon

    Utiliser les ressources du cluster Mesos pour crer des slaves Jenkins la demande en sappuyant sur des conteneurs Docker

  • Outils

  • @jlrigau#containerized_jenkins

    Jenkins Serveur dintgration continue Projet open-source maintenu par CloudBees crit en Java

    An extensible open source continuous integration server

  • @jlrigau#containerized_jenkins

    Docker Gestionnaire de conteneurs Projet open-source maintenu par Docker Inc. crit en Go

    Build, Ship and Run Any App, Anywhere

  • @jlrigau#containerized_jenkins

    Mesos Gestionnaire de cluster Projet open-source maintenu par la Fondation Apache crit en C++

    Program against your datacenter like its a single pool of resources

  • @jlrigau#containerized_jenkins

    Marathon Framework Mesos Projet open-source maintenu par Mesosphere crit en Scala

    Deploy and manage containers on top of Apache Mesos at scale

  • Design

  • @jlrigau#containerized_jenkins

    Architecture

    MesosMaster

    MesosSlave

    MesosSlave

    Marathon

    Jenkins Scheduler

    Cluster Mesos

    quorum = 1

  • @jlrigau#containerized_jenkins

    Jenkins Master

    Marathon MesosMasterMesosSlave Docker

    JenkinsMaster

    Mesos Slave

  • @jlrigau#containerized_jenkins

    Jenkins Slaves

    JenkinsScheduler

    MesosMaster

    MesosSlave Docker

    JenkinsSlave

    Mesos Slave

  • @YourTwitterHandle@YourTwitterHandle@jlrigau#containerized_jenkins

    Demo - Jenkins Master

  • @jlrigau#containerized_jenkins

    FROM jenkins:weekly ADD init/*.groovy /usr/share/jenkins/init.groovy.d/ USER root RUN apt-get update && apt-get -y install libsvn1 ADD http://downloads.mesosphere.io/master/debian/7/mesos_0.21.1-1.0.debian77_amd64.deb

    /tmp/mesos.deb RUN dpkg -i /tmp/mesos.deb && rm /tmp/mesos.deb RUN mkdir -p /usr/share/jenkins/plugins && \ chown -R jenkins /usr/share/jenkins/plugins /usr/share/jenkins/init.groovy.d ADD plugins.awk plugins.csv /usr/share/jenkins/ RUN awk -f /usr/share/jenkins/plugins.awk /usr/share/jenkins/plugins.csv | sh ADD jenkins-init.sh /usr/local/bin/jenkins-init.sh VOLUME ["/var/jenkins_home"] ENTRYPOINT ["/usr/local/bin/jenkins-init.sh"]

    Jenkins Dockerfile

  • @jlrigau#containerized_jenkins

    FROM jenkins:weekly ADD init/*.groovy /usr/share/jenkins/init.groovy.d/ USER root RUN apt-get update && apt-get -y install libsvn1 ADD http://downloads.mesosphere.io/master/debian/7/mesos_0.21.1-1.0.debian77_amd64.deb

    /tmp/mesos.deb RUN dpkg -i /tmp/mesos.deb && rm /tmp/mesos.deb RUN mkdir -p /usr/share/jenkins/plugins && \ chown -R jenkins /usr/share/jenkins/plugins /usr/share/jenkins/init.groovy.d ADD plugins.awk plugins.csv /usr/share/jenkins/ RUN awk -f /usr/share/jenkins/plugins.awk /usr/share/jenkins/plugins.csv | sh ADD jenkins-init.sh /usr/local/bin/jenkins-init.sh VOLUME ["/var/jenkins_home"] ENTRYPOINT ["/usr/local/bin/jenkins-init.sh"]

    Jenkins Dockerfile

  • @jlrigau#containerized_jenkins

    import hudson.model.*; import jenkins.model.*; println "--> disabling master executors" Jenkins.instance.setNumExecutors(0)

    master-executors.groovy

  • @jlrigau#containerized_jenkins

    FROM jenkins:weekly ADD init/*.groovy /usr/share/jenkins/init.groovy.d/ USER root RUN apt-get update && apt-get -y install libsvn1 ADD http://downloads.mesosphere.io/master/debian/7/mesos_0.21.1-1.0.debian77_amd64.deb

    /tmp/mesos.deb RUN dpkg -i /tmp/mesos.deb && rm /tmp/mesos.deb RUN mkdir -p /usr/share/jenkins/plugins && \ chown -R jenkins /usr/share/jenkins/plugins /usr/share/jenkins/init.groovy.d ADD plugins.awk plugins.csv /usr/share/jenkins/ RUN awk -f /usr/share/jenkins/plugins.awk /usr/share/jenkins/plugins.csv | sh ADD jenkins-init.sh /usr/local/bin/jenkins-init.sh VOLUME ["/var/jenkins_home"] ENTRYPOINT ["/usr/local/bin/jenkins-init.sh"]

    Jenkins Dockerfile

  • @jlrigau#containerized_jenkins

    FROM jenkins:weekly ADD init/*.groovy /usr/share/jenkins/init.groovy.d/ USER root RUN apt-get update && apt-get -y install libsvn1 ADD http://downloads.mesosphere.io/master/debian/7/mesos_0.21.1-1.0.debian77_amd64.deb

    /tmp/mesos.deb RUN dpkg -i /tmp/mesos.deb && rm /tmp/mesos.deb RUN mkdir -p /usr/share/jenkins/plugins && \ chown -R jenkins /usr/share/jenkins/plugins /usr/share/jenkins/init.groovy.d ADD plugins.awk plugins.csv /usr/share/jenkins/ RUN awk -f /usr/share/jenkins/plugins.awk /usr/share/jenkins/plugins.csv | sh ADD jenkins-init.sh /usr/local/bin/jenkins-init.sh VOLUME ["/var/jenkins_home"] ENTRYPOINT ["/usr/local/bin/jenkins-init.sh"]

    Jenkins Dockerfile

  • @jlrigau#containerized_jenkins

    mesos,latest scm-api,0.2 git-client,1.11.0 git,2.2.7

    plugins.csv

  • @jlrigau#containerized_jenkins

    BEGIN { FS="," } { print "curl -sSL --create-dirs -o /usr/share/jenkins/plugins/" $1 ".hpi

    https://updates.jenkins-ci.org/" ($2 == "latest" ? "latest/" : "download/plugins/" $1 "/" $2 "/") $1 ".hpi"

    }

    plugins.awk

  • @jlrigau#containerized_jenkins

    mesos,latest scm-api,0.2 git-client,1.11.0 git,2.2.7

    plugins.csv

  • @jlrigau#containerized_jenkins

    FROM jenkins:weekly ADD init/*.groovy /usr/share/jenkins/init.groovy.d/ USER root RUN apt-get update && apt-get -y install libsvn1 ADD http://downloads.mesosphere.io/master/debian/7/mesos_0.21.1-1.0.debian77_amd64.deb

    /tmp/mesos.deb RUN dpkg -i /tmp/mesos.deb && rm /tmp/mesos.deb RUN mkdir -p /usr/share/jenkins/plugins && \ chown -R jenkins /usr/share/jenkins/plugins /usr/share/jenkins/init.groovy.d ADD plugins.awk plugins.csv /usr/share/jenkins/ RUN awk -f /usr/share/jenkins/plugins.awk /usr/share/jenkins/plugins.csv | sh ADD jenkins-init.sh /usr/local/bin/jenkins-init.sh VOLUME ["/var/jenkins_home"] ENTRYPOINT ["/usr/local/bin/jenkins-init.sh"]

    Jenkins Dockerfile

  • @jlrigau#containerized_jenkins

    Cluster Mesos

  • @jlrigau#containerized_jenkins

    Mesos Slaves

  • @jlrigau#containerized_jenkins

    Framework Mesos

  • @jlrigau#containerized_jenkins

    Marathon

  • @jlrigau#containerized_jenkins

    { "id": "jenkins", "container": { "type": "DOCKER", "docker": { "image": "jlrigau/jenkins", "network": "HOST" }, "volumes": [ { "containerPath": "/var/jenkins_home", "hostPath": "/var/data/jenkins", "mode": "RW" } ] }, "cpus": 0.2, "mem": 128.0, "instances": 1 }

    jenkins.json

  • @jlrigau#containerized_jenkins

    { "id": "jenkins", "container": { "type": "DOCKER", "docker": { "image": "jlrigau/jenkins", "network": "HOST" }, "volumes": [ { "containerPath": "/var/jenkins_home", "hostPath": "/var/data/jenkins", "mode": "RW" } ] }, "cpus": 0.2, "mem": 128.0, "instances": 1 }

    jenkins.json

  • @jlrigau#containerized_jenkins

    { "id": "jenkins", "container": { "type": "DOCKER", "docker": { "image": "jlrigau/jenkins", "network": "HOST" }, "volumes": [ { "containerPath": "/var/jenkins_home", "hostPath": "/var/data/jenkins", "mode": "RW" } ] }, "cpus": 0.2, "mem": 128.0, "instances": 1 }

    jenkins.json

  • @jlrigau#containerized_jenkins

    { "id": "jenkins", "container": { "type": "DOCKER", "docker": { "image": "jlrigau/jenkins", "network": "HOST" }, "volumes": [ { "containerPath": "/var/jenkins_home", "hostPath": "/var/data/jenkins", "mode": "RW" } ] }, "cpus": 0.2, "mem": 128.0, "instances": 1 }

    jenkins.json

  • @jlrigau#containerized_jenkins

    $curl -X POST -H "Content-Type: application/json http:// MARATHON_PUBLIC_HOST:8080/v2/apps -d@jenkins.json

    Dploiement de Jenkins

  • @jlrigau#containerized_jenkins

    Jenkins est lanc

  • @jlrigau#containerized_jenkins

    mais sur quel slave ?

  • @jlrigau#containerized_jenkins

    Tche active

  • @jlrigau#containerized_jenkins

    root@ip-172-31-14-112:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES d85414d1ad4f jlrigau/jenkins:latest "/usr/local/bin/jenk 11 minutes ago Up 11 minutes mesos-f1c49c55-8075-4865-b644-7d35465c8a96

    docker ps

  • @jlrigau#containerized_jenkins

    root@ip-172-31-14-112:~# docker logs $(docker ps -lq) Copying init scripts Copying plugins /usr/share/jenkins/ref/init.groovy.d/tcp-slave-angent-port.groovy /usr/share/jenkins/ref/init.groovy.d/tcp-slave-angent-port.groovy -> init.groovy.d/tcp-slave-angent-port.groovy copy init.groovy.d/tcp-slave-angent-port.groovy to JENKINS_HOME Running from: /usr/share/jenkins/jenkins.war webroot: EnvVars.masterEnvVars.get("JENKINS_HOME") Apr 07, 2015 11:33:28 PM winstone.Logger logInternal INFO: Beginning extraction from war file Apr 07, 2015 11:33:30 PM org.eclipse.jetty.util.log.JavaUtilLog info INFO: jetty-winstone-2.8 Apr 07, 2015 11:33:32 PM org.eclipse.jetty.util.log.JavaUtilLog info INFO: NO JSP Support for , did not find org.apache.jasper.servlet.JspServlet Jenkins home directory: /var/jenkins_home found at: EnvVars.masterEnvVars.get("JENKINS_HOME") Apr 07, 2015 11:33:32 PM org.eclipse.jetty.util.log.JavaUtilLog info INFO: Started SelectChannelConnector@0.0.0.0:8080 Apr 07, 2015 11:33:32 PM winstone.Logger logInternal INFO: Winstone Servlet Engine v2.0 running: controlPort=disabled Apr 07, 2015 11:33:33 PM jenkins.InitReactorRunner$1 onAttained INFO: Started initialization Apr 07, 2015 11:33:58 PM jenkins.InitReactorRunner$1 onAttained INFO: Listed all plugins Apr 07, 2015 11:33:58 PM jenkins.InitReactorRunner$1 onAttained INFO: Prepared all plugins Apr 07, 2015 11:33:58 PM jenkins.InitReactorRunner$1 onAttained INFO: Started all plugins Apr 07, 2015 11:33:59 PM jenkins.InitReactorRunner$1 onAttained INFO: Augmented all extensions Apr 07, 2015 11:34:02 PM jenkins.InitReactorRunner$1 onAttained INFO: Loaded all jobs Apr 07, 2015 11:34:02 PM jenkins.util.groovy.GroovyHookScript execute INFO: Executing /var/jenkins_home/init.groovy.d/master-executors.groovy Apr 07, 2015 11:34:02 PM org.jenkinsci.main.modules.sshd.SSHD start INFO: Started SSHD at port 60955 --> disabling master executors Apr 07, 2015 11:34:03 PM jenkins.util.groovy.GroovyHookScript execute INFO: Executing /var/jenkins_home/init.groovy.d/tcp-slave-angent-port.groovy Apr 07, 2015 11:34:03 PM jenkins.InitReactorRunner$1 onAttained INFO: Completed initialization Apr 07, 2015 11:34:03 PM hudson.WebAppMain$3 run INFO: Jenkins is fully up and running --> setting agent port for jnlp

    docker logs $(docker ps -lq)

  • @jlrigau#containerized_jenkins

    Jenkins is alive!

  • @jlrigau#containerized_jenkins

    # of executors

  • @jlrigau#containerized_jenkins

    Plugin Mesos

  • @YourTwitterHandle@YourTwitterHandle@jlrigau#containerized_jenkins

    Demo - Jenkins Slaves

  • @jlrigau#containerized_jenkins

    Jenkins Scheduler

  • @jlrigau#containerized_jenkins

    Framework Mesos

  • @jlrigau#containerized_jenkins

    Java Slave Info

  • @jlrigau#containerized_jenkins

    Projet Java

  • @jlrigau#containerized_jenkins

    java -version

  • @jlrigau#containerized_jenkins

    Build Success !

  • @jlrigau#containerized_jenkins

    Console Output

  • @jlrigau#containerized_jenkins

    Jenkins nodes

  • @jlrigau#containerized_jenkins

    Tche active

  • @jlrigau#containerized_jenkins

    root@ip-172-31-14-111:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES ee5455595cc5 java:7 "/bin/sh -c 'java -D 15 minutes ago Up 15 minutes mesos-d6692494-0d90-4782-a887-702f6a6cd3fa

    docker ps

  • @jlrigau#containerized_jenkins

    Configure Maven

  • @jlrigau#containerized_jenkins

    Maven/Git Slave Info

  • @jlrigau#containerized_jenkins

    Projet Maven

  • @jlrigau#containerized_jenkins

    Source Code Management

  • @jlrigau#containerized_jenkins

    Source Code Management

  • @jlrigau#containerized_jenkins

    Build Success !

  • @jlrigau#containerized_jenkins

    Git checkout

  • @jlrigau#containerized_jenkins

    BUILD SUCCESS

  • @jlrigau#containerized_jenkins

    Tches actives

  • @jlrigau#containerized_jenkins

    root@ip-172-31-14-112:~# docker ps CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES f5d271f37950 jlrigau/maven-git:latest "/bin/sh -c 'java -D 43 seconds ago Up 42 seconds mesos-ed390fd9-6abc-452a-a5f2-cf195151b9a6 78bd7391c980 java:7 "/bin/sh -c 'java -D 45 seconds ago Up 45 seconds mesos-85d716dd-c887-42ce-a4bd-8b1883f89a71 9ab7272b32da jlrigau/jenkins:latest "/usr/local/bin/jenk About an hour ago Up About an hour mesos-9082d0e2-3ff8-4133-9e1e-6959d9ebbfcb

    docker ps

  • @jlrigau#containerized_jenkins

    root@ip-172-31-14-112:~# docker exec -it f5d271f37950 /bin/bash root@ip-172-31-14-112:/# ls -l /jenkins/workspace/Projet\ Maven/ total 20 -rw-r--r-- 1 root root 2229 Apr 8 01:12 README.md drwxr-xr-x 3 root root 4096 Apr 8 01:12 jenkins -rw-r--r-- 1 root root 342 Apr 8 01:12 jenkins.json drwxr-xr-x 2 root root 4096 Apr 8 01:12 maven-git drwxr-xr-x 3 root root 4096 Apr 8 01:12 sample

    docker exec

  • @YourTwitterHandle@YourTwitterHandle@jlrigau#containerized_jenkins

    Summary

  • @jlrigau#containerized_jenkins

    Liens Sources du Tools in Action https://github.com/jlrigau/ci-mesos

    Sources de la configuration du cluster Mesos https://github.com/WeScale/mesosphere-walking-tutorial

    Sources dinspiration Delivering eBays CI Solution with Apache Mesos - Part I Delivering eBays CI Solution with Apache Mesos - Part II

  • @YourTwitterHandle@YourTwitterHandle@jlrigau#containerized_jenkins

    Q & A

Recommended

View more >