class Dockerspec::Runner::Serverspec::Docker

Runs a Docker container using [Serverspec](serverspec.org/).

Public Class Methods

new(*opts) click to toggle source

Constructs a Docker Serverspec runner class to run Docker images.

@example From a Docker Container Image Tag

Dockerspec::Runner::Serverspec::Docker.new('myapp')
  #=> #<Dockerspec::Runner::Serverspec::Docker:0x0124>

@example From a Docker Container Image Tag Using Hash Format

Dockerspec::Runner::Serverspec::Docker.new(tag: 'myapp')
  #=> #<Dockerspec::Runner::Serverspec::Docker:0x0124>

@example From a Running Docker Container ID

Dockerspec::Runner::Serverspec::Docker.new(id: 'c51f86c28340')
  #=> #<Dockerspec::Runner::Serverspec::Docker:0x0125>

@param opts [String, Hash] The `:tag` or a list of options.

@option opts [String] :tag The Docker image tag name to run. @option opts [String] :id The Docker container ID to use instead of

starting a new container.

@option opts [Boolean] :rm (calculated) Whether to remove the Docker

container afterwards.

@option opts [String] :path The environment `PATH` value of the

container.

@option opts [Hash, Array] :env Some `ENV` instructions to add to the

container.

@option opts [Symbol, String] :family (calculated) The OS family.

It's automatically detected by default, but can be used to
**speed up the tests**. Some possible values:
`:alpine`, `:arch`, `:coreos`, `:debian`, `:gentoo`, `:nixos`,
`:plamo`, `:poky`, `:redhat`, `:suse`.

@option opts [Integer] :wait Time to wait before running the tests. @option opts [Symbol] :backend (calculated) Docker backend to use:

`:docker`, `:lxc`.

@return [Dockerspec::Runner::Serverspec::Docker] Runner object.

@api public

Calls superclass method Dockerspec::Runner::Docker::new
# File lib/dockerspec/runner/serverspec/docker.rb, line 74
def initialize(*opts)
  super
  calculate_docker_backend_name('docker')
end

Public Instance Methods

container() click to toggle source

Gets the internal {Docker::Container} object.

@return [Docker::Container] The container.

@api public

# File lib/dockerspec/runner/serverspec/docker.rb, line 86
def container
  @cached_container ||= begin
    backend = Engine::Specinfra::Backend.new(backend_name)
    backend.backend_instance_attribute(:container)
  end
end

Protected Instance Methods

before_running() click to toggle source

Sets the engines and the Specinfra configuration.

Sets the `:docker_image` or `:docker_container`.

@return void

@api private

Calls superclass method Dockerspec::Runner::Base#before_running
# File lib/dockerspec/runner/serverspec/docker.rb, line 104
def before_running
  super
  Specinfra.configuration.env(options[:env]) if options.key?(:env)
  if source == :id
    Specinfra.configuration.docker_container(id)
  else
    Specinfra.configuration.docker_image(image_id)
  end
end