Class: Dockerspec::Runner::Docker

Inherits:
Base
  • Object
show all
Includes:
Helper::MultipleSourcesDescription
Defined in:
lib/dockerspec/runner/docker.rb

Overview

This class runs a docker image (without using Serverspec for that).

This class is used mainly when you are not using Serverspec to run the tests.

Direct Known Subclasses

Serverspec::Docker

Constant Summary collapse

OPTIONS_DEFAULT_KEY =

Returns The option key to set when you pass a string instead of a hash of options.

Returns:

  • (Symbol)

    The option key to set when you pass a string instead of a hash of options.

:tag

Instance Attribute Summary collapse

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods included from Helper::MultipleSourcesDescription

#description

Methods inherited from Base

#container_name, #finalize, #id, #ipaddress, #restore_rspec_context, #run

Methods included from ConfigHelpers

#parse_log, #stderr, #stdout

Constructor Details

#initialize(*opts) ⇒ Dockerspec::Runner::Docker

Constructs a Docker runner class to run Docker images.

Examples:

From a Running Docker Image

Dockerspec::Runner::Docker.new('debian:8')
  #=> #<Dockerspec::Runner::Docker:0x0124>

From a Running Docker Container ID

# This does not start any new container
Dockerspec::Runner::Docker.new(id: 'c51f86c28340')
  #=> #<Dockerspec::Runner::Docker:0x0124>

From a Running Docker Container Image Name

Dockerspec::Runner::Docker.new('my-debian')
  #=> #<Dockerspec::Runner:0x0125>

Parameters:

  • opts (String, Hash)

    The :tag or a list of options.

Options Hash (*opts):

  • :tag (String)

    The Docker image tag name to run.

  • :id (String)

    The Docker container ID to use instead of starting a new container.

  • :rm (Boolean) — default: calculated

    Whether to remove the Docker container afterwards.

  • :path (String)

    The environment PATH value of the container.

  • :env (Hash, Array)

    Some ENV instructions to add to the container.

  • :wait (Integer)

    Time to wait before running the tests.

Raises:



91
92
93
94
# File 'lib/dockerspec/runner/docker.rb', line 91

def initialize(*opts)
  super
  send("setup_from_#{source}", options[source])
end

Instance Attribute Details

#containerDocker::Container (readonly)

The internal Docker::Container object.

Returns:

  • (Docker::Container)

    The container.



51
52
53
# File 'lib/dockerspec/runner/docker.rb', line 51

def container
  @container
end

Instance Method Details

#image_idString

Gets the Docker image ID.

Examples:

builder = Dockerspec::Builder.new('.').build
runner = Dockerspec::Runner::Docker.new(builder)
runner.image_id #=> "c51f86c28340[...]"

Returns:

  • (String)

    Image ID.



108
109
110
111
# File 'lib/dockerspec/runner/docker.rb', line 108

def image_id
  return @build.id unless @build.nil?
  super
end

#to_sString

Gets a descriptions of the object.

Examples:

Running from a Container Image ID

r = Dockerspec::Runner::Docker.new('debian')
r.to_s #=> "Docker Run from tag: \"debian\""

Attaching to a Running Container ID

r = Dockerspec::Runner::Docker.new(id: '92cc98ab560a')
r.to_s #=> "Docker Run from id: \"92cc98ab560a\""

Returns:

  • (String)

    The object description.



128
129
130
# File 'lib/dockerspec/runner/docker.rb', line 128

def to_s
  description('Docker Run from')
end