Welcome to our Presentation about

Contents

  1. Docker
  2. Jenkins
  3. Interconnection

Contents

  1. The IT Landscape is changing....
    1. Container Concept
    2. Why are we using this Concept?
  2. Docker
    1. What is Docker?
    2. History of Docker
    3. Docker Architecture
    4. Example of a Docker Workflow
    5. Live Demo
    6. Docker Compose and Swarm

Change of the IT Landscape

The Container Concept

Important Terms

Layer

Part of an Image

Could be Files or Command

Image

Image of a "Container"

Consists of multiple Layers

Container

Instanced version of an Image

Many Containers can run the same Image

Dockerfile


                        # Use the official image as a parent image.
                        FROM node:current-slim
                        # Set the working directory.
                        WORKDIR /usr/src/app
                        # Copy the file from your host to your current location.
                        COPY package.json .
                        # Run the command inside your image filesystem.
                        RUN npm install
                        # Add metadata to the image to describe which port the container is listening on at runtime.
                        EXPOSE 8080
                        # Run the specified command within the container.
                        CMD [ "npm", "start" ]
                        # Copy the rest of your app's source code from your host to your image filesystem.
                        COPY . .
                    

Registry

Service to administrate Images

Biggest One : Docker Hub

Volume

Mostly folder(s) on the Host System

Volumes are "mounted" into a Container

Network

Connection to the "outer" World could be Local or on the Internet

The Container uses the Host's Connection and Adapter

Node

VM or physical Machine, which is a member of a Network

Positive Aspects of Containers

Easy Deployment on nearly every system-type
Lightweight
CI/CD compatible (👀 E-Portfolio Jenkins)
Scalable
  • Horizontal
  • Vertical

So what is Docker ?

The History of Docker

If no timeline is shown, press down!!

Docker Architecture

Docker Workflow with DockerHub

Dockerfile Example


                    # Filename: Dockerfile.build
                    FROM node:10-alpine
                    WORKDIR /usr/src/app
                    COPY package*.json ./
                    RUN npm install
                    COPY . .
                    EXPOSE 3000
                
  • Adding the Base Image
  • Setting Work Directory
  • Copy Files (package*.json) into the Container
  • Install Dependencies ("npm install")
  • Copy Content
  • Port Opening

Docker Compose

  • Defining and running multi-container Docker applications
  • use a YAML file to configure your applications Service
  • create and start all the services from your configuration
    1. Define your app’s environment with a Dockerfile so it can be reproduced anywhere.
    2. Define the services that make up your app in docker-compose.yml so they can be run together in an isolated environment.
    3. Run docker-compose up and Compose starts and runs your entire app.

For Completion : Docker Swarm

Outlooks

Where can you integrate Docker into your Project ?

  • Database Server
  • Node.js Server
  • Your Webapp, e.g. Angular, React
  • CI/CD Pipeline : Jenkins ?

Example of Angular Express and MongoDB in Docker Compose


  1. Container 1 – Angular
  2. Container 2 – NodeJS and ExpressJS
  3. Container 3 – MongoDB

Container 1 – Angular


                    FROM node:6
                    RUN mkdir -p /usr/src/app
                    WORKDIR /usr/src/app
                    COPY package.json /usr/src/app
                    RUN npm cache clean
                    RUN npm install
                    COPY . /usr/src/app
                    EXPOSE 4200
                    CMD ["npm","start"]
                

Container 2 – NodeJS and ExpressJS


                    FROM node:6
                    RUN mkdir -p /usr/src/app
                    WORKDIR /usr/src/app
                    COPY package.json /usr/src/app
                    RUN npm cache clean
                    RUN npm install
                    COPY . /usr/src/app
                    EXPOSE 3000
                    CMD ["npm","start"]
                

Container 3 – MongoDB

  • For the DB Part we have no need to Change the Image so we pull the Default one....

