Class: DockerContainer
- Inherits:
-
Object
- Object
- DockerContainer
- Includes:
- DockerObject
- Defined in:
- lib/inspec-docker-resources/resources/docker_container.rb
Instance Method Summary collapse
- #command ⇒ Object
-
#has_volume?(destination, source) ⇒ Boolean
has_volume? matcher checks if the volume specified in source path of host is mounted in destination path of docker.
- #image ⇒ Object
-
#initialize(opts = {}) ⇒ DockerContainer
constructor
A new instance of DockerContainer.
- #labels ⇒ Object
- #ports ⇒ Object
- #repo ⇒ Object
- #resource_id ⇒ Object
- #running? ⇒ Boolean
- #status ⇒ Object
- #tag ⇒ Object
- #to_s ⇒ Object
Methods included from DockerObject
Constructor Details
#initialize(opts = {}) ⇒ DockerContainer
Returns a new instance of DockerContainer.
32 33 34 35 36 37 38 39 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 32 def initialize(opts = {}) # if a string is provided, we expect it is the name if opts.is_a?(String) @opts = { name: opts } else @opts = opts end end |
Instance Method Details
#command ⇒ Object
70 71 72 73 74 75 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 70 def command return unless object_info.entries.length == 1 cmd = object_info.commands[0] cmd.slice(1, cmd.length - 2) end |
#has_volume?(destination, source) ⇒ Boolean
has_volume? matcher checks if the volume specified in source path of host is mounted in destination path of docker
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 46 def has_volume?(destination, source) # volume_info is the hash which contains the low-level information about the container # if Mounts key is not present or is nil; raise exception raise Inspec::Exceptions::ResourceFailed, "Could not find any mounted volumes for your container" unless volume_info.Mounts[0] # Iterate through the list of mounted volumes and check if it matches with the given destination and source # is_mounted flag is used to handle to return explict boolean values of true or false is_mounted = false volume_info.Mounts.detect { |mount| is_mounted = mount.Destination == destination && mount.Source == source } is_mounted end |
#image ⇒ Object
77 78 79 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 77 def image object_info.images[0] if object_info.entries.length == 1 end |
#labels ⇒ Object
62 63 64 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 62 def labels object_info.labels end |
#ports ⇒ Object
66 67 68 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 66 def ports object_info.ports[0] if object_info.entries.length == 1 end |
#repo ⇒ Object
81 82 83 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 81 def repo parse_components_from_image(image)[:repo] if object_info.entries.size == 1 end |
#resource_id ⇒ Object
94 95 96 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 94 def resource_id object_info.ids[0] || @opts[:id] || @opts[:name] || "" end |
#running? ⇒ Boolean
41 42 43 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 41 def running? status.downcase.start_with?("up") if object_info.entries.length == 1 end |
#status ⇒ Object
58 59 60 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 58 def status object_info.status[0] if object_info.entries.length == 1 end |
#tag ⇒ Object
85 86 87 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 85 def tag parse_components_from_image(image)[:tag] if object_info.entries.size == 1 end |
#to_s ⇒ Object
89 90 91 92 |
# File 'lib/inspec-docker-resources/resources/docker_container.rb', line 89 def to_s name = @opts[:name] || @opts[:id] "Docker Container #{name}" end |