testing strategies for docker containers

Download Testing strategies for Docker containers

Post on 13-Feb-2017

347 views

Category:

Technology

1 download

Embed Size (px)

TRANSCRIPT

  • Testing Strategies for

    Docker Containers

    Alexei Ledenev @alexeiled

  • About meDT @HPE

    github.com/alexei-led/pumba

    #docker, #golang, #aws

    medium.com/@alexeiled

    @alexeiled

    http://github.com/alexei-led/pumbahttp://medium.com/@alexeiledhttp://twitter.com/alexeiled

  • Why Docker Portability

    Speed

    Configuration

    Docker Hub (App Store)

  • Docker Architecture

  • Demo App & Test Demo App

    Rest API server

    #golang

    Test

    Newman

    Postman scenario file

    #nodejs

    https://github.com/postmanlabs/newman

  • The Naive Approach

  • #builddemoapp$gobuild-o.dist/demo-v

    #runappandtests$.dist/demo&>/dev/null&$newmanrun-etest/local.env.jsondemo-rest-api-tests.postman.json

    #buildDockerdemoimage$dockerbuild-tdemo-fdocker/Dockerfile.dist.

    https://asciinema.org/a/100204

    https://asciinema.org/a/100204

  • Benefits and Drawbacks Familiar CI flow

    Application portability

    Smaller Docker image

    Non portable DEV environment

    Non portable TEST environment

  • App & Test Container

  • #builddemoapp&testcontainer$dockerbuild-tdemo:apptest-fdocker/Dockerfile.build.apptest.

    #runtests$dockerrun-it--rmdemo:apptestscript/test.sh

    #runapp$dockerrun-d-p10000:10000demo:apptestdemo

    https://asciinema.org/a/100216

    https://asciinema.org/a/100216

  • Benefits and Drawbacks 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

  • Test Aware Container

  • #buildtestawareDockerimage$dockerbuild-tdemo:testaware-fdocker/Dockerfile.build.testaware.

    #runtests$dockerrun-it--rmdemo:testaware

    #getapplayersfromimage$APP_LAYER=$(dockerhistorydemo:testaware|\grep-eLABELSPLIT=T|\awk{print$1})

    #tagAPP_LAYERandpushit$dockertag$APP_LAYERdemo:app

    #rundemoapp$dockerrun-itrm-p10000:10000demo:app

    https://asciinema.org/a/100260

    https://asciinema.org/a/100260

  • 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)

  • Me :-)

    After trying multiple approaches, the following is the one that I can recommend.

  • 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.

  • #buildBuildContainerimage$dockerbuild-tdemo:builder-fdocker/Dockerfile.builder.

    #useBuildercontainertobuildtheapp$dockerrun-it--rm\-v$(pwd)/.dist:/go/src/app/.dist\-eCGO_ENABLED=0demo/buildergobuild-v-o.dist/demo

    #buildAppContainerimage$dockerbuild-tdemo:dist-fdocker/Dockerfile.dist.

    #buildTestContainerimage$dockerbuild-tdemo:test-fdocker/Dockerfile.test.

    #createcommonnetworkforappandtest$dockernetworkcreatemynet

    #rundemoapp$dockerrun-d--namedemo--networkmynetdemo:dist

    #runtests$dockerrun-d--nametests--networkmynetdemo:test\newmanrun-etest/demo.env.json\test/demo-rest-api-tests.postman.json

  • CI with Test Containers

  • 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, etc. Docker CI/CD service, like

    codefresh.io

    http://codefresh.io

  • Q&A

    @alexeiled

    http://twitter.com/alexeiled