Class: Baps::Executor
- Inherits:
-
Object
- Object
- Baps::Executor
- Defined in:
- lib/baps/executor.rb
Constant Summary collapse
- DOCKER_IMAGE_ID =
'elvinefendi/baps'
Class Method Summary collapse
Instance Method Summary collapse
- #execute ⇒ Object
-
#initialize(path:, use_docker: true, publish: true) ⇒ Executor
constructor
A new instance of Executor.
Constructor Details
#initialize(path:, use_docker: true, publish: true) ⇒ Executor
Returns a new instance of Executor.
5 6 7 8 9 10 11 12 13 |
# File 'lib/baps/executor.rb', line 5 def initialize(path:, use_docker: true, publish: true) raise ArgumentError.new('Given path does not exist.') unless File.exist?(path) @path = File.(path) @use_docker = use_docker # TODO refactor this! @@publish = publish @definitions = definitions_from_directory if File.directory?(@path) @definitions = [Definition.new(@path)] if File.file?(@path) end |
Class Method Details
.publish? ⇒ Boolean
15 16 17 |
# File 'lib/baps/executor.rb', line 15 def self.publish? !!@@publish end |
Instance Method Details
#execute ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/baps/executor.rb', line 19 def execute if !@definitions || @definitions.empty? puts 'No definition to execute' return end return @definitions.each(&:execute) unless @use_docker errors = {} @definitions.each do |definition| cmd = "exe/baps -p #{path_in_docker} --no-docker" cmd << ' --no-publish' unless @@publish container = base_container.run(cmd) container.attach { |stream, chunk| puts "#{stream}: #{chunk}" } if (code = container.wait(Baps::TIMEOUT)['StatusCode']) > 0 errors[definition] = code end end unless errors.empty? raise ExecutorError, errors.map { |d, c| "#{d.path} exited with #{c}" }.join("\n") end end |