Ce diaporama a bien été signalé.
Nous utilisons votre profil LinkedIn et vos données d’activité pour vous proposer des publicités personnalisées et pertinentes. Vous pouvez changer vos préférences de publicités à tout moment.

Using Docker for Testing

Demo of how to dockerise and deploy your microservices application to the test environment, how to run selenium tests inside docker and how to put this all together to integrate your tests in your CI/CD pipeline using Jenkins.
Presented at ATA GTR 2016 in Pune.

Using Docker for Testing

  1. 1. Using Docker for Testing MUKTA APHALE ATA GTR 2016, PUNE @muktaa
  2. 2. Who Am I? • Developer, DevOps Enthusiast • Passion for technology, innovation and the thirst to keep learning • Love to code • Love to design solutions • Love to network • Believe in dreaming big • Believe in work-life balance @muktaa
  3. 3. Agenda • Where testing stands today, current challenges of testing • What is Docker? • How can docker help in better automation testing? • A traditional way of doing integration testing • Demo of using Docker for testing • Demo of integrating dockerized tests with your CI @muktaa
  4. 4. Pain Points of Testing • Unit tests, integration tests, complex integration tests • UI testing • Git branching • Environments • Failed tests pollute environment • Deployment dependencies, testing dependencies @muktaa
  5. 5. Docker @muktaa Linux  Container Docker Data  Centre,   Docker Cloud,  Docker Engine,  Docker Hub,   UCP Benefits: Speed Portability Density Open  Source “Can  create  lightweight,  self   sufficient  containers  from   any  application”
  6. 6. Docker Applications • Testing • Microservices Applications • Simplifying Development • Simplifying Deployment • Production • CaaS @muktaa
  7. 7. Docker for enabling Testing • Mimic production environment • Consistent Environments • Black Box Testing • Scalability Testing • Configuration Testing • Testing Simplified @muktaa
  8. 8. Deploying for Integration Testing: Old Way • Build project • SCP the build artifact to the server(s) • Ssh into the server • Stop webserver • Replace the build artifact at the right path • Restart webserver o SCP the tar.gz from the project to the server(s) o ssh into the server o stop tomcat o remove the “work”, “webapps”, “shared” and “common” folders o extract the tar.gz into the tomcat folder o start tomcat @muktaa
  9. 9. Integration Testing: Old Way • Wait for deployment to complete ◦Webserver comes up • Ensure setup is clean ◦DB Scripts, Env variables, etc • Get your latest integration test code ready • Point your integration tests to your newly deployed setup • Run integration tests @muktaa
  10. 10. Let’s use Docker… @muktaa
  11. 11. Example Scenario • Webserver • NGiNX • App Server • 3 load balanced instances • Node js • DB Server • Redis @muktaa
  12. 12. Output • Prints the number of times the page was hit • Source Code: https://github.com/muktaa/dock er-example/ @muktaa
  13. 13. Dockerizing Each Component • Dockerfile for each component • Docker-compose.yml • Build Script @muktaa
  14. 14. Demo DEPLOY APPLICATION FOR INTEGRATION TESTING @muktaa
  15. 15. Steps • Git clone https://github.com/muktaa/docker-example/ • Docker-compose build • Docker-compose up @muktaa
  16. 16. Running Integration Tests LETS DOCKERIZE THE INTEGRATION TESTS TOO! @muktaa
  17. 17. Example of Selenium Tests • https://github.com/muktaa/SeleniumExample • Ready docker image available: ◦Docker pull selenium-example • Customize the sample tests, refer to README: https://github.com/muktaa/SeleniumExample/blob/m aster/README.md • Headless Selenium tests @muktaa
  18. 18. Demo • https://github.com/muktaa/SeleniumExample/blob/m aster/Dockerfile • Docker pull muktaa/selenium-example:headless • Docker run -it -e TEST_URL=http://54.254.223.84:5555/ muktaa/selenium-example:headless @muktaa
  19. 19. Sample Output @muktaa
  20. 20. Nightly Build PUTTING  IT  ALL  TOGETHER  TO  WRITE  NIGHTLY  BUILD  JOB  FOR  OUR   DOCKERIZED INTEGRATION  TESTS @muktaa
  21. 21. Jenkins Job @muktaa
  22. 22. Job Configuration @muktaa
  23. 23. Job Build Step 1 #/bin/bash +x docker-compose --project-name=${JOB_NAME}stop &> /dev/null || true &> /dev/null docker-compose --project-name=${JOB_NAME}rm -- force &> /dev/null || true &> /dev/null docker stop `docker ps -a -q -f status=exited`&> /dev/null || true &> /dev/null docker rm -v `docker ps -a -q -f status=exited`&> /dev/null || true &> /dev/null docker rmi `docker images--filter 'dangling=true' -q --no- trunc` &> /dev/null || true &> /dev/null docker-compose build docker-compose --project-name=${JOB_NAME}up & @muktaa
  24. 24. Job Build Step 2, 3 docker run -itd -v /var/lib/jenkins/workspace/docker- example/test-report:/usr/share/app/target/surefire- reports -e TEST_URL=http://54.254.223.84:5555/ muktaa/selenium-example:headless @muktaa
  25. 25. Job Build Steps 3, 4 @muktaa
  26. 26. What Next? • Lots More! • Running Selenium tests inside Docker • Using docker swarm to deploy • Using docker machine to manage hosts for testing @muktaa
  27. 27. References • http://blogs.plos.org/tech/testing-made-awesome-with-docker/ • https://www.wouterdanes.net/2014/04/11/continuous-integration-using- docker-maven-and-jenkins.html • http://making.meetup.com/post/122890386432/steps-towards-automated- testing-with-docker-and • https://divan.github.io/posts/integration_testing/ • https://medium.com/@WoloxEngineering/ruby-on-rails-continuous- integration-with-jenkins-and-docker-compose-8dfd24c3df57#.7vxoq2gfg • http://anandmanisankar.com/posts/docker-container-nginx-node-redis- example/ • http://www.conductor.com/nightlight/running-selenium-grid-using-docker- compose/ @muktaa
  28. 28. Thank You! QUESTIONS? @muktaa

×