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

Instance Method Details

#almalinux_platformString

Dockerfile lines installing an SSH server and sudo on AlmaLinux.

Returns:

  • (String)

    the RUN lines



178
179
180
181
182
183
184
185
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 178

def almalinux_platform
  "    ENV container=docker\n    RUN yum clean all\n    RUN yum install -y sudo openssh-server openssh-clients which\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''\n  CODE\nend\n"

#amazonlinux_platformString

Dockerfile lines installing an SSH server and sudo on Amazon Linux.

Returns:

  • (String)

    the RUN lines



154
155
156
157
158
159
160
161
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 154

def amazonlinux_platform
  "    ENV container=docker\n    RUN yum clean all\n    RUN yum install -y --allowerasing sudo openssh-server openssh-clients which curl\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''\n  CODE\nend\n"

#arch_platformString

Dockerfile lines installing an SSH server and sudo on Arch Linux.

Returns:

  • (String)

    the RUN lines



67
68
69
70
71
72
73
74
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 67

def arch_platform
  "    RUN pacman --noconfirm -Sy archlinux-keyring\n    RUN pacman-db-upgrade\n    RUN pacman --noconfirm -Syu openssl openssh sudo curl\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key\n  CODE\nend\n"

#centosstream_platformString

Dockerfile lines installing an SSH server and sudo on CentOS Stream.

Returns:

  • (String)

    the RUN lines



166
167
168
169
170
171
172
173
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 166

def centosstream_platform
  "    ENV container=docker\n    RUN yum clean all\n    RUN yum install -y sudo openssh-server openssh-clients which\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''\n  CODE\nend\n"

#debian_platformString

Dockerfile lines installing an SSH server and sudo on Debian and Ubuntu.

Returns:

  • (String)

    the RUN lines



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 = "    RUN [ ! -f \"/sbin/initctl\" ] || dpkg-divert --local --rename --add /sbin/initctl \\\n        && ln -sf /bin/true /sbin/initctl\n  CODE\n  packages = <<-CODE\n    ENV DEBIAN_FRONTEND=noninteractive\n    ENV container=docker\n    RUN apt-get update\n    RUN apt-get install -y sudo openssh-server curl lsb-release\n  CODE\n  config[:disable_upstart] ? disable_upstart + packages : packages\nend\n"

#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.

Parameters:

  • username (String)

    the login user to create

  • homedir (String)

    that user's home directory

Returns:

  • (String)

    the RUN lines



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)
  "    RUN if ! getent passwd \#{username}; then \\\n          useradd -d \#{homedir} -m -s /bin/bash -p '*' \#{username}; \\\n        fi\n    RUN mkdir -p /etc/sudoers.d\n    RUN chmod 0750 /etc/sudoers.d\n    RUN echo \"\#{username} ALL=(ALL) NOPASSWD: ALL\" >> /etc/sudoers.d/\#{username}\n    RUN echo \"Defaults !requiretty\" >> /etc/sudoers.d/\#{username}\n    RUN mkdir -p \#{homedir}/.ssh\n    RUN chown -R \#{username} \#{homedir}/.ssh\n    RUN chmod 0700 \#{homedir}/.ssh\n    RUN touch \#{homedir}/.ssh/authorized_keys\n    RUN chown \#{username} \#{homedir}/.ssh/authorized_keys\n    RUN chmod 0600 \#{homedir}/.ssh/authorized_keys\n    RUN mkdir -p /run/sshd\n  CODE\nend\n"

#dockerfile_platformString

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.

Returns:

  • (String)

    the RUN lines for this platform

Raises:

  • (Kitchen::ActionFailed)

    if the platform is not recognised



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_platformString

Dockerfile lines installing an SSH server and sudo on Fedora.

Returns:

  • (String)

    the RUN lines



96
97
98
99
100
101
102
103
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 96

def fedora_platform
  "    ENV container=docker\n    RUN dnf clean all\n    RUN dnf install -y sudo openssh-server openssh-clients which curl\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''\n  CODE\nend\n"

#gentoo_paludis_platformString

Dockerfile lines installing an SSH server and sudo on Gentoo with Paludis.

Returns:

  • (String)

    the RUN lines



119
120
121
122
123
124
125
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 119

def gentoo_paludis_platform
  "    RUN cave sync\n    RUN cave resolve -zx net-misc/openssh app-admin/sudo\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key\n  CODE\nend\n"

#gentoo_platformString

Dockerfile lines installing an SSH server and sudo on Gentoo with Portage.

Returns:

  • (String)

    the RUN lines



108
109
110
111
112
113
114
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 108

def gentoo_platform
  "    RUN emerge-webrsync\n    RUN emerge --quiet --noreplace net-misc/openssh app-admin/sudo\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -A -t rsa -f /etc/ssh/ssh_host_rsa_key\n  CODE\nend\n"

#opensuse_platformString

Dockerfile lines installing an SSH server and sudo on openSUSE and SLES.

Returns:

  • (String)

    the RUN lines



130
131
132
133
134
135
136
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 130

def opensuse_platform
  "    ENV container=docker\n    RUN zypper install -y sudo openssh which curl gawk\n    RUN /usr/sbin/sshd-gen-keys-start\n  CODE\nend\n"

#photonos_platformString

Dockerfile lines installing an SSH server and sudo on Photon OS.

Returns:

  • (String)

    the RUN lines



202
203
204
205
206
207
208
209
210
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 202

def photonos_platform
  "    ENV container=docker\n    RUN tdnf clean all\n    RUN tdnf install -y sudo openssh-server openssh-clients which curl\n    RUN [ -f \"/etc/ssh/ssh_host_ecdsa_key\" ] || ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''\n    RUN [ -f \"/etc/ssh/ssh_host_ed25519_key\" ] || ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''\n  CODE\nend\n"

#rhel_platformString

Dockerfile lines installing an SSH server and sudo on RHEL, CentOS, and Oracle Linux.

Returns:

  • (String)

    the RUN lines



141
142
143
144
145
146
147
148
149
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 141

def rhel_platform
  "    ENV container=docker\n    RUN yum clean all\n    RUN yum install -y sudo openssh-server openssh-clients which\n    RUN which curl || yum install -y curl\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''\n  CODE\nend\n"

#rockylinux_platformString

Dockerfile lines installing an SSH server and sudo on Rocky Linux.

Returns:

  • (String)

    the RUN lines



190
191
192
193
194
195
196
197
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 190

def rockylinux_platform
  "    ENV container=docker\n    RUN yum clean all\n    RUN yum install -y sudo openssh-server openssh-clients which\n    RUN [ -f \"/etc/ssh/ssh_host_rsa_key\" ] || ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''\n  CODE\nend\n"