Docker Compose File


                    # Define the services/ containers to be run
                    services:
                    #######################
                     angular:
                      build: angular-app
                      ports:
                      - "4200:4200"
                    #######################
                     express:
                      build: express-server
                      ports:
                      - "3000:3000"
                      links:
                      - database
                    #######################
                     database:
                      image: mongo
                      ports:
                      - "27017:27017"
                

Jenkins

Jenkins Logo
  • What is Jenkins?
  • A brief history of Jenkins
  • What do I need a build server and CI/CD for?
  • What is Jenkins capable of doing?
  • Why do I need a build server when there is GitHub actions?
  • How to install Jenkins
  • How to create a project in Jenkins
  • How to integrate Jenkins with GitHub
  • How to use Jenkins in your own project
  • Live Demo of Jenkins at Betterzon

What is Jenkins?

what is Jenkins

History of Jenkins

  • Released February 2005 as "Hudson"
  • Renamed to Jenkins in 2011 after a dispute with Oracle
  • Both projects co-existed with Oracle claiming that Jenkins was the fork
  • Jenkins finally replaced Hudson in 2017

InfoWorld Article on Hudson Dispute

What do I need a build server and CI/CD for?

What is Jenkins capable of doing?

Why do I need a build server when there is GitHub actions?

  • Self-hosted
  • More customizable

How to install Jenkins

... standalone


                    wget -q -O - https://pkg.jenkins.io/debian-stable/jenkins.io.key | sudo apt-key add -
                    sudo sh -c 'echo deb https://pkg.jenkins.io/debian-stable binary/ > \
                        /etc/apt/sources.list.d/jenkins.list'
                    sudo apt-get update
                    sudo apt-get install jenkins
                    sudo systemctl start jenkins
                

... via Docker


                    docker run -p 8080:8080 -p 50000:50000 jenkins/jenkins:lts
                    docker run -p 8080:8080 -p 50000:50000 -v jenkins_home:/var/jenkins_home jenkins/jenkins:lts
                

... if that was a bit too easy for you


                    docker network create jenkins
                    docker image pull docker:dind
                    docker run \
                        --name jenkins-docker \
                        --privileged \
                        --network jenkins
                        --network-alias docker \
                        --env DOCKER_TLS_CERTDIR=/certs \
                        --volume jenkins-docker-certs:/certs/client \
                        --volume jenkins-data:/var/jenkins_home \
                        --publish 2376:2376 \
                        docker:dind
                

                    FROM jenkins/jenkins:2.249.3-slim
                    USER root
                    RUN apt-get update && apt-get install -y apt-transport-https \
                           ca-certificates curl gnupg2 \
                           software-properties-common
                    RUN curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add -
                    RUN apt-key fingerprint 0EBFCD88
                    RUN add-apt-repository \
                           "deb [arch=amd64] https://download.docker.com/linux/debian \
                           $(lsb_release -cs) stable"
                    RUN apt-get update && apt-get install -y docker-ce-cli
                    USER jenkins
                    RUN jenkins-plugin-cli --plugins blueocean:1.24.3
                

                    docker build -t my-docker-jenkins-image .
                    docker run my-docker-jenkins-image
                

... or for those who use Windows

https://www.jenkins.io/doc/book/installing/

How to create a project in Jenkins

How to integrate Jenkins with GitHub

GitHub and Jenkins Integration

How to use Jenkins in your own project

  • Running unit tests
  • Building the project
  • Running continuous tests, e.g. before a pull request can be accepted

