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



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

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

#environment_variable(regex) ⇒ Object



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

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

#environment_variablesObject



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

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

#has_domainname?(domain) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_domainname?(domain)
  self.domain_name == domain
end

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

Returns:

  • (Boolean)


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

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)


82
83
84
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 82

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

#has_hostname?(hostname) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#has_image?(image) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 10

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

#has_image_sha?(image) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 14

def has_image_sha?(image)
  self.image_sha == image
end

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

Returns:

  • (Boolean)


107
108
109
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 107

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)


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

def has_restart_limit?(limit)
  restart_limit == limit
end

#has_restart_policy?(policy) ⇒ Boolean

Returns:

  • (Boolean)


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

def has_restart_policy?(policy)
  restart_policy == policy
end

#has_user?(user) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#hostnameObject



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

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

#hostsObject



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

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

#imageObject



18
19
20
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 18

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

#image_shaObject



22
23
24
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 22

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

#include_regex?Boolean

Returns:

  • (Boolean)


6
7
8
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 6

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

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

Returns:

  • (Boolean)


99
100
101
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 99

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

#mountsObject



111
112
113
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 111

def mounts
  inspection['Mounts']
end

#port_mapObject



103
104
105
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 103

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

#privileged?Boolean

Returns:

  • (Boolean)


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

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

#publishes_all_ports?Boolean

TODO: matcher for this

Returns:

  • (Boolean)


94
95
96
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 94

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

#restart_limitObject



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

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

#restart_policyObject



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

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

#userObject



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

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