Class: ManageIQ::Floe::Workflow::Runner::Docker

Inherits:
ManageIQ::Floe::Workflow::Runner show all
Defined in:
lib/manageiq/floe/workflow/runner/docker.rb

Instance Method Summary collapse

Methods inherited from ManageIQ::Floe::Workflow::Runner

for_resource

Methods included from Logging

included, #logger

Constructor Details

#initializeDocker

Returns a new instance of Docker.



6
7
8
9
10
11
# File 'lib/manageiq/floe/workflow/runner/docker.rb', line 6

def initialize(*)
  require "awesome_spawn"
  require "tempfile"

  super
end

Instance Method Details

#run!(resource, env = {}, secrets = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/manageiq/floe/workflow/runner/docker.rb', line 13

def run!(resource, env = {}, secrets = {})
  raise ArgumentError, "Invalid resource" unless resource&.start_with?("docker://")

  image = resource.sub("docker://", "")

  params = ["run", :rm, [:net, "host"]]
  params += env.map { |k, v| [:e, "#{k}=#{v}"] } if env

  secrets_file = nil

  if secrets && !secrets.empty?
    secrets_file = Tempfile.new
    secrets_file.write(secrets.to_json)
    secrets_file.flush

    params << [:e, "SECRETS=/run/secrets"]
    params << [:v, "#{secrets_file.path}:/run/secrets:z"]
  end

  params << image

  logger.debug("Running docker: #{AwesomeSpawn.build_command_line("docker", params)}")
  result = AwesomeSpawn.run!("docker", :params => params)

  [result.exit_status, result.output]
ensure
  secrets_file&.close!
end