Continuous Deployment on Jenkins and Docker

Miguel Ángel García Martínez

What are we going to see?

  • Jenkins
  • Docker
  • Docker-Compose
  • Continuous Integration
  • Continuous Deployment

Why?

Individuals and interactions over processes and tools

How are we going to do that?

  • Running a Jenkins server
  • Configuring a little project
  • Testing and deploying when it changes

How are we going to do that, exactly?

  • Run Jenkins server
  • Run Jenkins server on Docker
  • Configure the job te be launched
  • Run jenkins-swarm slave
  • Run jenkins-swarm slave on Docker
  • Create a docker-compose with both
  • Add master branch continuous integration

All of this in 5 minutes

Installing Jenkins:


 wget http://mirrors.jenkins-ci.org/war/latest/jenkins.war
 java -jar jenkins.war
            
            

Requirements:

Yes, it requires java

Jenkins landing page

Installing Jenkins, Docker mode:


 docker run -p 8080:8080 -p 50000:50000 jenkins
            
            

Docker glossary:

  • Image: like a class
  • Container: like an object
  • Volume: a mount point

Docker in a nutshell:

  • docker images Shows all downloaded images
  • docker ps Shows all running containers
  • docker ps -a Shows all created containers
  • docker run <image>
    download the image if necessary, create a container and run it.
  • docker exec -ti <container> <command>
    Executes the command on container

Configuring a job in jenkins:

Drawbacks:

  • How to prevent installing python, ruby, java, etc. in the same host?
  • How to prevent installing two different versions of python, ruby, java, etc. in the same host?
  • How to prevent installing two different versions of a library?
  • How to migrate the current infrastructure to production?
  • Get rid of packaging systems, like deb, rpm, ...

Our own image (reduced)


FROM java:8-jdk
RUN apt-get update \
    && apt-get install -y \
               git \
               wget \
               python3 \
               python3-pip
RUN apt-get clean
RUN wget http://[...]/swarm-client-2.0-jar-with-dependencies.jar

COPY jenkins-slave.sh /usr/local/bin/jenkins-slave.sh

VOLUME /home/jenkins-slave

ENTRYPOINT ["/usr/local/bin/jenkins-slave.sh"]
            
            

Docker-compose

  • Allows us to create a default docker configuration
  • Allows us to create a network of dockers
  • And all of this in a simple YAML file

Docker-compose


version: '2'
services:
  master:
    image: jenkins:2.7.1
    ports:
      - 8080:8080
    volumes:
      - ./data/master:/var/jenkins_home

  slave:
    build: slave
    command: -master http://master:8080 -executors 1
      -labels python -name builder
      -username swarm -password swarm
    links:
      - master

            
            

What does we have?

What does we want?

Drawbacks

  • Database preloaded data
  • Third party services (RabbitMQ, ...)
  • New development requirements
  • Security issues