Class: Dockerspec::Runner::Compose
- Includes:
- Helper::MultipleSourcesDescription
- Defined in:
- lib/dockerspec/runner/compose.rb
Overview
This class runs Docker Compose (without using Serverspec for that).
This class is used mainly when you are not using Serverspec to run the tests.
Direct Known Subclasses
Constant Summary collapse
- OPTIONS_DEFAULT_KEY =
Returns The option key to set when you pass a string instead of a hash of options.
:file
Class Attribute Summary collapse
-
.current_instance ⇒ Docker::Runner::Compose::Base
Saves the latest created Compose object.
Instance Attribute Summary collapse
-
#compose ⇒ DockerCompose
readonly
The internal DockerCompose object.
Instance Method Summary collapse
-
#container ⇒ Docker::Container
Gets the selected container object.
-
#container_name ⇒ String?
private
Gets the selected container name.
-
#finalize ⇒ Object
Stops and deletes the Docker Compose containers.
-
#initialize(*opts) ⇒ Dockerspec::Runner::Compose
constructor
Constructs a runner class to run Docker Compose.
-
#options ⇒ Object
private
Returns general and container specific options merged.
-
#run ⇒ Dockerspec::Runner::Compose
Does not call ready because container is still not ready.
-
#select_container(name, opts = nil) ⇒ Object
Selects the container to test and sets its configuration options.
-
#to_s ⇒ String
Gets a descriptions of the object.
Methods included from Helper::MultipleSourcesDescription
Methods inherited from Base
#id, #image_id, #ipaddress, #restore_rspec_context
Methods included from ConfigHelpers
Constructor Details
#initialize(*opts) ⇒ Dockerspec::Runner::Compose
Constructs a runner class to run Docker Compose.
89 90 91 92 93 94 |
# File 'lib/dockerspec/runner/compose.rb', line 89 def initialize(*opts) Compose.current_instance = self @container_options = {} super setup_from_file(file) end |
Class Attribute Details
.current_instance ⇒ Docker::Runner::Compose::Base
Saves the latest created Dockerspec::Runner::Compose object.
42 43 44 |
# File 'lib/dockerspec/runner/compose.rb', line 42 def current_instance @current_instance end |
Instance Attribute Details
#compose ⇒ DockerCompose (readonly)
The internal DockerCompose object.
58 59 60 |
# File 'lib/dockerspec/runner/compose.rb', line 58 def compose @compose end |
Instance Method Details
#container ⇒ Docker::Container
Gets the selected container object.
This method is used in Base to get information from the container: ID, image ID, ...
178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/dockerspec/runner/compose.rb', line 178 def container if container_name.nil? raise RunnerError, 'Use `its_container` to select a container to test.' end compose_container = compose.containers[container_name] if compose_container.nil? raise RunnerError, "Container not found: #{compose_container.inspect}" end compose_container.container end |
#container_name ⇒ String?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Gets the selected container name.
160 161 162 163 |
# File 'lib/dockerspec/runner/compose.rb', line 160 def container_name return nil if @options[:container].nil? @options[:container].to_s end |
#finalize ⇒ Object
Stops and deletes the Docker Compose containers.
Automatically called when :rm
option is enabled.
219 220 221 222 223 |
# File 'lib/dockerspec/runner/compose.rb', line 219 def finalize return if [:rm] == false || compose.nil? compose.stop compose.delete end |
#options ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns general and container specific options merged.
148 149 150 151 |
# File 'lib/dockerspec/runner/compose.rb', line 148 def container_name = @options[:container] @container_options[container_name] || @options end |
#run ⇒ Dockerspec::Runner::Compose
Does not call ready because container is still not ready.
Runs the Docker Container.
- Sets up the test context.
- Runs the container (or Compose).
- Saves the created underlaying test context.
112 113 114 115 116 117 118 119 |
# File 'lib/dockerspec/runner/compose.rb', line 112 def run before_running start_time = Time.new.utc run_container when_running do_wait((Time.new.utc - start_time).to_i) self end |
#select_container(name, opts = nil) ⇒ Object
Selects the container to test and sets its configuration options.
Also sets the selected container as ready in the underlaying test engines.
135 136 137 138 139 |
# File 'lib/dockerspec/runner/compose.rb', line 135 def select_container(name, opts = nil) @options[:container] = name @container_options[name] = @options.merge(opts) if opts.is_a?(Hash) when_container_ready end |
#to_s ⇒ String
Gets a descriptions of the object.
206 207 208 |
# File 'lib/dockerspec/runner/compose.rb', line 206 def to_s description('Docker Compose Run from') end |