Class: Wrapbox::Runner::Docker
- Inherits:
-
Object
- Object
- Wrapbox::Runner::Docker
- Defined in:
- lib/wrapbox/runner/docker.rb
Defined Under Namespace
Classes: Cli, ExecutionError
Instance Attribute Summary collapse
-
#container_definition ⇒ Object
readonly
Returns the value of attribute container_definition.
-
#keep_container ⇒ Object
readonly
Returns the value of attribute keep_container.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(options) ⇒ Docker
constructor
A new instance of Docker.
- #run(class_name, method_name, args, container_definition_overrides: {}, environments: []) ⇒ Object
- #run_cmd(cmds, container_definition_overrides: {}, environments: [], ignore_signal: false) ⇒ Object
Constructor Details
#initialize(options) ⇒ Docker
Returns a new instance of Docker.
30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/wrapbox/runner/docker.rb', line 30 def initialize() @name = [:name] @container_definitions = [:container_definition] ? [[:container_definition]] : [:container_definitions] @logger = Wrapbox.logger if @container_definitions.size >= 2 raise "Docker runner does not support multi container currently" end @container_definition = @container_definitions[0] @keep_container = [:keep_container] end |
Instance Attribute Details
#container_definition ⇒ Object (readonly)
Returns the value of attribute container_definition.
14 15 16 |
# File 'lib/wrapbox/runner/docker.rb', line 14 def container_definition @container_definition end |
#keep_container ⇒ Object (readonly)
Returns the value of attribute keep_container.
14 15 16 |
# File 'lib/wrapbox/runner/docker.rb', line 14 def keep_container @keep_container end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
14 15 16 |
# File 'lib/wrapbox/runner/docker.rb', line 14 def name @name end |
Class Method Details
.split_overridable_options_and_parameters(options) ⇒ Object
19 20 21 22 23 24 25 26 27 28 |
# File 'lib/wrapbox/runner/docker.rb', line 19 def self.() opts = .dup = {} i[keep_container].each do |key| value = opts.delete(key) [key] = value if value end [, opts] end |
Instance Method Details
#run(class_name, method_name, args, container_definition_overrides: {}, environments: []) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/wrapbox/runner/docker.rb', line 44 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: [], ignore_signal: false) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/wrapbox/runner/docker.rb', line 54 def run_cmd(cmds, container_definition_overrides: {}, environments: [], ignore_signal: false) ths = [] definition = container_definition .merge(container_definition_overrides) environments = extract_environments(environments) cmds << nil if cmds.empty? cmds.each_with_index do |cmd, idx| ths << Thread.new(cmd, idx) do |c, i| envs = environments + ["WRAPBOX_CMD_INDEX=#{idx}"] exec_docker( definition: definition, cmd: c&.shellsplit, environments: envs ) end end ths.each { |th| th&.join } true rescue SignalException => e sig = "SIG#{Signal.signame(e.signo)}" if ignore_signal @logger.info("Receive #{sig} signal. But Docker container continue running") else @logger.info("Receive #{sig} signal. Stop All tasks") ths.each do |th| th.report_on_exception = false th.raise(e) end thread_timeout = 15 ths.each { |th| th.join(thread_timeout) } end nil end |