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
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_variables ⇒ Object
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
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
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
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
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
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
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
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
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
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
43 44 45 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 43 def has_user?(user) self.user == user end |
#hostname ⇒ Object
55 56 57 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 55 def hostname inspection['Config']['Hostname'] end |
#hosts ⇒ Object
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 |
#image ⇒ Object
18 19 20 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 18 def image inspection['Config']['Image'].split('@')[0] end |
#image_sha ⇒ Object
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
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
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 |
#mounts ⇒ Object
111 112 113 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 111 def mounts inspection['Mounts'] end |
#port_map ⇒ Object
103 104 105 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 103 def port_map inspection['HostConfig']['PortBindings'] end |
#privileged? ⇒ 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
94 95 96 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 94 def publishes_all_ports? inspection['HostConfig']['PublishAllPorts'] end |
#restart_limit ⇒ Object
71 72 73 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 71 def restart_limit inspection['HostConfig']['RestartPolicy']['MaximumRetryCount'] end |
#restart_policy ⇒ Object
79 80 81 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 79 def restart_policy inspection['HostConfig']['RestartPolicy']['Name'] end |
#user ⇒ Object
47 48 49 |
# File 'lib/serverspec_extra_types/types/docker_container.rb', line 47 def user inspection['Config']['User'] end |