Class: Floe::ContainerRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/floe/container_runner.rb,
lib/floe/container_runner/docker.rb,
lib/floe/container_runner/podman.rb,
lib/floe/container_runner/kubernetes.rb,
lib/floe/container_runner/docker_mixin.rb

Defined Under Namespace

Modules: DockerMixin Classes: Docker, Kubernetes, Podman

Class Method Summary collapse

Class Method Details

.cli_options(optimist) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/floe/container_runner.rb', line 11

def cli_options(optimist)
  optimist.banner("")
  optimist.banner("Container runner options:")

  optimist.opt :container_runner, "Type of runner for docker container images (docker, podman, or kubernetes)", :type => :string, :short => 'r'
  optimist.opt :container_runner_options, "Options to pass to the container runner", :type => :strings, :short => 'o'

  optimist.opt :docker,     "Use docker to run container images     (short for --container-runner=docker)",     :type => :boolean
  optimist.opt :podman,     "Use podman to run container images     (short for --container-runner=podman)",     :type => :boolean
  optimist.opt :kubernetes, "Use kubernetes to run container images (short for --container-runner=kubernetes)", :type => :boolean
end

.resolve_cli_options!(opts) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/floe/container_runner.rb', line 23

def resolve_cli_options!(opts)
  # shortcut support
  opts[:container_runner] ||= "docker" if opts[:docker]
  opts[:container_runner] ||= "podman" if opts[:podman]
  opts[:container_runner] ||= "kubernetes" if opts[:kubernetes]

  runner_options = opts[:container_runner_options].to_h { |opt| opt.split("=", 2) }

  begin
    set_runner(opts[:container_runner], runner_options)
  rescue ArgumentError => e
    Optimist.die(:container_runner, e.message)
  end
end

.runnerObject



38
39
40
# File 'lib/floe/container_runner.rb', line 38

def runner
  @runner || set_runner(nil)
end

.set_runner(name_or_instance, options = {}) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/floe/container_runner.rb', line 42

def set_runner(name_or_instance, options = {})
  @runner =
    case name_or_instance
    when "docker", nil
      Floe::ContainerRunner::Docker.new(options)
    when "podman"
      Floe::ContainerRunner::Podman.new(options)
    when "kubernetes"
      Floe::ContainerRunner::Kubernetes.new(options)
    when Floe::Runner
      name_or_instance
    else
      raise ArgumentError, "container runner must be one of: docker, podman, kubernetes"
    end
end