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.

Codefresh + Cloud 66 webinar: Testing Strategies for Docker Driven Development


Published on

Slides from Alexei Ledenev's talk on testing strategies for Docker containers. Abstract: Being able to build a Docker container is only part of its development story. You need to be able to test your newly created containers. Ideally, we’d all like our container testing to be repeatable and portable. But there’s more than one way to achieve this so how do you know which method to choose? During this talk, we will demonstrate several approaches for testing Docker containers, discussing benefits and drawbacks with each approach.

Published in: Technology
  • D0WNL0AD FULL ▶ ▶ ▶ ▶ ◀ ◀ ◀ ◀
    Are you sure you want to  Yes  No
    Your message goes here

Codefresh + Cloud 66 webinar: Testing Strategies for Docker Driven Development

  1. 1. Testing Strategies for Docker Driven Development
  2. 2. Testing Strategies for Docker Containers Alexei Ledenev
  3. 3. About me… • • •#docker, #golang, #aws • •@alexeiled
  4. 4. Why Docker Portability Speed Configuration Docker Hub (“App Store”)
  5. 5. Docker Architecture
  6. 6. Demo App & Test Demo App Rest API server #golang Test Newman Postman scenario file #nodejs
  7. 7. The “Naive” Approach
  8. 8. go build -o .dist/demo -v run app and tests .dist/demo &>/dev/null & newman run -e test/local.env.json test/demo-rest-api-tests.postman.json build Docker demo image docker build -t demo -f docker/Dockerfile.dist .
  9. 9. Benefits and Drawbacks Familiar CI flow Application portability Smaller Docker image • Non portable DEV environment • Non portable TEST environment
  10. 10. App & Test Container
  11. 11. # build demo app & test container $ docker build -t demo:apptest -f docker/ . # run tests $ docker run -it --rm demo:apptest script/ # run app $ docker run -d -p 10000:10000 demo:apptest demo
  12. 12. Benefits and Drawbacks Simple CI flow Application portability Portable DEV environment Portable TEST environment • Bigger Docker image size • Need to rebuild the whole image on code or test change • Polluted Docker image • Need to manage test results
  13. 13. Test Aware Container
  14. 14. # build test aware Docker image $ docker build -t demo:testaware -f docker/ . # run tests $ docker run -it --rm demo:testaware # get app layers from image $ APP_LAYER=$(docker history demo:testaware | grep -e ‘LABEL SPLIT=T’ | awk ‘{print $1}’) # tag APP_LAYER and push it $ docker tag $APP_LAYER demo:app # run demo app $ docker run -it --rm -p 10000:10000 --name demo demo:app
  15. 15. Benefits and Drawbacks Application portability Portable TEST and DEV environments 2 separate images One Dockerfile • Need to rebuild the whole image on code or test change • Need some shell “magic” to create a clean APP image (non-Docker way)
  16. 16. – Me :-) “After trying multiple approaches, the following is the one that I can recommend.”
  17. 17. Docker Automation Flow Docker automation CI/CD flow consists from multiple steps, like: build, scan, test, run, deploy and others. Each step requires different tools, runtime, packages, data and configuration files Use dedicated Docker container for every step For example: Builder Container - use it to build your app. Docker container with compilers, linters, package managers and other dev tool. Test Container(s) - user it to test your app. Docker container with testing tools, test scripts, runtimes and helper files and required packages. App Container - the one you push/deploy. Docker container with application binary, runtime and required packages only.
  18. 18. CI with Test Containers
  19. 19. # build Build Container image $ docker build -t demo:builder -f docker/Dockerfile.builder . # use Builder container to build the app $ docker run -it --rm -v $(pwd)/.dist:/go/src/app/.dist -e CGO_ENABLED=0 demo/builder go build -v -o .dist/demo # build App Container image $ docker build -t demo:dist -f docker/Dockerfile.dist . # build Test Container image $ docker build -t demo:test -f docker/Dockerfile.test . # create common network for app and test $ docker network create mynet # run demo app $ docker run -d --name demo --network mynet demo:dist # run tests $ docker run -it --rm --name tests --network mynet demo:test newman run -e test/demo.env.json test/demo-rest-api-tests.postman.json
  20. 20. Benefits and Drawbacks • Application portability • Portable DEV environment • Build ANYWHERE • Portable TEST environment • Test ANYWHERE • Small APP image • Fast builds • Need an approach/tool to automate and orchestrate Docker build flow • Bash, Ansible, … • dobi, habitus, … • Docker CI/CD service, like
  21. 21. Q&A @alexeiled
  22. 22. ● Create your Codefresh account at ● Additional info on Containers & Docker Driven Development - & ● Twitter - @codefresh ● Questions for sales - ● Create your Cloud 66 account at ● Twitter - @cloud66 Next Steps
  23. 23. Thank You!