2015-09-08 15:58:32 +00:00
|
|
|
# encoding: utf-8
|
|
|
|
require 'docker'
|
|
|
|
|
|
|
|
module Vulcano::Backends
|
|
|
|
class Docker < Vulcano.backend(1)
|
|
|
|
name 'docker'
|
|
|
|
|
2015-09-22 17:32:48 +00:00
|
|
|
attr_reader :os
|
2015-09-08 15:58:32 +00:00
|
|
|
def initialize(conf)
|
|
|
|
@conf = conf
|
|
|
|
@files = {}
|
|
|
|
id = @conf['host'] ||
|
2015-09-09 10:13:13 +00:00
|
|
|
fail('You must specify a docker container ID.')
|
2015-09-08 15:58:32 +00:00
|
|
|
@container = ::Docker::Container.get(id) ||
|
2015-09-09 10:13:13 +00:00
|
|
|
fail("Can't find Docker container #{id}")
|
2015-09-22 17:32:48 +00:00
|
|
|
@os = OS.new(self)
|
2015-09-08 15:58:32 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def file(path)
|
|
|
|
@files[path] ||= LinuxFile.new(self, path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def run_command(cmd)
|
|
|
|
stdout, stderr, exit_status = @container.exec([
|
|
|
|
'/bin/sh', '-c', cmd
|
|
|
|
])
|
|
|
|
CommandResult.new(stdout.join, stderr.join, exit_status)
|
2015-09-09 10:13:13 +00:00
|
|
|
rescue ::Docker::Error::DockerError => _
|
2015-09-08 15:58:32 +00:00
|
|
|
raise
|
2015-09-09 10:13:13 +00:00
|
|
|
rescue => _
|
2015-09-08 15:58:32 +00:00
|
|
|
# @TODO: differentiate any other error
|
|
|
|
raise
|
|
|
|
end
|
2015-09-22 17:32:48 +00:00
|
|
|
|
|
|
|
class OS < OSCommon
|
|
|
|
def initialize(backend)
|
|
|
|
# hardcoded to unix/linux for now, until other operating systems
|
|
|
|
# are supported
|
|
|
|
super(backend, { family: 'unix' })
|
|
|
|
end
|
|
|
|
end
|
2015-09-08 15:58:32 +00:00
|
|
|
end
|
|
|
|
end
|