lib/beaker/hypervisor/docker.rb in beaker-2.26.0 vs lib/beaker/hypervisor/docker.rb in beaker-2.27.0
- old
+ new
@@ -166,93 +166,101 @@
def root_password
'root'
end
def dockerfile_for(host)
+ if host['dockerfile'] then
+ @logger.debug("attempting to load user Dockerfile from #{host['dockerfile']}")
+ if File.exist?(host['dockerfile']) then
+ dockerfile = File.read(host['dockerfile'])
+ else
+ raise "requested Dockerfile #{host['dockerfile']} does not exist"
+ end
+ else
+ raise("Docker image undefined!") if (host['image']||= nil).to_s.empty?
- # Warn if image is not define, empty or nil
- @logger.error("Docker image undefined!") if (host['image']||= nil).to_s.empty?
+ # specify base image
+ dockerfile = <<-EOF
+ FROM #{host['image']}
+ EOF
- # specify base image
- dockerfile = <<-EOF
- FROM #{host['image']}
- EOF
+ # additional options to specify to the sshd
+ # may vary by platform
+ sshd_options = ''
- # additional options to specify to the sshd
- # may vary by platform
- sshd_options = ''
+ # add platform-specific actions
+ service_name = "sshd"
+ case host['platform']
+ when /ubuntu/, /debian/
+ service_name = "ssh"
+ dockerfile += <<-EOF
+ RUN apt-get update
+ RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::DEBIAN_PACKAGES.join(' ')}
+ EOF
+ when /cumulus/
+ dockerfile += <<-EOF
+ RUN apt-get update
+ RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::CUMULUS_PACKAGES.join(' ')}
+ EOF
+ when /fedora-22/
+ dockerfile += <<-EOF
+ RUN dnf clean all
+ RUN dnf install -y sudo openssh-server openssh-clients #{Beaker::HostPrebuiltSteps::UNIX_PACKAGES.join(' ')}
+ RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
+ RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
+ EOF
+ when /^el-/, /centos/, /fedora/, /redhat/, /eos/
+ dockerfile += <<-EOF
+ RUN yum clean all
+ RUN yum install -y sudo openssh-server openssh-clients #{Beaker::HostPrebuiltSteps::UNIX_PACKAGES.join(' ')}
+ RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
+ RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
+ EOF
+ when /opensuse/, /sles/
+ dockerfile += <<-EOF
+ RUN zypper -n in openssh #{Beaker::HostPrebuiltSteps::SLES_PACKAGES.join(' ')}
+ RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
+ RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
+ RUN sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config
+ EOF
+ else
+ # TODO add more platform steps here
+ raise "platform #{host['platform']} not yet supported on docker"
+ end
- # add platform-specific actions
- service_name = "sshd"
- case host['platform']
- when /ubuntu/, /debian/
- service_name = "ssh"
+ # Make sshd directory, set root password
dockerfile += <<-EOF
- RUN apt-get update
- RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::DEBIAN_PACKAGES.join(' ')}
+ RUN mkdir -p /var/run/sshd
+ RUN echo root:#{root_password} | chpasswd
EOF
- when /cumulus/
- dockerfile += <<-EOF
- RUN apt-get update
- RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::CUMULUS_PACKAGES.join(' ')}
- EOF
- when /fedora-22/
+
+ # Configure sshd service to allowroot login using password
dockerfile += <<-EOF
- RUN dnf clean all
- RUN dnf install -y sudo openssh-server openssh-clients #{Beaker::HostPrebuiltSteps::UNIX_PACKAGES.join(' ')}
- RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
- RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
+ RUN sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
+ RUN sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
EOF
- when /^el-/, /centos/, /fedora/, /redhat/, /eos/
- dockerfile += <<-EOF
- RUN yum clean all
- RUN yum install -y sudo openssh-server openssh-clients #{Beaker::HostPrebuiltSteps::UNIX_PACKAGES.join(' ')}
- RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
- RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
- EOF
- when /opensuse/, /sles/
- dockerfile += <<-EOF
- RUN zypper -n in openssh #{Beaker::HostPrebuiltSteps::SLES_PACKAGES.join(' ')}
- RUN ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key
- RUN ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key
- RUN sed -ri 's/^#?UsePAM .*/UsePAM no/' /etc/ssh/sshd_config
- EOF
- else
- # TODO add more platform steps here
- raise "platform #{host['platform']} not yet supported on docker"
- end
- # Make sshd directory, set root password
- dockerfile += <<-EOF
- RUN mkdir -p /var/run/sshd
- RUN echo root:#{root_password} | chpasswd
- EOF
- # Configure sshd service to allowroot login using password
- dockerfile += <<-EOF
- RUN sed -ri 's/^#?PermitRootLogin .*/PermitRootLogin yes/' /etc/ssh/sshd_config
- RUN sed -ri 's/^#?PasswordAuthentication .*/PasswordAuthentication yes/' /etc/ssh/sshd_config
- EOF
+ # Any extra commands specified for the host
+ dockerfile += (host['docker_image_commands'] || []).map { |command|
+ "RUN #{command}\n"
+ }.join('')
+ # Override image entrypoint
+ if host['docker_image_entrypoint']
+ dockerfile += "ENTRYPOINT #{host['docker_image_entrypoint']}\n"
+ end
- # Any extra commands specified for the host
- dockerfile += (host['docker_image_commands'] || []).map { |command|
- "RUN #{command}\n"
- }.join('')
+ # How to start a sshd on port 22. May be an init for more supervision
+ # Ensure that the ssh server can be restarted (done from set_env) and container keeps running
+ cmd = host['docker_cmd'] || ["sh","-c","service #{service_name} start ; tail -f /dev/null"]
+ dockerfile += <<-EOF
+ EXPOSE 22
+ CMD #{cmd}
+ EOF
- # Override image entrypoint
- if host['docker_image_entrypoint']
- dockerfile += "ENTRYPOINT #{host['docker_image_entrypoint']}\n"
end
-
- # How to start a sshd on port 22. May be an init for more supervision
- # Ensure that the ssh server can be restarted (done from set_env) and container keeps running
- cmd = host['docker_cmd'] || ["sh","-c","service #{service_name} start ; tail -f /dev/null"]
- dockerfile += <<-EOF
- EXPOSE 22
- CMD #{cmd}
- EOF
-
+
@logger.debug("Dockerfile is #{dockerfile}")
return dockerfile
end
end