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

#arch_platformObject


44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 44

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

#debian_platformObject


57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 57

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


117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 117

def dockerfile_base_linux(username, homedir)
  <<-CODE
    RUN if ! getent passwd #{username}; then \
          useradd -d #{homedir} -m -s /bin/bash -p '*' #{username}; \
        fi
    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
# 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', 'almalinux', 'rockylinux'
    rhel_platform
  else
    raise ActionFailed, "Unknown platform '#{config[:platform]}'"
  end
end

#fedora_platformObject


71
72
73
74
75
76
77
78
79
# File 'lib/kitchen/docker/helpers/dockerfile_helper.rb', line 71

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


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

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


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

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


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

def opensuse_platform
  <<-CODE
    ENV container docker
    RUN zypper install -y sudo openssh which curl
    RUN /usr/sbin/sshd-gen-keys-start
  CODE
end

#rhel_platformObject


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

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