Class: Serverspec::Type::DockerContainer

Inherits:
Object
  • Object
show all
Defined in:
lib/serverspec_extra_types/types/docker_container.rb

Overview

This class monkey patches serverspec’s docker container type with some more method to be used in matchers

Instance Method Summary collapse

Instance Method Details

#domain_nameObject



64
65
66
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 64

def domain_name
  inspection['Config']['Domainname']
end

#environment_variable(regex) ⇒ Object



36
37
38
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 36

def environment_variable(regex)
  environment_variables.find { |str| str =~ /^#{regex}=/ }.split('=')[1..-1].join('=')
end

#environment_variablesObject



40
41
42
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 40

def environment_variables
  inspection['Config']['Env']
end

#has_domainname?(domain) ⇒ Boolean

Returns:

  • (Boolean)


60
61
62
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 60

def has_domainname?(domain)
  domain_name == domain
end

#has_environment_variable?(regex, value = nil) ⇒ Boolean

Returns:

  • (Boolean)


28
29
30
31
32
33
34
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 28

def has_environment_variable?(regex, value = nil)
  if value
    environment_variable(regex) == value
  else
    environment_variable(regex)
  end
end

#has_host?(host) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 84

def has_host?(host)
  hosts.include? host
end

#has_hostname?(hostname) ⇒ Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 52

def has_hostname?(hostname)
  self.hostname == hostname
end

#has_image?(image) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 12

def has_image?(image)
  self.image == image
end

#has_image_sha?(image) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 16

def has_image_sha?(image)
  image_sha == image
end

#has_mount?(source, target, type) ⇒ Boolean

Returns:

  • (Boolean)


109
110
111
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 109

def has_mount?(source, target, type)
  mounts.find { |mount| mount['Source'] == source && mount['Destination'] == target && mount['Type'] == type }
end

#has_restart_limit?(limit) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 68

def has_restart_limit?(limit)
  restart_limit == limit
end

#has_restart_policy?(policy) ⇒ Boolean

Returns:

  • (Boolean)


76
77
78
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 76

def has_restart_policy?(policy)
  restart_policy == policy
end

#has_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 44

def has_user?(user)
  self.user == user
end

#hostnameObject



56
57
58
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 56

def hostname
  inspection['Config']['Hostname']
end

#hostsObject



88
89
90
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 88

def hosts
  inspection['HostConfig']['ExtraHosts'].map { |itm| itm.split(':')[1] + ' ' + itm.split(':')[0] }
end

#imageObject



20
21
22
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 20

def image
  inspection['Config']['Image'].split('@')[0]
end

#image_shaObject



24
25
26
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 24

def image_sha
  inspection['Config']['Image'].split('@')[1]
end

#include_regex?Boolean

Returns:

  • (Boolean)


8
9
10
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 8

def include_regex?
  inspection.find { |str| str =~ regex }
end

#map_port?(host, container, protocol = 'tcp') ⇒ Boolean

Returns:

  • (Boolean)


101
102
103
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 101

def map_port?(host, container, protocol = 'tcp')
  inspection['NetworkSettings']['Ports']["#{container}/#{protocol}"][0]['HostPort'] == host
end

#mountsObject



113
114
115
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 113

def mounts
  inspection['Mounts']
end

#port_mapObject



105
106
107
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 105

def port_map
  inspection['HostConfig']['PortBindings']
end

#privileged?Boolean

Returns:

  • (Boolean)


92
93
94
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 92

def privileged?
  inspection['HostConfig']['Privileged']
end

#publishes_all_ports?Boolean

TODO: matcher for this

Returns:

  • (Boolean)


97
98
99
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 97

def publishes_all_ports?
  inspection['HostConfig']['PublishAllPorts']
end

#restart_limitObject



72
73
74
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 72

def restart_limit
  inspection['HostConfig']['RestartPolicy']['MaximumRetryCount']
end

#restart_policyObject



80
81
82
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 80

def restart_policy
  inspection['HostConfig']['RestartPolicy']['Name']
end

#userObject



48
49
50
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 48

def user
  inspection['Config']['User']
end