Class: ManageIQ::Floe::Workflow::Runner::Podman

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

Instance Method Summary collapse

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

for_resource

Methods included from Logging

included, #logger

Constructor Details

#initializePodman

Returns a new instance of Podman.



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

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

  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
# File 'lib/manageiq/floe/workflow/runner/podman.rb', line 13

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

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

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

  if secrets && !secrets.empty?
    secret_guid = SecureRandom.uuid
    AwesomeSpawn.run!("podman", :params => ["secret", "create", secret_guid, "-"], :in_data => secrets.to_json)

    params << [:e, "SECRETS=/run/secrets/#{secret_guid}"]
    params << [:secret, secret_guid]
  end

  params << image

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

  [result.exit_status, result.output]
ensure
  AwesomeSpawn.run("podman", :params => ["secret", "rm", secret_guid]) if secret_guid
end