Demo of Jenkins use in our project


                    export REPO_NAME='Mueller-Patrick/Betterzon'
                    export JOB_NAME='Verify_Build_on_PR'

                    curl "https://api.GitHub.com/repos/$REPO_NAME/statuses/$GIT_COMMIT" \
                    -H "Content-Type: application/json" \
                    -H "Authorization: token $GH_TOKEN" \
                    -X POST \
                    -d "{
                        \"state\": \"pending\",
                        \"context\": \"jenkins/$REPO_NAME\",
                        \"description\": \"Jenkins\",
                        \"target_url\": \"https://ci.betterzon.xyz/job/$JOB_NAME/$BUILD_NUMBER/console\"
                    }"
                

                    export REPO_NAME='Mueller-Patrick/Betterzon'
                    export JOB_NAME='Verify_Build_on_PR'
                    TEST_ERROR=0

                    cd Frontend
                    ng build || TEST_ERROR=$?
                    cd ..

                    if [ $TEST_ERROR -eq 0 ] ; then
                        curl "https://api.GitHub.com/repos/$REPO_NAME/statuses/$GIT_COMMIT" \
                        -H "Content-Type: application/json" \
                        -H "Authorization: token $GH_TOKEN" \
                        -X POST \
                        -d "{
                            \"state\": \"success\",
                            \"context\": \"jenkins/$REPO_NAME\",
                            \"description\": \"Jenkins\",
                            \"target_url\": \"https://ci.betterzon.xyz/job/$JOB_NAME/$BUILD_NUMBER/console\"
                        }"
                    else
                        curl "https://api.GitHub.com/repos/$REPO_NAME/statuses/$GIT_COMMIT" \
                        -H "Content-Type: application/json" \
                        -H "Authorization: token $GH_TOKEN" \
                        -X POST \
                        -d "{
                            \"state\": \"failure\",
                            \"context\": \"jenkins/$REPO_NAME\",
                            \"description\": \"Jenkins\",
                            \"target_url\": \"https://ci.betterzon.xyz/job/$JOB_NAME/$BUILD_NUMBER/console\"
                        }"

                        exit $TEST_ERROR
                    fi
                

Interconnection

Setting up a Jenkins Instance into a Docker Container

The Master - Docker File


                    FROM jenkins/jenkins:latest

                    RUN /usr/local/bin/install-plugins.sh git matrix-auth workflow-aggregator docker-workflow blueocean credentials-binding

                    ENV JENKINS_USER admin
                    ENV JENKINS_PASS admin

                    ENV JAVA_OPTS -Djenkins.install.runSetupWizard=false

                    COPY executors.groovy /usr/share/jenkins/ref/init.groovy.d/
                    COPY default-user.groovy /usr/share/jenkins/ref/init.groovy.d/

                    VOLUME /var/jenkins_home
                

The Slave - Docker File


                    FROM ubuntu:16.04
                    # Install Docker CLI in the agent
                    RUN apt-get update && apt-get install -y apt-transport-https ca-certificates
                    RUN apt-key adv --keyserver hkp://p80.pool.sks-keyservers.net:80 --recv-keys 58118E89F3A912897C070ADBF76221572C52609D
                    RUN echo "deb [arch=amd64] https://download.docker.com/linux/ubuntu xenial stable" > /etc/apt/sources.list.d/docker.list
                    RUN apt-get update && apt-get install -y docker-ce --allow-unauthenticated
                    RUN apt-get update && apt-get install -y openjdk-8-jre curl python python-pip git
                    RUN easy_install jenkins-webapi
                    # Get docker-compose in the agent container
                    .
                    .
                    .
                    .
                

The Compose File


                    version: '3.1'
                    services:
                        jenkins:
                            build: jenkins-master
                            container_name: jenkins
                            ports:
                                - '8080:8080'
                                - '50000:50000'
                        jenkins-slave:
                            build: jenkins-slave
                            container_name: jenkins-slave
                            restart: always
                            environment:
                                - 'JENKINS_URL=http://jenkins:8080'
                            volumes:
                                - /var/run/docker.sock:/var/run/docker.sock  # Expose the docker daemon in the container
                                - /home/jenkins:/home/jenkins # Avoid mysql volume mount issue
                            depends_on:
                                - jenkins
                

Using Docker IN Jenkins

Hope you enjoyed
our e-Portfolio ❤️


Let's start your 🐳 & Jenkins Adventure
with our Examples on Github


Also feel free to look in our Presentation - Sourcecode and reveal.js