Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Using Docker for Testing

19,813 views

Published on

Linux containers and Docker specifically have revolutionized the way applications are run at scale, but testing can greatly benefit from those technologies too.Containers allow to run tests in isolation with a minimum performance penalty, increased speed with respect to virtual machine based tests and easier configuration and less complexity for integration testing. Testing with containers allows running tests in a new, clean environment for each execution, minimizing false positives and environment corruption. At the same time it allows reusing container clusters to run development, testing and production workloads.You will learn to effectively use Jenkins with Docker and Kubernetes, a multi host Docker clustering technology, to run your Jenkins jobs in isolated containers for each execution at scale.

http://www.agiletestingdays.com/session/using-docker-for-testing/

Published in: Technology

Using Docker for Testing

  1. 1. Using Docker for Testing Carlos Sanchez
 @csanchez
  2. 2. About Senior Software Engineer @ CloudBees Author of Jenkins Kubernetes plugin Long time OSS contributor at Apache Maven, Eclipse, Puppet,…
  3. 3. Containers & micro services
  4. 4. @YourTwitterHandle Docker Linux containers Union File System File System Users Processes Network
  5. 5. But it is not trivial
  6. 6. Docker Linux required but Docker Machine (formerly Boot2Docker) to the rescue OS X Windows
  7. 7. Docker Build once, run anywhere (kind of) Bare metal Virtual Machines Cloud Docker
  8. 8. developer oriented Dependency hell installation nightmares “it ran on my machine”
  9. 9. ops oriented no need to know internals of apps focus on OPs problems (scale, monitoring,…) clearer deliverables from dev
  10. 10. @YourTwitterHandle Docker delivery Docker image Docker infrastructure App System
  11. 11. Related projects
  12. 12. Docker Machine Provision Docker engines VirtualBox, replaces boot2docker ! Amazon EC2 Microsoft Azure Google Compute Engine OpenStack Rackspace VMware …
  13. 13. Docker Swarm Clustering for Docker containers Using the same API Integrates with Mesos / Mesosphere And planned Amazon EC2 Container Service (ECS) Google Kubernetes IBM Bluemix Container Service Joyent Smart Data Center Microsoft Azure
  14. 14. Docker Compose Orchestration of multi-container apps Based on Fig Defined by: containers configuration links volumes
  15. 15. Apache Mesos A distributed systems kernel Docker Containerizer Marathon & Chronos
  16. 16. Docker & Jenkins
  17. 17. What are we trying to solve Different projects, different requirements languages (Java, Ruby,…) tools (Maven, Ant, …) system libraries (OpenSSL, …) operating systems (Debian, Red Hat,…) external dependencies (MySQL, Postgres)
  18. 18. @YourTwitterHandle Initial solution Jenkins master slave 3 slave 2 slave 1
  19. 19. Dockerfile # A Debian based image FROM jenkinsci/jnlp-slave RUN apt-get update && apt-get install -y mysql && rm -rf /var/lib/apt/lists/*
  20. 20. Dockerfile FROM centos RUN yum -y install openjdk-8 mysql ENV JENKINS_REMOTING_VERSION 2.52 ENV HOME /home/jenkins RUN useradd -c "Jenkins user" -d $HOME -m jenkins RUN curl --create-dirs -sSLo /usr/share/jenkins/remoting- $JENKINS_REMOTING_VERSION.jar http://repo.jenkins-ci.org/public/ org/jenkins-ci/main/remoting/$JENKINS_REMOTING_VERSION/remoting- $JENKINS_REMOTING_VERSION.jar && chmod 755 /usr/share/jenkins COPY jenkins-slave.sh /usr/local/bin/jenkins-slave.sh USER jenkins VOLUME /home/jenkins ENTRYPOINT ["/usr/local/bin/jenkins-slave.sh"]
  21. 21. Docker plugin
  22. 22. Docker plugin As a plugin on demand slaves https://github.com/jenkinsci/docker-plugin
  23. 23. @YourTwitterHandle Jenkins master slave 3 slave 2 slave 1
  24. 24. CloudBees Docker Custom Build Environment Plugin
  25. 25. Custom Build Environment Avoid dependencies in Jenkins Containers are completely isolated Use any executor/slave
  26. 26. @YourTwitterHandle Jenkins master slave container docker exec
  27. 27. Dockerfile FROM centos RUN yum -y install openjdk-8 mysql ENV JENKINS_REMOTING_VERSION 2.52 ENV HOME /home/jenkins RUN useradd -c "Jenkins user" -d $HOME -m jenkins RUN curl --create-dirs -sSLo /usr/share/jenkins/remoting- $JENKINS_REMOTING_VERSION.jar http://repo.jenkins-ci.org/public/ org/jenkins-ci/main/remoting/$JENKINS_REMOTING_VERSION/remoting- $JENKINS_REMOTING_VERSION.jar && chmod 755 /usr/share/jenkins COPY jenkins-slave.sh /usr/local/bin/jenkins-slave.sh USER jenkins VOLUME /home/jenkins ENTRYPOINT ["/usr/local/bin/jenkins-slave.sh"]
  28. 28. Custom Build Environment Take advantage of all pre-built Docker images java, ruby, python, maven,…
  29. 29. Docker images are now a deliverable Docker images are part of the pipeline Build/test/deploy images Deliver as any other artifact even if not used to run production systems
  30. 30. More Docker!
  31. 31. @YourTwitterHandle Jenkins plugins Docker CloudBees Docker Custom Build Environment CloudBees Docker Build and Publish CloudBees Docker Hub Notification CloudBees Docker Traceability docker-build-step Docker workflow Kubernetes Mesos
  32. 32. Build and Publish
  33. 33. Docker Hub Notification
  34. 34. Docker & Selenium
  35. 35. Selenium Manage multiple combinations of browsers Any number of them Standalone or Selenium Hub even with VNC
  36. 36. Selenium Hub hub: image: selenium/hub:2.48.2 ports: - "4444:4444" firefox: image: selenium/node-firefox-debug:2.48.2 links: - hub ports: - "5901:5900" chrome: image: selenium/node-chrome-debug:2.48.1 links: - hub ports: - "5902:5900"
  37. 37. Kubernetes
  38. 38. Kubernetes Container cluster orchestration Docker containers across multiple hosts (nodes or minions) Higher level API Enforced state Monitoring of endpoints
  39. 39. Providers GKE Azure Vmware Rackspace oVirt Vagrant CloudStack Ubuntu
  40. 40. Pod Group of colocated containers Same network namespace/IP Environment variables Shared volumes host mounted empty volumes GCE data disks AWS EBS volumes nfs glusterfs secrets
  41. 41. @YourTwitterHandle Pods Node client kubelet pods Master Node kubelet pods Node kubelet pods … … …
  42. 42. Pod kind: "Pod" apiVersion: "v1" metadata: name: "jenkins" labels: name: "jenkins" spec: containers: - name: "jenkins" image: "csanchez/jenkins-swarm: 1.625.1-for-volumes" ports: - containerPort: 8080 - containerPort: 50000 volumeMounts: - name: "jenkins-data" mountPath: "/var/jenkins_home" volumes: - name: "jenkins-data" hostPath: path: "/home/docker/jenkins"
  43. 43. Kubernetes Jenkins plugin
  44. 44. Kubernetes Jenkins plugin As a plugin on demand slaves https://github.com/jenkinsci/kubernetes- plugin
  45. 45. Danke!

×