Class: Specinfra::Backend::DockerCompose

Inherits:
Exec
  • Object
show all
Defined in:
lib/specinfra/backend/docker_compose.rb

Overview

Specinfra and Serverspec backend for Docker Compose.

Direct Known Subclasses

DockerComposeLxc

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ DockerCompose

Constructs a Docker Compose Specinfra Backend.

Parameters:

  • config (Hash) (defaults to: {})

    Configuration options.

Options Hash (config):

  • docker_compose_file: (String)

    Docker Compose configuration file path (required).

  • docker_compose_container: (String)

    The name of the container you want to test (required). Only one can be tested.

  • docker_wait: (Fixnum)

    Seconds to wait for containers to start (i.e., time to sleep before running the tests) (recommended).


40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/specinfra/backend/docker_compose.rb', line 40

def initialize(config = {})
  super

  ::Docker.url = get_config(:docker_url)

  file = get_config(:docker_compose_file)
  fail 'Please specify docker_compose_file.' unless file

  @compose = ::DockerCompose.load(file)
  ObjectSpace.define_finalizer(self, proc { finalize })
  Dir.chdir(::File.dirname(file)) { do_start }
end

Instance Method Details

#add_pre_command(cmd) ⇒ String

Adds a prefix or previous instruction to the command.

Does nothing.

Parameters:

  • cmd (String)

    The command to run.

Returns:

  • (String)

    The command.


83
84
85
# File 'lib/specinfra/backend/docker_compose.rb', line 83

def add_pre_command(cmd)
  cmd
end

#build_command(cmd) ⇒ String

Builds a command.

Does nothing.

Parameters:

  • cmd (String)

    The command to run.

Returns:

  • (String)

    The command.


72
73
74
# File 'lib/specinfra/backend/docker_compose.rb', line 72

def build_command(cmd)
  cmd
end

#run_command(cmd, opts = {}) ⇒ Object

Runs a Specinfra command.

Parameters:

  • cmd (String)

    The command to run.

  • opts (Hash) (defaults to: {})

    Options to pass to Docker::Container#exec.

Returns:

  • nil


59
60
61
62
63
# File 'lib/specinfra/backend/docker_compose.rb', line 59

def run_command(cmd, opts = {})
  cmd = build_command(cmd)
  cmd = add_pre_command(cmd)
  docker_compose_run!(cmd, opts)
end

#send_file(_from, _to) ⇒ Object

Note:

Not implemented yet.

Sends a file.

Parameters:

  • _from (String)

    The file origin.

  • _to (String)

    The file destination.

Returns:

  • nil

Raises:

  • (RuntimeError)

    Always raises an error.


95
96
97
# File 'lib/specinfra/backend/docker_compose.rb', line 95

def send_file(_from, _to)
  fail 'docker_compose does not support send_file'
end