Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Test Driven Infrastructure for Docker

Test Driven Infrastructure for Docker

Test driven development is common sense, test driven infrastructure not. Using serverspec and related tools, it becomes really ease to test a docker setup, starting from the host, dockerd, its images and containers, and the container contents itself. References : http://www.infrabricks.de/blog/2015/04/16/docker-container-mit-serverspetesten-teil-2/ https://github.com/de-wiring/containerspec

Andreas Schmidt

May 08, 2015
Tweet

More Decks by Andreas Schmidt

Other Decks in Technology

Transcript

  1. Test Driven Development (TDD) is common sense. Today, infrastructure is

    code. Containers and Hosts can be spec'ed and tested
  2. serverspec.org •  by @gosukenatorand community •  like unit-tests for your

    hosts •  independend of provisioning mechanisms •  != rspec-puppet •  readable DSL, based on ruby
  3. serverspec.org – Resource types •  files •  users, groups • 

    "network": bridge, port, gateway, interface, routing_table •  "os": cgroup, service, yumrepo, cron, kernel_module, iptables, ... •  x509: certificates, keys •  windows (yesh!): iis, registry_keys
  4. Host level - Daemon •  Ensure that dockerd is installed

    •  Configured the way you want it to be (/etc/ default/docker) •  Running with given options (i.e. selinux) •  Running TLS-enabled with correct TLS setup 1
  5. Host level - Daemon •  Example spec at https://gist.github.com/aschmidt75/163c36450c9c24f21285 • 

    correct TLS keys & certs •  not listening on 0.0.0.0 •  not using docker.sock •  TLS works as expected •  ... 1
  6. Host level - Images •  Ensure that specific images are

    present •  Ensure that conditions on images are met, i.e. Maintainer is set, Ports are exposed, Environment entries are present a.s.o. •  Serverspec type does a "docker inspect", checks values. 2 (*)  h&ps://github.com/de-­‐wiring/containerspec/wiki/Specifying-­‐and-­‐tes?ng-­‐a-­‐docker-­‐setup  
  7. Host level - Containers •  Ensure that specific containers are

    present, running within certain conditions. •  i.e. not privileged, as a certain user, not as root, exposing ports (or not), having volumes mounted (ro), having capabilities dropped or added a.s.o. 3 (*)  h&ps://github.com/de-­‐wiring/containerspec/wiki/Specifying-­‐and-­‐tes?ng-­‐a-­‐docker-­‐setup  
  8. Host level - Complete Setup •  Drawback of serverspec: Tests

    only a single image / container •  containerspec is based on cucumber •  tests multiple images/containers at once •  selects by name, image repo, ... 4 (*)  h&ps://github.com/de-­‐wiring/containerspec/wiki/Specifying-­‐and-­‐tes?ng-­‐a-­‐docker-­‐setup  
  9. Container level •  Host: ✔ •  docker backend of serverspec

    allows for looking into containers: "docker exec" •  Everything can be tested inside containers – as long as testing binaries (i.e. netstat) are installed. 5
  10. Build chains do not just produce application packages. With docker,

    they produce infrastructure. Testing Infrastructure is not that hard.