lib/beaker/hypervisor/docker.rb in beaker-2.5.0 vs lib/beaker/hypervisor/docker.rb in beaker-2.5.1

- old
+ new

@@ -117,19 +117,19 @@ # 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/ - sshd_options = '-o "PermitRootLogin yes" -o "PasswordAuthentication yes"' + 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/ - sshd_options = '-o "PermitRootLogin yes" -o "PasswordAuthentication yes"' dockerfile += <<-EOF RUN apt-get update RUN apt-get install -y openssh-server openssh-client #{Beaker::HostPrebuiltSteps::CUMULUS_PACKAGES.join(' ')} EOF when /^el-/, /centos/, /fedora/, /redhat/, /eos/ @@ -138,15 +138,15 @@ 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/ - sshd_options = '-o "PermitRootLogin yes" -o "PasswordAuthentication yes" -o "UsePAM no"' 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 @@ -155,10 +155,17 @@ 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('') @@ -166,10 +173,11 @@ 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 - cmd = host['docker_cmd'] || "/usr/sbin/sshd -D #{sshd_options}" + # 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