2015-09-03 12:06:43 +00:00
|
|
|
require 'docker'
|
|
|
|
require 'yaml'
|
2015-09-03 11:22:15 +00:00
|
|
|
require_relative '../lib/vulcano'
|
2015-09-03 12:06:43 +00:00
|
|
|
|
2015-09-03 12:14:57 +00:00
|
|
|
tests = ARGV
|
|
|
|
if tests.empty?
|
|
|
|
puts 'Nothing to do.'
|
|
|
|
exit 0
|
|
|
|
end
|
2015-09-03 11:22:15 +00:00
|
|
|
|
2015-09-03 12:06:43 +00:00
|
|
|
class DockerTester
|
|
|
|
def initialize(tests)
|
|
|
|
@tests = tests
|
|
|
|
@images = docker_images_by_tag
|
|
|
|
@conf = tests_conf
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
# test all images
|
|
|
|
@conf['images'].each{|n|
|
|
|
|
test_image(n)
|
|
|
|
}.all? or raise "Test failures"
|
|
|
|
end
|
|
|
|
|
|
|
|
def docker_images_by_tag
|
|
|
|
# get all docker image tags
|
|
|
|
images = {}
|
|
|
|
Docker::Image.all.map do |img|
|
|
|
|
Array(img.info['RepoTags']).each do |tag|
|
|
|
|
images[tag] = img
|
|
|
|
end
|
|
|
|
end
|
|
|
|
images
|
|
|
|
end
|
|
|
|
|
|
|
|
def tests_conf
|
|
|
|
# get the test configuration
|
|
|
|
conf_path = File::join(File::dirname(__FILE__), '..', '.tests.yaml')
|
|
|
|
raise "Can't find tests config in #{conf_path}" unless File::file?(conf_path)
|
|
|
|
conf = YAML.load(File::read(conf_path))
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_container(container_id)
|
2015-09-03 14:17:52 +00:00
|
|
|
opts = { 'target' => "docker://#{container_id}" }
|
2015-09-03 12:06:43 +00:00
|
|
|
runner = Vulcano::Runner.new(nil, opts)
|
|
|
|
runner.add_tests(@tests)
|
|
|
|
runner.run
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_image(name)
|
|
|
|
dname = "docker-#{name}:latest"
|
|
|
|
image = @images[dname]
|
|
|
|
raise "Can't find docker image #{dname}" if image.nil?
|
|
|
|
|
2015-09-03 15:24:45 +00:00
|
|
|
puts "--> start docker #{name}"
|
2015-09-03 12:06:43 +00:00
|
|
|
container = Docker::Container.create(
|
|
|
|
'Cmd' => [ '/bin/bash' ],
|
|
|
|
'Image' => image.id,
|
|
|
|
'OpenStdin' => true,
|
|
|
|
)
|
|
|
|
container.start
|
|
|
|
|
2015-09-03 15:24:45 +00:00
|
|
|
puts "--> run test on docker #{name}"
|
2015-09-03 12:06:43 +00:00
|
|
|
res = test_container(container.id)
|
|
|
|
|
2015-09-03 15:24:45 +00:00
|
|
|
puts "--> killrm docker #{name}"
|
2015-09-03 12:06:43 +00:00
|
|
|
container.kill
|
|
|
|
container.delete(force: true)
|
|
|
|
res
|
|
|
|
end
|
|
|
|
end
|
2015-09-03 11:22:15 +00:00
|
|
|
|
2015-09-03 12:06:43 +00:00
|
|
|
DockerTester.new(tests).run
|