35
Trust, but verify Testing with Docker Containers

Trust, but verify | Testing with Docker Containers

  • Upload
    nan-liu

  • View
    105

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Trust, but verify | Testing with Docker Containers

Trust, but verifyTesting with Docker Containers

Page 2: Trust, but verify | Testing with Docker Containers

whoami

● Nan Liu

Page 3: Trust, but verify | Testing with Docker Containers

Ship Faster

Page 4: Trust, but verify | Testing with Docker Containers

Snap Container

FROM alpine:3.4MAINTAINER Nan LiuENV SNAP_LOG_LEVELEXPOSE 8181ADD build/snapteld /opt/snap/sbin/snapteldADD build/snaptel /opt/snap/sbin/snaptelCOPY snapteld.conf /etc/snap/snapteld.conf

CMD /opt/snap/sbin/snapteld -t 0 -l 1 -o ''

Page 5: Trust, but verify | Testing with Docker Containers

Snap Container

Just it.

Page 6: Trust, but verify | Testing with Docker Containers

Fail

dynamically linked (uses shared libs), not stripped

Page 7: Trust, but verify | Testing with Docker Containers

Serverspec

require "serverspec"set :backend, (ssh/exec/cmd/...)

describe :label do describe :resource_type("name") do it { should be_assertions } endend

System

Vagrant

Ubuntu VM

Windows VM

Serverspec

Remote System

Page 8: Trust, but verify | Testing with Docker Containers

Verify

describe package("snap-telemetry") do it { should be_installed }end

describe command("ldd $(which snapteld)") do its(:stdout) { should match /not a dynamic executable/ }end

* serverspec in vagrant

Page 9: Trust, but verify | Testing with Docker Containers

Container Inspection

Page 10: Trust, but verify | Testing with Docker Containers

Docker Serverspec

require 'serverspec'require 'dockerspec/serverspec'

describe docker_build(path: './Dockerfile') do # erb, string # testenddescribe docker_run('intelsdi/snap:xenial', family: 'debian') #testend

Page 11: Trust, but verify | Testing with Docker Containers

Docker Serverspec

describe docker_build("alpine/.") do it { should have_maintainer /Nan Liu/ } %w[SNAP_VERSION SNAP_TRUST_LEVEL SNAP_LOG_LEVEL].each do |e| it { should have_env e } end it { should have_label( "license" => "Apache 2.0" ) } it { should have_expose '8181' }end

Page 12: Trust, but verify | Testing with Docker Containers

Docker Serverspec

describe docker_build("alpine/.") do describe docker_run(described_image) do describe file('/etc/snap/snapteld.conf') do its(:content_as_yaml) { should include('log_path' => '/var/log/snap') should include('control' => { "auto_discover_path" => "/opt/snap/plugins"}) } end endend

Page 13: Trust, but verify | Testing with Docker Containers

Demo

Page 14: Trust, but verify | Testing with Docker Containers

Travis CI

sudo: trueservices: - dockerlanguage: rubybefore_deploy: - docker login -e="$DOCKER_EMAIL" -u="$DOCKER_USERNAME" -p="$DOCKER_PASSWORD"

Page 15: Trust, but verify | Testing with Docker Containers

Travis CI

deploy: provider: script script: docker push intelsdi/snap:latest on: branch: master

Page 16: Trust, but verify | Testing with Docker Containers

Mission Accomplished

Page 17: Trust, but verify | Testing with Docker Containers

Testing Snap

● Operating systems○ Linux: RedHat/Ubuntu○ MacOS

● 85 Plugins○ Databases/NoSQL○ OpenStack

● ^^^ * Snap Version * Plugin Versions = ???

Page 18: Trust, but verify | Testing with Docker Containers

Engineer view

Page 19: Trust, but verify | Testing with Docker Containers

User view

Page 20: Trust, but verify | Testing with Docker Containers

Large Test Goals

