Class: Dockerspec::Runner::Serverspec::Docker

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

Overview

Runs a Docker container using Serverspec.

Constant Summary

Constants inherited from Docker

Docker::OPTIONS_DEFAULT_KEY

Constants inherited from Base

Base::OPTIONS_DEFAULT_KEY

Instance Attribute Summary

Attributes included from Base

#backend_name

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods included from Base

#finalize, #to_s

Methods inherited from Docker

#image_id, #to_s

Methods included from Helper::MultipleSourcesDescription

#description

Methods inherited from Base

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

Methods included from ConfigHelpers

#parse_log, #stderr, #stdout

Constructor Details

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

Constructs a Docker Serverspec runner class to run Docker images.

Examples:

From a Docker Container Image Tag

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

From a Docker Container Image Tag Using Hash Format

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

From a Running Docker Container ID

Dockerspec::Runner::Serverspec::Docker.new(id: 'c51f86c28340')
  #=> #<Dockerspec::Runner::Serverspec::Docker: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.

  • :family (Symbol, String) — default: 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.

  • :wait (Integer)

    Time to wait before running the tests.

  • :backend (Symbol) — default: calculated

    Docker backend to use: :docker, :lxc.



74
75
76
77
# File 'lib/dockerspec/runner/serverspec/docker.rb', line 74

def initialize(*opts)
  super
  calculate_docker_backend_name('docker')
end

Instance Method Details

#containerDocker::Container

Gets the internal Docker::Container object.

Returns:

  • (Docker::Container)

    The container.



86
87
88
89
90
91
# 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