Class: Dockerspec::Runner
- Inherits:
-
Object
- Object
- Dockerspec::Runner
- Includes:
- Helper::MultipleSourcesDescription
- Defined in:
- lib/dockerspec/runner.rb
Overview
This class runs a docker image (without using Serverspec for that).
This class is not used much, only inherited by Serverspec::Runner, which uses Serverspec to run the images. Some of the methods here are used there, others not.
Direct Known Subclasses
Instance Method Summary collapse
-
#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
constructor
Constructs a Docker runner class to run Docker images.
-
#run ⇒ Dockerspec::Runner
Runs the Docker Container.
-
#to_s ⇒ String
Gets a descriptions of the object.
Methods included from Helper::MultipleSourcesDescription
Constructor Details
#initialize(*opts) ⇒ Dockerspec::Runner
Constructs a Docker runner class to run Docker images.
67 68 69 70 71 |
# File 'lib/dockerspec/runner.rb', line 67 def initialize(*opts) @options = (opts) send("setup_from_#{source}", @options[source]) ObjectSpace.define_finalizer(self, proc { finalize }) end |
Instance Method Details
#finalize ⇒ Object
Stops and deletes the Docker Container.
Automatically called when :rm
option is enabled.
135 136 137 138 139 |
# File 'lib/dockerspec/runner.rb', line 135 def finalize return unless @options[:rm] && !@container.nil? @container.stop @container.delete end |
#id ⇒ String
Gets the Docker container ID.
104 105 106 107 |
# File 'lib/dockerspec/runner.rb', line 104 def id return nil unless @container.respond_to?(:id) @container.id end |
#image_id ⇒ String
Gets the Docker image ID.
121 122 123 124 |
# File 'lib/dockerspec/runner.rb', line 121 def image_id return @build.id unless @build.nil? @container.json['Image'] end |
#run ⇒ Dockerspec::Runner
Runs the Docker Container.
86 87 88 89 90 |
# File 'lib/dockerspec/runner.rb', line 86 def run create_container run_container self end |
#to_s ⇒ String
Gets a descriptions of the object.
156 157 158 |
# File 'lib/dockerspec/runner.rb', line 156 def to_s description('Docker Run from') end |