Module: Kitchen::Docker::Helpers::DockerfileHelper

Includes:
Configurable
Included in:
Container::Linux
Defined in:
lib/kitchen/docker/helpers/dockerfile_helper.rb

Instance Method Summary collapse

Instance Method Details

#almalinux_platformObject



135
136
137
138
139
140
141
142
143
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 135

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 ''
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
  CODE
end

#arch_platformObject



52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 52

def arch_platform
  # See https://bugs.archlinux.org/task/47052 for why we
  # blank out limits.conf.
  <<-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
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
    RUN echo >/etc/security/limits.conf
  CODE
end

#centosstream_platformObject



125
126
127
128
129
130
131
132
133
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 125

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 ''
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
  CODE
end

#debian_platformObject



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

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) ⇒ Object



165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 165

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_platformObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 23

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', 'amazonlinux'
    rhel_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_platformObject



79
80
81
82
83
84
85
86
87
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 79

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 ''
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
  CODE
end

#gentoo_paludis_platformObject



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

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
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
  CODE
end

#gentoo_platformObject



89
90
91
92
93
94
95
96
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 89

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
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -A -t dsa -f /etc/ssh/ssh_host_dsa_key
  CODE
end

#opensuse_platformObject



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

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_platformObject



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

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_platformObject



115
116
117
118
119
120
121
122
123
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 115

def rhel_platform
  <<-CODE
    ENV container docker
    RUN yum clean all
    RUN yum 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 ''
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
  CODE
end

#rockylinux_platformObject



145
146
147
148
149
150
151
152
153
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 145

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 ''
    RUN [ -f "/etc/ssh/ssh_host_dsa_key" ] || ssh-keygen -t dsa -f /etc/ssh/ssh_host_dsa_key -N ''
  CODE
end