Class: DaggerRuby::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/dagger_ruby/config.rb

Constant Summary collapse

ENGINE_IMAGE =
"registry.dagger.io/engine".freeze
RUNTIMES =
%i[auto apple docker].freeze
PROGRESS_MODES =
%w[auto pretty plain tty dots logs].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Config

Returns a new instance of Config.

Raises:

  • (ArgumentError)


13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/dagger_ruby/config.rb', line 13

def initialize(options = {})
  @log_output = options[:log_output]
  @workdir = options[:workdir]
  @timeout = options[:timeout] || 600
  @quiet = options[:quiet] || ENV["DAGGER_QUIET"]&.to_i
  @silent = options[:silent] || ENV["DAGGER_SILENT"] == "true"
  @progress = normalize_progress(options[:progress] || ENV.fetch("DAGGER_PROGRESS", nil))
  @runtime = normalize_runtime(options.fetch(:runtime, ENV.fetch("DAGGER_RUBY_RUNTIME", "auto")))
  @runner_host = options[:runner_host]
  @dagger_version = options.fetch(:dagger_version, DAGGER_VERSION).to_s.delete_prefix("v")
  @verify_version = options.fetch(:verify_version, true)

  raise ArgumentError, "runner_host and runtime cannot both be configured" if @runner_host && @runtime != :auto
end

Instance Attribute Details

#dagger_versionObject (readonly)

Returns the value of attribute dagger_version.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def dagger_version
  @dagger_version
end

#log_outputObject (readonly)

Returns the value of attribute log_output.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def log_output
  @log_output
end

#progressObject (readonly)

Returns the value of attribute progress.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def progress
  @progress
end

#quietObject (readonly)

Returns the value of attribute quiet.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def quiet
  @quiet
end

#runner_hostObject (readonly)

Returns the value of attribute runner_host.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def runner_host
  @runner_host
end

#runtimeObject (readonly)

Returns the value of attribute runtime.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def runtime
  @runtime
end

#silentObject (readonly)

Returns the value of attribute silent.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def silent
  @silent
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def timeout
  @timeout
end

#verify_versionObject (readonly)

Returns the value of attribute verify_version.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def verify_version
  @verify_version
end

#workdirObject (readonly)

Returns the value of attribute workdir.



10
11
12
# File 'lib/dagger_ruby/config.rb', line 10

def workdir
  @workdir
end

Instance Method Details

#dagger_progressObject



42
43
44
# File 'lib/dagger_ruby/config.rb', line 42

def dagger_progress
  pretty_progress? ? "logs" : progress
end

#environmentObject



28
29
30
31
32
# File 'lib/dagger_ruby/config.rb', line 28

def environment
  environment = {}
  environment["_EXPERIMENTAL_DAGGER_RUNNER_HOST"] = resolved_runner_host if resolved_runner_host
  environment
end

#expected_engine_versionObject



34
35
36
# File 'lib/dagger_ruby/config.rb', line 34

def expected_engine_version
  "v#{dagger_version}"
end

#pretty_progress?Boolean

Returns:

  • (Boolean)


38
# File 'lib/dagger_ruby/config.rb', line 38

def pretty_progress? = progress == "pretty"

#progress_reporter(out: $stdout, enabled: true, environment: ENV) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/dagger_ruby/config.rb', line 46

def progress_reporter(out: $stdout, enabled: true, environment: ENV)
  enabled &&= pretty_progress?
  color = enabled && out.respond_to?(:tty?) && out.tty? && !environment.key?("NO_COLOR") &&
          environment.fetch("TERM", "") != "dumb"
  Progress.new(out: out, enabled: enabled, streaming: streaming_logs?, color: color,
               relay: enabled && Progress::Relay.from_environment(environment))
end

#streaming_logs?Boolean

Returns:

  • (Boolean)


40
# File 'lib/dagger_ruby/config.rb', line 40

def streaming_logs? = %w[pretty logs].include?(progress)