Class: BoringBuilder::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/boringbuilder/runtime.rb

Defined Under Namespace

Classes: Probe

Constant Summary collapse

RUNTIME_COMMANDS =
{
  apple: %w[container system status],
  docker: %w[docker version]
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requested, probe: nil, host_os: RUBY_PLATFORM) ⇒ Runtime

Returns a new instance of Runtime.



18
19
20
21
22
# File 'lib/boringbuilder/runtime.rb', line 18

def initialize(requested, probe: nil, host_os: RUBY_PLATFORM)
  @requested = requested.to_sym
  @probe = probe || method(:probe_command)
  @host_os = host_os
end

Instance Attribute Details

#requestedObject (readonly)

Returns the value of attribute requested.



16
17
18
# File 'lib/boringbuilder/runtime.rb', line 16

def requested
  @requested
end

Instance Method Details

#dagger_runtime(resolved = resolve) ⇒ Object



43
44
45
# File 'lib/boringbuilder/runtime.rb', line 43

def dagger_runtime(resolved = resolve)
  %i[session custom].include?(resolved) ? :auto : resolved
end

#resolveObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/boringbuilder/runtime.rb', line 24

def resolve
  return session_runtime if dagger_session?
  return :custom if custom_runner?
  return ensure_available!(requested) unless requested == :auto

  failures = []
  runtime_order.each do |runtime|
    result = @probe.call(runtime, RUNTIME_COMMANDS.fetch(runtime))
    return runtime if result.success?

    failures << "#{runtime}: #{result.message}"
  end

  raise BoringBuilder::RuntimeError, <<~MESSAGE.strip
    No supported container runtime is ready. Start Apple Container with `container system start`
    or start Docker, then try again. Probes: #{failures.join('; ')}
  MESSAGE
end