Class: Serverspec::Type::DockerContainer
- Inherits:
-
Object
- Object
- Serverspec::Type::DockerContainer
- 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
- #domain_name ⇒ Object
- #environment_variable(regex) ⇒ Object
- #environment_variables ⇒ Object
- #has_domainname?(domain) ⇒ Boolean
- #has_environment_variable?(regex, value = nil) ⇒ Boolean
- #has_host?(host) ⇒ Boolean
- #has_hostname?(hostname) ⇒ Boolean
- #has_image?(image) ⇒ Boolean
- #has_image_sha?(image) ⇒ Boolean
- #has_mount?(source, target, type) ⇒ Boolean
- #has_restart_limit?(limit) ⇒ Boolean
- #has_restart_policy?(policy) ⇒ Boolean
- #has_user?(user) ⇒ Boolean
- #hostname ⇒ Object
- #hosts ⇒ Object
- #image ⇒ Object
- #image_sha ⇒ Object
- #include_regex? ⇒ Boolean
- #map_port?(host, container, protocol = 'tcp') ⇒ Boolean
- #mounts ⇒ Object
- #port_map ⇒ Object
- #privileged? ⇒ Boolean
-
#publishes_all_ports? ⇒ Boolean
TODO: matcher for this.
- #restart_limit ⇒ Object
- #restart_policy ⇒ Object
- #user ⇒ Object
Instance Method Details
#domain_name ⇒ Object
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_variables ⇒ Object
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
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
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
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
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
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
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
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
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
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
44 45 46 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 44 def has_user?(user) self.user == user end |
#hostname ⇒ Object
56 57 58 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 56 def hostname inspection['Config']['Hostname'] end |
#hosts ⇒ Object
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 |
#image ⇒ Object
20 21 22 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 20 def image inspection['Config']['Image'].split('@')[0] end |
#image_sha ⇒ Object
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
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
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 |
#mounts ⇒ Object
113 114 115 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 113 def mounts inspection['Mounts'] end |
#port_map ⇒ Object
105 106 107 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 105 def port_map inspection['HostConfig']['PortBindings'] end |
#privileged? ⇒ 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
97 98 99 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 97 def publishes_all_ports? inspection['HostConfig']['PublishAllPorts'] end |
#restart_limit ⇒ Object
72 73 74 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 72 def restart_limit inspection['HostConfig']['RestartPolicy']['MaximumRetryCount'] end |
#restart_policy ⇒ Object
80 81 82 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 80 def restart_policy inspection['HostConfig']['RestartPolicy']['Name'] end |
#user ⇒ Object
48 49 50 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 48 def user inspection['Config']['User'] end |