● Matrix of Snap/Snap plugin versions● Support multiple OS versions● Small overhead/footprint +● Debugging tool +

Page 21: Trust, but verify | Testing with Docker Containers

Large Test

Pros

● simple?

Cons

● script sprawl● parsing output (jq)● dockerfile proliferation● no os abstraction

System

Docker

Snap

Dependency

#!/bin/bash● launch containers● run scripts in containers● cleanup

#!/bin/bashtest scripts

Page 22: Trust, but verify | Testing with Docker Containers

Large Test

Pros

● Testing framework

Cons

● snowflake containers● dockerfile proliferation

System

Docker

Snap

Dependency

#!/bin/bash● launch containers● run scripts in containers● cleanup

#!/bin/env pythongoss test framework

Page 23: Trust, but verify | Testing with Docker Containers

Large Test

Pros

● all in one

Cons

● ruby dependency● need to learn serverspec

System

Docker

Snap

Dependency

docker serverspec● build containers● docker exec commands● cleanup

Page 24: Trust, but verify | Testing with Docker Containers

Docker Compose

services: snap: image: intelsdi/snap:${OS}_test environment: SNAP_VERSION: "${SNAP_VERSION}" volumes: - "${PLUGIN_PATH}:/plugin""

Page 25: Trust, but verify | Testing with Docker Containers

Docker Compose Serverspec

describe docker_compose("../docker-compose.yml") do its_container(:snap) do describe command("snaptel task create -t /plugin/examples/tasks/#{t}") do its(:exit_status) { should eq 0 } end endend

Page 26: Trust, but verify | Testing with Docker Containers

Large Test

System

Docker

Snap

Dependency

docker-compose-serverspec● build containers● docker exec

commands● cleanup

Page 27: Trust, but verify | Testing with Docker Containers

Docker-inception (sibling containers)

docker run -v /var/run/docker.sock:/var/run/docker.sock \ -v "${proj_dir}":/plugin \ -e PLUGIN_PATH="${proj_dir}" \ -e SNAP_VERSION="${SNAP_VERSION}" \ -e OS="${OS}" \ -it intelsdi/serverspec:alpine \ /bin/sh -c "cd /plugin/scripts && rspec ./test/*_spec.rb"

Page 28: Trust, but verify | Testing with Docker Containers

Docker Compose Serverspec

describe docker_compose("../docker-compose.yml") do its_container(:snap) do describe command("snaptel task create -t /plugin/examples/tasks/#{t}") do its(:exit_status) { should eq 0 } end endend

Page 29: Trust, but verify | Testing with Docker Containers

Large Test

its_container(:influxdb) do describe 'wait for influxdb service' do it do c=cmd_retry('curl -sl -I localhost:8086/ping') expect(c.exit_status).to eq 0 end end end

System

Docker

Snap

Influxdb

docker-serverspec● build containers● docker exec

commands● cleanup

Page 30: Trust, but verify | Testing with Docker Containers

Large Test

describe command("#{snaptel} plugin list") do it { load_all_plugins } its(:exit_status) { should eq 0 } its(:stdout) { plugins.each do |p| _ , name = p should contain(/#{name}/) end }end

Page 31: Trust, but verify | Testing with Docker Containers

Demo

Page 32: Trust, but verify | Testing with Docker Containers

Large Test

Cons

● Docker environment variable nesting ● pry debug output munged

System

Docker

Snap

Dependency

docker-serverspec● build containers● docker exec

commands● cleanup

Page 33: Trust, but verify | Testing with Docker Containers

Ship Faster with Confidence

Page 34: Trust, but verify | Testing with Docker Containers

Questions?

● serverspec.org● github.com/zuazo/dockerspec● github.com/nanliu/docker-serverspec

● github.com/intelsdi-x/snap

Page 35: Trust, but verify | Testing with Docker Containers

Next Docker Meetup

● Feb 9th @ Puppet Labs● Mike Coleman | Docker