Dockerized Maven
Matthias Bertschy (http://matthiasbertschy.info)
Delivering like a Pro with Docker
5 October, 2016
who?
● working as a sysadmin since 2005
● CISSP and RHCE
● recently switched to DevOps
● day-to-day work with OpenShift and Docker
about this talk
how to leverage custom Docker containers to:
● handle build dependencies on local workstations
● provide clean Jenkins slaves
● run tests inside orchestrated deployments
● run tests inside OpenShift projects
build dependencies
pain
● every developer is different
○ workstation OS
○ development tools
● every team (microservice) is different
○ programming language
○ dependencies
● building quality software requires consistency
● keeping the same environment throughout the pipeline is
the key
let's use Docker...
Dockerfile
FROM docker.io/centos
ENV MAVEN_VERSION 3.3.3
RUN yum update -y && 
yum install -y java-1.8.0-openjdk-headless && 
tar xzf apache-maven-$MAVEN_VERSION-bin.tar.gz -C
/usr/local/ && 
mkdir -p /usr/local/apache-maven-$MAVEN_VERSION/.m2/ && 
yum clean all
COPY contrib/settings.xml
/usr/local/apache-maven-$MAVEN_VERSION/conf/
/home/mbertschy/java
#!/bin/bash
cmd="/usr/bin/java"
cwd=`pwd`
user=`id -u`
group=`id -g`
docker run -i --privileged --user=${user}:${group}
--volume=${cwd}:${cwd} --workdir=${cwd} --entrypoint ${cmd}
--rm <mvn_container> "${@}"
/home/mbertschy/mvn
#!/bin/bash
MAVEN_VERSION=3.3.3
cmd="/usr/local/apache-maven-${MAVEN_VERSION}/bin/mvn"
cwd=`pwd`
user=`id -u`
group=`id -g`
docker run -i --privileged --user=${user}:${group}
--volume=${cwd}:${cwd} --workdir=${cwd} --entrypoint ${cmd}
--rm <mvn_container> "${@}"
usage
[mbertschy@devops tmp]$ /home/mbertschy/mvn validate
[mbertschy@devops tmp]$ /home/mbertschy/mvn package
[mbertschy@devops tmp]$ /home/mbertschy/java -jar target/*.jar
. ____ _ __ _ _
/ / ___'_ __ _ _(_)_ __ __ _    
( ( )___ | '_ | '_| | '_ / _` |    
/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |___, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v1.2.5.RELEASE)
...
benefits
● build and test tools are centrally managed
● different versions of tools do not interfere
● workstation are configured in a breeze
● developers can focus on producing quality code
Jenkins slaves
Jenkins: master vs slave
MASTER
● light workload
● at least one per team
(separation of duties)
● numerous / on-demand
● better virtualized
SLAVE
● heavy workload
● the need for speed
● better using bare metal
● could be shared to reduce cost
pain
● slaves should be shared between teams for cost reasons
● every team (microservice) is different
○ programming language
○ dependencies
● maintaining and upgrading a slave farm is increasingly
difficult without uniformity
● building quality software requires consistency
● keeping the same environment throughout the pipeline is
the key
let's use Docker
(again)...
... there's a plugin for
that!
Docker Plugin
https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin
● Maintainers: Kanstantsin Shautsou, Nigel Magnay
● ~4000 installation per month, and growing
● use a docker host to dynamically provision a slave, run a
single build, then tear-down that slave
● optionally, the container can be committed, so that (for
example) manual QA could be performed by the
container being imported into a local docker provider
Dockerfile
...
RUN yum install -y openssh-server rsync && 
/usr/bin/ssh-keygen -A && 
echo "UseDNS no" >>/etc/ssh/sshd_config && 
echo "GSSAPIAuthentication no" >>/etc/ssh/sshd_config && 
echo "StrictModes no" >>/etc/ssh/sshd_config && 
rm -f /run/nologin && 
useradd -u 500 -g root -p '...' jenkins && 
mkdir /home/jenkins/workspace && 
chown jenkins:root /home/jenkins/workspace
EXPOSE 22
configuration
Prerequisite: you need a docker host with docker.service
listening on port 4243
● as a Jenkins administrator, go to Manage Jenkins
● then Configure System
● at the bottom of the page, you should find a button
proposing to Add a new cloud
Dockerized maven
Dockerized maven
Dockerized maven
usage
● in your Maven project configuration, you just have to
Restrict where this project can be run
● and enter the correct label to match your new slave:
● you can then hit Build Now
usage (2)
Started by upstream project
"S11N/products-md-service-api-build" build number 118
originally caused by:
Started by an SCM change
[EnvInject] - Loading node environment variables.
Building remotely on slave01-f7d02a1538bf (mvn-build) in
workspace
/home/jenkins/workspace/S11N/production-orders-service-build
[WS-CLEANUP] Deleting project workspace...
Cloning the remote Git repository
...
benefits
● slaves are clean at every build
● slaves are generic and can be reused for many build types
(mvn, npm, ...)
● we can use lightweight OS for slaves (atomic CentOS)
● easy maintenance
● consistency
Docker Compose
what?
● tool for defining and running multi-container Docker
applications
● great for development, testing, and staging environments
● we use it for component testing on workstations
● define the services in docker-compose.yml
● docker-compose up
docker-compose.yml
---
db:
image: postgresql-94-rhel7:latest
ports:
- "5432:5432"
environment:
POSTGRESQL_USER: myuser
POSTGRESQL_PASSWORD: ********
POSTGRESQL_DATABASE: mydb
docker-compose.yml (2)
...
product:
image: products-md-service:0.1.0-SNAPSHOT
ports:
- "18080:8080"
links:
- db
environment:
DB_URL: jdbc:postgresql://db:5432/mydb
DB_USER: myuser
DB_PASSWORD: ********
Docker
architecture
db
172.17.0.2
product
172.17.0.3
workstation
10.10.1.32
pain
● links defined in docker-compose.yml are only resolvable
from containers started by Compose
● testing and debugging should be performed as if the
developer was inside Docker space
● building quality software requires consistency
● keeping the same environment throughout the pipeline is
the key
let's use Docker
(again)...
principle
● links defined in docker-compose.yml are only resolvable
from containers started by Compose
● we already have our development environment packaged
inside a container
● let's insert our developer inside the Compose world!
● we have called this pattern "the avatar"
Docker
architecture
db
172.17.0.2
product
172.17.0.3
workstation
10.10.1.32
avatar
172.17.0.4
docker-compose.yml
...
avatar:
image: <mvn_container>
ports:
- "2222:22"
links:
- db
- product
command: [/sbin/sshd, -D]
usage
[mbertschy@devops tmp]$ docker-compose up -d
Creating tmp_db_1
Creating tmp_product_1
Creating tmp_avatar_1
[...]$ rsync -a -e "ssh -p 2222" ./ jenkins@127.0.0.1/
[mbertschy@devops tmp]$ ssh -l jenkins -p 2222 127.0.0.1
jenkins@127.0.0.1's password:
[jenkins@e250549ee18d ~]$ pwd
/home/jenkins
[jenkins@e250549ee18d ~]$ ping db
PING db (172.17.0.2) 56(84) bytes of data.
64 bytes from db (172.17.0.2): icmp_seq=1 ttl=64 time=0.106 ms
benefits
● tests rely on link definitions
● different versions of tools do not interfere
● workstation are configured in a breeze
● developers can focus on producing quality code
OpenShift
what?
Built on opensource projects:
● Docker provides the abstraction for packaging apps
● Kubernetes orchestrates Docker containers
OpenShift Enterprise adds:
● Source code management, builds, and deployments
● Image management and promotion
● Application management
● Team and user tracking for large developer organizations
Dockerized maven
component architecture
● database:
○ 1x PostgreSQL pod
○ 1x service (SQL)
● backend:
○ 1x SpringBoot pod
○ 2x service (REST, gRPC)
○ 1x route
● frontend
○ 1x NGINX pod (serving node.js application)
○ 1x service (HTTP)
○ 1x route
Dockerized maven
Dockerized maven
Dockerized maven
pain
● pods and services are only accessible from containers
started inside the same project
● routes can only publish HTTP (v1) based protocols
● tests have to access services directly (flyway scripts for
databases, message brokers, binary protocols, ...)
● building quality software requires consistency
● keeping the same environment throughout the pipeline is
the key
let's use Docker
(one last time)...
principle
● pods and services are only accessible from containers
started inside the same project (until 3.3...)
● we already have our development environment packaged
inside a container
● let's insert our developer inside the OpenShift project!
● this is a second use of our pattern called "the avatar"
Dockerfile
...
# fix permissions to run inside openshift
RUN chmod 0770 /home/jenkins && 
chmod 2770 /home/jenkins/workspace && 
chmod 2770 /usr/local/apache-maven-$MAVEN_VERSION/.m2/
ADD oc-3.2.0.20-linux.tar.gz /usr/local/bin/
# when running from jenkins, plugin starts /sbin/sshd -D
# this default sleep is for OpenShift to keep pod running
CMD ["sleep", "infinity"]
template.yml
apiVersion: v1
kind: DeploymentConfig
metadata:
name: mvn-avatar
spec:
replicas: 1
template:
spec:
containers:
image: <mvn_container>
imagePullPolicy: Always
name: mvn-avatar
Dockerized maven
usage
[mbertschy@devops tmp]$ oc get pods
NAME READY STATUS RESTARTS AGE
mvn-avatar-1-94snc 1/1 Running 0 6d
db-products-md-srv-1-13o5f 1/1 Running 0 6d
products-md-srv-1-lw3cb 1/1 Running 0 6d
products-md-web-1-g1fu8 1/1 Running 0 6d
[mbertschy@devops tmp]$ oc rsync ./ mvn-avatar-1-94snc:/
[mbertschy@devops tmp]$ oc rsh mvn-avatar-1-94snc
sh-4.2$ ping db-products-md-srv
PING db-products-md-srv.qa-products-md.svc.cluster.local
(172.30.46.79) 56(84) bytes of data.
^C
usage from Jenkins
[products-md-ctest] $ /bin/sh -xe /tmp/hudson84804829430149.sh
++ oc get pod -l app=mvn-avatar --no-headers
++ awk '{print $1}'
+ avatarPod=mvn-avatar-1-94snc
+ oc rsh mvn-avatar-1-94snc mkdir -p S11N/products-md-deploy
+ oc rsync --progress=true S11N/products-md-deploy/
mvn-avatar-1-94snc:S11N/products-md-deploy/
+ oc rsh mvn-avatar-1-94snc bash -c 'cd
S11N/products-md-deploy ; source *-conf.sh || true ; export ;
mvn verify'
...
usage from Jenkins (2)
...
+ mkdir -p S11N/products-md-ctest/cucumberOutput
+ oc rsync
mvn-avatar-1-94snc:S11N/products-md-deploy/cucumberOutput/
S11N/products-md-ctest/cucumberOutput --no-perms=true
receiving incremental file list
20161003133154.json
benefits
● tests are run from inside OpenShift projects
● native name resolution and load balancers are leveraged
● developers can jump inside projects for live debugging
● Jenkins integration is possible with minimal fuss
thanks

More Related Content

PDF
Tech Talk - Vagrant
PDF
JOSA TechTalk: Taking Docker to Production
PDF
JOSA TechTalk: Introduction to docker
PDF
Docker Continuous Delivery Workshop
PPTX
Настройка окружения для кросскомпиляции проектов на основе docker'a
PDF
Developer workflow with docker
PPTX
Introduction to docker and oci
PDF
Introduction to Docker Container
Tech Talk - Vagrant
JOSA TechTalk: Taking Docker to Production
JOSA TechTalk: Introduction to docker
Docker Continuous Delivery Workshop
Настройка окружения для кросскомпиляции проектов на основе docker'a
Developer workflow with docker
Introduction to docker and oci
Introduction to Docker Container

What's hot (20)

PDF
Docker From Scratch
PPTX
Docker Presentation
PDF
A Shift from Monolith to Microservice using Docker
PPTX
Learn docker in 90 minutes
PDF
Docker in real life
PDF
Using Docker to build and test in your laptop and Jenkins
PDF
Docker Introduction
PPTX
Docker - Ankara JUG, Nisan 2015
PDF
Docker Introduction
PDF
Docker and OpenStack Boston Meetup
PPTX
[Codelab 2017] Docker 기초 및 활용 방안
PDF
Docker dDessi november 2015
PPTX
Docker open stack boston
PDF
Rami Sayar - Node microservices with Docker
PDF
Introduction to Containers - SQL Server and Docker
PPTX
Containers #101 : Docker ONBUILD triggers and Introduction to Docker Compose
PPTX
Docker Basics
PDF
PPTX
Docker : Container Virtualization
PPTX
Docker container a-brief_introduction_2016-01-30
Docker From Scratch
Docker Presentation
A Shift from Monolith to Microservice using Docker
Learn docker in 90 minutes
Docker in real life
Using Docker to build and test in your laptop and Jenkins
Docker Introduction
Docker - Ankara JUG, Nisan 2015
Docker Introduction
Docker and OpenStack Boston Meetup
[Codelab 2017] Docker 기초 및 활용 방안
Docker dDessi november 2015
Docker open stack boston
Rami Sayar - Node microservices with Docker
Introduction to Containers - SQL Server and Docker
Containers #101 : Docker ONBUILD triggers and Introduction to Docker Compose
Docker Basics
Docker : Container Virtualization
Docker container a-brief_introduction_2016-01-30
Ad

Viewers also liked (14)

PPT
Jenkins on Docker
PDF
What is this "docker"
PDF
From Monolith to Docker Distributed Applications
PDF
Testing Distributed Micro Services. Agile Testing Days 2017
PPTX
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
PPTX
TDC2016SP - Testes unitários e testes de integração de aplicações Java utiliz...
PDF
Using Containers for Building and Testing: Docker, Kubernetes and Mesos. FOSD...
PDF
Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
PDF
Developing Java based microservices ready for the world of containers
PDF
Continuous Integration using Docker & Jenkins
PDF
Jenkins Docker
PDF
Using Docker for Testing
PDF
Docker for Java Developers
PPTX
Faster Java EE Builds with Gradle
Jenkins on Docker
What is this "docker"
From Monolith to Docker Distributed Applications
Testing Distributed Micro Services. Agile Testing Days 2017
Using Docker to Develop, Test and Run Maven Projects - Wouter Danes
TDC2016SP - Testes unitários e testes de integração de aplicações Java utiliz...
Using Containers for Building and Testing: Docker, Kubernetes and Mesos. FOSD...
Scaling Jenkins with Docker: Swarm, Kubernetes or Mesos?
Developing Java based microservices ready for the world of containers
Continuous Integration using Docker & Jenkins
Jenkins Docker
Using Docker for Testing
Docker for Java Developers
Faster Java EE Builds with Gradle
Ad

Similar to Dockerized maven (20)

PDF
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
PDF
From Monolith to Docker Distributed Applications. JavaOne
ODP
Scaling your jenkins master with docker
PDF
JUC Europe 2015: Scaling Your Jenkins Master with Docker
PDF
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
PDF
Docker 0.11 at MaxCDN meetup in Los Angeles
PPTX
Introduction to docker
PDF
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
PDF
Continuous Integration/Deployment with Docker and Jenkins
PDF
LXC to Docker Via Continuous Delivery
PDF
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
PDF
Docker+java
PDF
Docker-v3.pdf
PDF
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
PPTX
DevOps Best Practices with Openshift - DevOpsFusion 2020
PPTX
DevOps best practices with OpenShift
PDF
DCSF 19 Building Your Development Pipeline
PDF
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
PPTX
Docker Container As A Service - JAX 2016
CI/CD with Jenkins and Docker - DevOps Meetup Day Thailand
From Monolith to Docker Distributed Applications. JavaOne
Scaling your jenkins master with docker
JUC Europe 2015: Scaling Your Jenkins Master with Docker
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
Docker 0.11 at MaxCDN meetup in Los Angeles
Introduction to docker
The Docker "Gauntlet" - Introduction, Ecosystem, Deployment, Orchestration
Continuous Integration/Deployment with Docker and Jenkins
LXC to Docker Via Continuous Delivery
CI and CD at Scale: Scaling Jenkins with Docker and Apache Mesos
Docker+java
Docker-v3.pdf
Docker 1 0 1 0 1: a Docker introduction, actualized for the stable release of...
DevOps Best Practices with Openshift - DevOpsFusion 2020
DevOps best practices with OpenShift
DCSF 19 Building Your Development Pipeline
Introduction to Docker at SF Peninsula Software Development Meetup @Guidewire
Docker Container As A Service - JAX 2016

Recently uploaded (20)

PDF
A review of recent deep learning applications in wood surface defect identifi...
PPTX
Modernising the Digital Integration Hub
PDF
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
PDF
Getting Started with Data Integration: FME Form 101
PDF
Hybrid model detection and classification of lung cancer
PPTX
O2C Customer Invoices to Receipt V15A.pptx
PPTX
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
PDF
Developing a website for English-speaking practice to English as a foreign la...
PPTX
Web Crawler for Trend Tracking Gen Z Insights.pptx
PDF
Zenith AI: Advanced Artificial Intelligence
PDF
Taming the Chaos: How to Turn Unstructured Data into Decisions
PDF
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
DOCX
search engine optimization ppt fir known well about this
PPTX
Chapter 5: Probability Theory and Statistics
PDF
sustainability-14-14877-v2.pddhzftheheeeee
PDF
Hindi spoken digit analysis for native and non-native speakers
PDF
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
PDF
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
PPTX
The various Industrial Revolutions .pptx
PDF
Getting started with AI Agents and Multi-Agent Systems
A review of recent deep learning applications in wood surface defect identifi...
Modernising the Digital Integration Hub
Microsoft Solutions Partner Drive Digital Transformation with D365.pdf
Getting Started with Data Integration: FME Form 101
Hybrid model detection and classification of lung cancer
O2C Customer Invoices to Receipt V15A.pptx
MicrosoftCybserSecurityReferenceArchitecture-April-2025.pptx
Developing a website for English-speaking practice to English as a foreign la...
Web Crawler for Trend Tracking Gen Z Insights.pptx
Zenith AI: Advanced Artificial Intelligence
Taming the Chaos: How to Turn Unstructured Data into Decisions
Hybrid horned lizard optimization algorithm-aquila optimizer for DC motor
search engine optimization ppt fir known well about this
Chapter 5: Probability Theory and Statistics
sustainability-14-14877-v2.pddhzftheheeeee
Hindi spoken digit analysis for native and non-native speakers
How ambidextrous entrepreneurial leaders react to the artificial intelligence...
ENT215_Completing-a-large-scale-migration-and-modernization-with-AWS.pdf
The various Industrial Revolutions .pptx
Getting started with AI Agents and Multi-Agent Systems

Dockerized maven

  • 1. Dockerized Maven Matthias Bertschy (http://matthiasbertschy.info) Delivering like a Pro with Docker 5 October, 2016
  • 2. who? ● working as a sysadmin since 2005 ● CISSP and RHCE ● recently switched to DevOps ● day-to-day work with OpenShift and Docker
  • 3. about this talk how to leverage custom Docker containers to: ● handle build dependencies on local workstations ● provide clean Jenkins slaves ● run tests inside orchestrated deployments ● run tests inside OpenShift projects
  • 5. pain ● every developer is different ○ workstation OS ○ development tools ● every team (microservice) is different ○ programming language ○ dependencies ● building quality software requires consistency ● keeping the same environment throughout the pipeline is the key
  • 7. Dockerfile FROM docker.io/centos ENV MAVEN_VERSION 3.3.3 RUN yum update -y && yum install -y java-1.8.0-openjdk-headless && tar xzf apache-maven-$MAVEN_VERSION-bin.tar.gz -C /usr/local/ && mkdir -p /usr/local/apache-maven-$MAVEN_VERSION/.m2/ && yum clean all COPY contrib/settings.xml /usr/local/apache-maven-$MAVEN_VERSION/conf/
  • 8. /home/mbertschy/java #!/bin/bash cmd="/usr/bin/java" cwd=`pwd` user=`id -u` group=`id -g` docker run -i --privileged --user=${user}:${group} --volume=${cwd}:${cwd} --workdir=${cwd} --entrypoint ${cmd} --rm <mvn_container> "${@}"
  • 9. /home/mbertschy/mvn #!/bin/bash MAVEN_VERSION=3.3.3 cmd="/usr/local/apache-maven-${MAVEN_VERSION}/bin/mvn" cwd=`pwd` user=`id -u` group=`id -g` docker run -i --privileged --user=${user}:${group} --volume=${cwd}:${cwd} --workdir=${cwd} --entrypoint ${cmd} --rm <mvn_container> "${@}"
  • 10. usage [mbertschy@devops tmp]$ /home/mbertschy/mvn validate [mbertschy@devops tmp]$ /home/mbertschy/mvn package [mbertschy@devops tmp]$ /home/mbertschy/java -jar target/*.jar . ____ _ __ _ _ / / ___'_ __ _ _(_)_ __ __ _ ( ( )___ | '_ | '_| | '_ / _` | / ___)| |_)| | | | | || (_| | ) ) ) ) ' |____| .__|_| |_|_| |___, | / / / / =========|_|==============|___/=/_/_/_/ :: Spring Boot :: (v1.2.5.RELEASE) ...
  • 11. benefits ● build and test tools are centrally managed ● different versions of tools do not interfere ● workstation are configured in a breeze ● developers can focus on producing quality code
  • 13. Jenkins: master vs slave MASTER ● light workload ● at least one per team (separation of duties) ● numerous / on-demand ● better virtualized SLAVE ● heavy workload ● the need for speed ● better using bare metal ● could be shared to reduce cost
  • 14. pain ● slaves should be shared between teams for cost reasons ● every team (microservice) is different ○ programming language ○ dependencies ● maintaining and upgrading a slave farm is increasingly difficult without uniformity ● building quality software requires consistency ● keeping the same environment throughout the pipeline is the key
  • 16. ... there's a plugin for that!
  • 17. Docker Plugin https://wiki.jenkins-ci.org/display/JENKINS/Docker+Plugin ● Maintainers: Kanstantsin Shautsou, Nigel Magnay ● ~4000 installation per month, and growing ● use a docker host to dynamically provision a slave, run a single build, then tear-down that slave ● optionally, the container can be committed, so that (for example) manual QA could be performed by the container being imported into a local docker provider
  • 18. Dockerfile ... RUN yum install -y openssh-server rsync && /usr/bin/ssh-keygen -A && echo "UseDNS no" >>/etc/ssh/sshd_config && echo "GSSAPIAuthentication no" >>/etc/ssh/sshd_config && echo "StrictModes no" >>/etc/ssh/sshd_config && rm -f /run/nologin && useradd -u 500 -g root -p '...' jenkins && mkdir /home/jenkins/workspace && chown jenkins:root /home/jenkins/workspace EXPOSE 22
  • 19. configuration Prerequisite: you need a docker host with docker.service listening on port 4243 ● as a Jenkins administrator, go to Manage Jenkins ● then Configure System ● at the bottom of the page, you should find a button proposing to Add a new cloud
  • 23. usage ● in your Maven project configuration, you just have to Restrict where this project can be run ● and enter the correct label to match your new slave: ● you can then hit Build Now
  • 24. usage (2) Started by upstream project "S11N/products-md-service-api-build" build number 118 originally caused by: Started by an SCM change [EnvInject] - Loading node environment variables. Building remotely on slave01-f7d02a1538bf (mvn-build) in workspace /home/jenkins/workspace/S11N/production-orders-service-build [WS-CLEANUP] Deleting project workspace... Cloning the remote Git repository ...
  • 25. benefits ● slaves are clean at every build ● slaves are generic and can be reused for many build types (mvn, npm, ...) ● we can use lightweight OS for slaves (atomic CentOS) ● easy maintenance ● consistency
  • 27. what? ● tool for defining and running multi-container Docker applications ● great for development, testing, and staging environments ● we use it for component testing on workstations ● define the services in docker-compose.yml ● docker-compose up
  • 29. docker-compose.yml (2) ... product: image: products-md-service:0.1.0-SNAPSHOT ports: - "18080:8080" links: - db environment: DB_URL: jdbc:postgresql://db:5432/mydb DB_USER: myuser DB_PASSWORD: ********
  • 31. pain ● links defined in docker-compose.yml are only resolvable from containers started by Compose ● testing and debugging should be performed as if the developer was inside Docker space ● building quality software requires consistency ● keeping the same environment throughout the pipeline is the key
  • 33. principle ● links defined in docker-compose.yml are only resolvable from containers started by Compose ● we already have our development environment packaged inside a container ● let's insert our developer inside the Compose world! ● we have called this pattern "the avatar"
  • 36. usage [mbertschy@devops tmp]$ docker-compose up -d Creating tmp_db_1 Creating tmp_product_1 Creating tmp_avatar_1 [...]$ rsync -a -e "ssh -p 2222" ./ jenkins@127.0.0.1/ [mbertschy@devops tmp]$ ssh -l jenkins -p 2222 127.0.0.1 jenkins@127.0.0.1's password: [jenkins@e250549ee18d ~]$ pwd /home/jenkins [jenkins@e250549ee18d ~]$ ping db PING db (172.17.0.2) 56(84) bytes of data. 64 bytes from db (172.17.0.2): icmp_seq=1 ttl=64 time=0.106 ms
  • 37. benefits ● tests rely on link definitions ● different versions of tools do not interfere ● workstation are configured in a breeze ● developers can focus on producing quality code
  • 39. what? Built on opensource projects: ● Docker provides the abstraction for packaging apps ● Kubernetes orchestrates Docker containers OpenShift Enterprise adds: ● Source code management, builds, and deployments ● Image management and promotion ● Application management ● Team and user tracking for large developer organizations
  • 41. component architecture ● database: ○ 1x PostgreSQL pod ○ 1x service (SQL) ● backend: ○ 1x SpringBoot pod ○ 2x service (REST, gRPC) ○ 1x route ● frontend ○ 1x NGINX pod (serving node.js application) ○ 1x service (HTTP) ○ 1x route
  • 45. pain ● pods and services are only accessible from containers started inside the same project ● routes can only publish HTTP (v1) based protocols ● tests have to access services directly (flyway scripts for databases, message brokers, binary protocols, ...) ● building quality software requires consistency ● keeping the same environment throughout the pipeline is the key
  • 46. let's use Docker (one last time)...
  • 47. principle ● pods and services are only accessible from containers started inside the same project (until 3.3...) ● we already have our development environment packaged inside a container ● let's insert our developer inside the OpenShift project! ● this is a second use of our pattern called "the avatar"
  • 48. Dockerfile ... # fix permissions to run inside openshift RUN chmod 0770 /home/jenkins && chmod 2770 /home/jenkins/workspace && chmod 2770 /usr/local/apache-maven-$MAVEN_VERSION/.m2/ ADD oc-3.2.0.20-linux.tar.gz /usr/local/bin/ # when running from jenkins, plugin starts /sbin/sshd -D # this default sleep is for OpenShift to keep pod running CMD ["sleep", "infinity"]
  • 49. template.yml apiVersion: v1 kind: DeploymentConfig metadata: name: mvn-avatar spec: replicas: 1 template: spec: containers: image: <mvn_container> imagePullPolicy: Always name: mvn-avatar
  • 51. usage [mbertschy@devops tmp]$ oc get pods NAME READY STATUS RESTARTS AGE mvn-avatar-1-94snc 1/1 Running 0 6d db-products-md-srv-1-13o5f 1/1 Running 0 6d products-md-srv-1-lw3cb 1/1 Running 0 6d products-md-web-1-g1fu8 1/1 Running 0 6d [mbertschy@devops tmp]$ oc rsync ./ mvn-avatar-1-94snc:/ [mbertschy@devops tmp]$ oc rsh mvn-avatar-1-94snc sh-4.2$ ping db-products-md-srv PING db-products-md-srv.qa-products-md.svc.cluster.local (172.30.46.79) 56(84) bytes of data. ^C
  • 52. usage from Jenkins [products-md-ctest] $ /bin/sh -xe /tmp/hudson84804829430149.sh ++ oc get pod -l app=mvn-avatar --no-headers ++ awk '{print $1}' + avatarPod=mvn-avatar-1-94snc + oc rsh mvn-avatar-1-94snc mkdir -p S11N/products-md-deploy + oc rsync --progress=true S11N/products-md-deploy/ mvn-avatar-1-94snc:S11N/products-md-deploy/ + oc rsh mvn-avatar-1-94snc bash -c 'cd S11N/products-md-deploy ; source *-conf.sh || true ; export ; mvn verify' ...
  • 53. usage from Jenkins (2) ... + mkdir -p S11N/products-md-ctest/cucumberOutput + oc rsync mvn-avatar-1-94snc:S11N/products-md-deploy/cucumberOutput/ S11N/products-md-ctest/cucumberOutput --no-perms=true receiving incremental file list 20161003133154.json
  • 54. benefits ● tests are run from inside OpenShift projects ● native name resolution and load balancers are leveraged ● developers can jump inside projects for live debugging ● Jenkins integration is possible with minimal fuss