lib/kitchen/driver/docker.rb in kitchen-docker-0.1.0.dev vs lib/kitchen/driver/docker.rb in kitchen-docker-0.1.1.dev
- old
+ new
@@ -27,10 +27,11 @@
#
# @author Sean Porter <portertech@gmail.com>
class Docker < Kitchen::Driver::SSHBase
default_config :image, 'ubuntu'
+ default_config :platform, 'ubuntu'
default_config :port, '22'
default_config :username, 'kitchen'
default_config :password, 'kitchen'
default_config :require_chef_omnibus, 'latest'
@@ -48,23 +49,49 @@
end
protected
def dockerfile
- path = File.join(File.dirname(__FILE__), 'docker', 'Dockerfile')
- File.expand_path(path)
+ from = "FROM #{config[:image]}"
+ platform = case config[:platform]
+ when 'debian', 'ubuntu'
+ <<-eos
+ ENV DEBIAN_FRONTEND noninteractive
+ RUN apt-get update
+ RUN apt-get install -y sudo openssh-server
+ eos
+ when 'rhel', 'centos'
+ <<-eos
+ RUN yum clean all
+ RUN yum install -y sudo openssh-server openssh-clients
+ RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
+ RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
+ eos
+ else
+ raise ActionFailed,
+ "Unknown platform '#{config[:platform]}'"
+ end
+ base = <<-eos
+ RUN mkdir /var/run/sshd
+ RUN echo '127.0.0.1 localhost.localdomain localhost' >> /etc/hosts
+ RUN useradd -d /home/kitchen -m -s /bin/bash kitchen
+ RUN echo kitchen:kitchen | chpasswd
+ RUN echo 'kitchen ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
+ eos
+ [from, platform, base].join("\n")
end
def parse_image_id(output)
output.each_line do |line|
return line.split(/\s+/).last if line =~ /image id/i
end
- raise ActionFailed, 'Could not parse Docker build output for image ID'
+ raise ActionFailed,
+ 'Could not parse Docker build output for image ID'
end
def build_image(state)
- output = run_command("cat #{dockerfile} | docker build -")
+ output = run_command("docker build -", :input => dockerfile)
parse_image_id(output)
end
def parse_container_id(output)
container_id = output.chomp
@@ -75,10 +102,11 @@
container_id
end
def run_container(state)
image_id = state[:image_id]
- output = run_command("docker run -d #{image_id} /usr/sbin/sshd -D -u0")
+ cmd = "docker run -d #{image_id} /usr/sbin/sshd -D -o UseDNS=no -o UsePAM=no"
+ output = run_command(cmd)
parse_container_id(output)
end
def parse_container_ip(output)
begin