Module: Kitchen::Docker::Helpers::DockerfileHelper
- Includes:
- Configurable
- Included in:
- Container::Linux
- Defined in:
- lib/kitchen/docker/helpers/dockerfile_helper.rb
Overview
Per-distribution Dockerfile fragments that prepare a Linux image for SSH.
Instance Method Summary collapse
-
#almalinux_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on AlmaLinux.
-
#amazonlinux_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Amazon Linux.
-
#arch_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Arch Linux.
-
#centosstream_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on CentOS Stream.
-
#debian_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Debian and Ubuntu.
-
#dockerfile_base_linux(username, homedir) ⇒ String
Dockerfile lines creating the login user and its SSH directory.
-
#dockerfile_platform ⇒ String
Dockerfile lines that prepare the configured platform for SSH.
-
#fedora_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Fedora.
-
#gentoo_paludis_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Gentoo with Paludis.
-
#gentoo_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Gentoo with Portage.
-
#opensuse_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on openSUSE and SLES.
-
#photonos_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Photon OS.
-
#rhel_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on RHEL, CentOS, and Oracle Linux.
-
#rockylinux_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Rocky Linux.
Instance Method Details
#almalinux_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on AlmaLinux.
178 179 180 181 182 183 184 185 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 178 def almalinux_platform <<-CODE ENV container=docker RUN yum clean all RUN yum install -y sudo openssh-server openssh-clients which RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' CODE end |
#amazonlinux_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Amazon Linux.
154 155 156 157 158 159 160 161 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 154 def amazonlinux_platform <<-CODE ENV container=docker RUN yum clean all RUN yum install -y --allowerasing sudo openssh-server openssh-clients which curl RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' CODE end |
#arch_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Arch Linux.
67 68 69 70 71 72 73 74 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 67 def arch_platform <<-CODE RUN pacman --noconfirm -Sy archlinux-keyring RUN pacman-db-upgrade RUN pacman --noconfirm -Syu openssl openssh sudo curl RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key CODE end |
#centosstream_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on CentOS Stream.
166 167 168 169 170 171 172 173 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 166 def centosstream_platform <<-CODE ENV container=docker RUN yum clean all RUN yum install -y sudo openssh-server openssh-clients which RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' CODE end |
#debian_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Debian and Ubuntu.
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 79 def debian_platform disable_upstart = <<-CODE RUN [ ! -f "/sbin/initctl" ] || dpkg-divert --local --rename --add /sbin/initctl \ && ln -sf /bin/true /sbin/initctl CODE packages = <<-CODE ENV DEBIAN_FRONTEND=noninteractive ENV container=docker RUN apt-get update RUN apt-get install -y sudo openssh-server curl lsb-release CODE config[:disable_upstart] ? disable_upstart + packages : packages end |
#dockerfile_base_linux(username, homedir) ⇒ String
Dockerfile lines creating the login user and its SSH directory.
The user gets passwordless sudo and Defaults !requiretty, because Test
Kitchen runs commands non-interactively and sudo would otherwise refuse.
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 220 def dockerfile_base_linux(username, homedir) <<-CODE RUN if ! getent passwd #{username}; then \ useradd -d #{homedir} -m -s /bin/bash -p '*' #{username}; \ fi RUN mkdir -p /etc/sudoers.d RUN chmod 0750 /etc/sudoers.d RUN echo "#{username} ALL=(ALL) NOPASSWD: ALL" >> /etc/sudoers.d/#{username} RUN echo "Defaults !requiretty" >> /etc/sudoers.d/#{username} RUN mkdir -p #{homedir}/.ssh RUN chown -R #{username} #{homedir}/.ssh RUN chmod 0700 #{homedir}/.ssh RUN touch #{homedir}/.ssh/authorized_keys RUN chown #{username} #{homedir}/.ssh/authorized_keys RUN chmod 0600 #{homedir}/.ssh/authorized_keys RUN mkdir -p /run/sshd CODE end |
#dockerfile_platform ⇒ String
Dockerfile lines that prepare the configured platform for SSH.
Each distribution needs its own package manager invocation to install an SSH server and sudo, and its own host-key generation, which is why there is one method per family rather than a shared one.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 33 def dockerfile_platform case config[:platform] when "arch" arch_platform when "debian", "ubuntu" debian_platform when "fedora" fedora_platform when "gentoo" gentoo_platform when "gentoo-paludis" gentoo_paludis_platform when "opensuse/tumbleweed", "opensuse/leap", "opensuse", "sles" opensuse_platform when "rhel", "centos", "oraclelinux" rhel_platform when "amazonlinux" amazonlinux_platform when "centosstream" centosstream_platform when "almalinux" almalinux_platform when "rockylinux" rockylinux_platform when "photon" photonos_platform else raise ActionFailed, "Unknown platform '#{config[:platform]}'" end end |
#fedora_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Fedora.
96 97 98 99 100 101 102 103 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 96 def fedora_platform <<-CODE ENV container=docker RUN dnf clean all RUN dnf install -y sudo openssh-server openssh-clients which curl RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' CODE end |
#gentoo_paludis_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Gentoo with Paludis.
119 120 121 122 123 124 125 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 119 def gentoo_paludis_platform <<-CODE RUN cave sync RUN cave resolve -zx net-misc/openssh app-admin/sudo RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key CODE end |
#gentoo_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Gentoo with Portage.
108 109 110 111 112 113 114 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 108 def gentoo_platform <<-CODE RUN emerge-webrsync RUN emerge --quiet --noreplace net-misc/openssh app-admin/sudo RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key CODE end |
#opensuse_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on openSUSE and SLES.
130 131 132 133 134 135 136 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 130 def opensuse_platform <<-CODE ENV container=docker RUN zypper install -y sudo openssh which curl gawk RUN /usr/sbin/sshd-gen-keys-start CODE end |
#photonos_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Photon OS.
202 203 204 205 206 207 208 209 210 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 202 def photonos_platform <<-CODE ENV container=docker RUN tdnf clean all RUN tdnf install -y sudo openssh-server openssh-clients which curl RUN [ -f "/etc/ssh/ssh_host_ecdsa_key" ] || ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' RUN [ -f "/etc/ssh/ssh_host_ed25519_key" ] || ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N '' CODE end |
#rhel_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on RHEL, CentOS, and Oracle Linux.
141 142 143 144 145 146 147 148 149 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 141 def rhel_platform <<-CODE ENV container=docker RUN yum clean all RUN yum install -y sudo openssh-server openssh-clients which RUN which curl || yum install -y curl RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' CODE end |
#rockylinux_platform ⇒ String
Dockerfile lines installing an SSH server and sudo on Rocky Linux.
190 191 192 193 194 195 196 197 |
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 190 def rockylinux_platform <<-CODE ENV container=docker RUN yum clean all RUN yum install -y sudo openssh-server openssh-clients which RUN [ -f "/etc/ssh/ssh_host_rsa_key" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' CODE end |