Class: Dockerspec::Runner::Base
- Inherits:
-
Object
- Object
- Dockerspec::Runner::Base
- Includes:
- ConfigHelpers
- Defined in:
- lib/dockerspec/runner/base.rb
Overview
A basic class with the minimal skeleton to create a Runner: Classes to start docker containers.
Constant Summary collapse
- OPTIONS_DEFAULT_KEY =
The option key to set when you pass a string instead of a hash of options.
:ignored
Instance Attribute Summary collapse
-
#options ⇒ Hash
readonly
private
Gets the configuration options.
Instance Method Summary collapse
-
#container ⇒ Docker::Container
Gets the internal Docker::Container object.
-
#container_name ⇒ String
Gets the container name.
-
#finalize ⇒ Object
Stops and deletes the Docker Container.
-
#id ⇒ String
Gets the Docker container ID.
-
#image_id ⇒ String
Gets the Docker image ID.
-
#initialize(*opts) ⇒ Dockerspec::Runner::Base
constructor
Constructs a runner class to run Docker images.
-
#ipaddress ⇒ String
Gets the Docker Container IP address.
-
#restore_rspec_context ⇒ Object
Restores the Specinfra backend instance to point to this object's container.
-
#run ⇒ Dockerspec::Runner::Base
Runs the Docker Container.
Methods included from ConfigHelpers
Constructor Details
#initialize(*opts) ⇒ Dockerspec::Runner::Base
Constructs a runner class to run Docker images.
65 66 67 68 69 |
# File 'lib/dockerspec/runner/base.rb', line 65 def initialize(*opts) @options = (opts) @engines = EngineList.new(self) ObjectSpace.define_finalizer(self, proc { finalize }) end |
Instance Attribute Details
#options ⇒ Hash (readonly)
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 configuration options.
47 48 49 |
# File 'lib/dockerspec/runner/base.rb', line 47 def @options end |
Instance Method Details
#container ⇒ Docker::Container
Gets the internal Docker::Container object.
126 127 128 |
# File 'lib/dockerspec/runner/base.rb', line 126 def container raise RunnerError, "#{self.class}#container method must be implemented" end |
#container_name ⇒ String
Gets the container name.
140 141 142 |
# File 'lib/dockerspec/runner/base.rb', line 140 def container_name container.json['Name'] end |
#finalize ⇒ Object
Stops and deletes the Docker Container.
Automatically called when :rm
option is enabled.
203 204 205 206 207 |
# File 'lib/dockerspec/runner/base.rb', line 203 def finalize return if [:rm] == false || container.nil? container.stop container.delete end |
#id ⇒ String
Gets the Docker container ID.
159 160 161 162 |
# File 'lib/dockerspec/runner/base.rb', line 159 def id return nil unless container.respond_to?(:id) container.id end |
#image_id ⇒ String
Gets the Docker image ID.
174 175 176 |
# File 'lib/dockerspec/runner/base.rb', line 174 def image_id container.json['Image'] end |
#ipaddress ⇒ String
Gets the Docker Container IP address.
This is used by Engine::Infrataster.
190 191 192 |
# File 'lib/dockerspec/runner/base.rb', line 190 def ipaddress container.json['NetworkSettings']['IPAddress'] end |
#restore_rspec_context ⇒ Object
Restores the Specinfra backend instance to point to this object's container.
This is used to avoid Serverspec running against the last started container if you are testing multiple containers at the same time.
112 113 114 |
# File 'lib/dockerspec/runner/base.rb', line 112 def restore_rspec_context @engines.restore end |
#run ⇒ Dockerspec::Runner::Base
Runs the Docker Container.
- Sets up the test context.
- Runs the container (or Compose).
- Saves the created underlaying test context.
- Sets the container as ready.
- Waits the required (configured) time after container has been started.
93 94 95 96 97 98 99 100 101 |
# File 'lib/dockerspec/runner/base.rb', line 93 def run before_running start_time = Time.new.utc run_container when_running when_container_ready do_wait((Time.new.utc - start_time).to_i) self end |