Class: Wrapbox::Runner::Docker

Inherits:
Object
  • Object
show all
Defined in:
lib/wrapbox/runner/docker.rb

Defined Under Namespace

Classes: Cli, ExecutionError

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Docker

Returns a new instance of Docker.



16
17
18
19
20
# File 'lib/wrapbox/runner/docker.rb', line 16

def initialize(options)
  @name = options[:name]
  @container_definition = options[:container_definition]
  @keep_container = options[:keep_container]
end

Instance Attribute Details

#container_definitionObject (readonly)

Returns the value of attribute container_definition.



11
12
13
# File 'lib/wrapbox/runner/docker.rb', line 11

def container_definition
  @container_definition
end

#keep_containerObject (readonly)

Returns the value of attribute keep_container.



11
12
13
# File 'lib/wrapbox/runner/docker.rb', line 11

def keep_container
  @keep_container
end

#nameObject (readonly)

Returns the value of attribute name.



11
12
13
# File 'lib/wrapbox/runner/docker.rb', line 11

def name
  @name
end

Instance Method Details

#run(class_name, method_name, args, container_definition_overrides: {}, environments: []) ⇒ Object



22
23
24
25
26
27
28
29
30
# File 'lib/wrapbox/runner/docker.rb', line 22

def run(class_name, method_name, args, container_definition_overrides: {}, environments: [])
  definition = container_definition
    .merge(container_definition_overrides)

  envs = base_environments(class_name, method_name, args)
  envs.concat(extract_environments(environments))

  exec_docker(definition: definition, cmd: ["bundle", "exec", "rake", "wrapbox:run"], environments: envs)
end

#run_cmd(cmds, container_definition_overrides: {}, environments: []) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/wrapbox/runner/docker.rb', line 32

def run_cmd(cmds,  container_definition_overrides: {}, environments: [])
  definition = container_definition
    .merge(container_definition_overrides)

  environments = extract_environments(environments)

  ths = cmds.map do |cmd|
    Thread.new(cmd) do |c|
      exec_docker(definition: definition, cmd: c.split(/\s+/), environments: environments)
    end
  end
  ths.each(&:join)
end