Class: Lemans::Config::Environment

Inherits:
Object
  • Object
show all
Extended by:
Conversion
Defined in:
lib/lemans/config/environment.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Resources

Constant Summary

Constants included from Conversion

Conversion::DURATION, Conversion::DURATION_FACTORS, Conversion::SIZE, Conversion::SIZE_FACTORS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Conversion

absolute_path!, float!, integer!, megabytes!, seconds!

Constructor Details

#initializeEnvironment

Returns a new instance of Environment.



35
36
37
38
39
40
41
42
43
# File 'lib/lemans/config/environment.rb', line 35

def initialize
  @image = nil
  @dockerfile = nil
  @backend = "daytona"
  @workdir = "/app"
  @resources = Resources.new(cpus: 2, memory: 2048, storage: 5120)
  @build_timeout = 10 * 60
  @network = NetworkPolicy.new
end

Instance Attribute Details

#backendObject

Returns the value of attribute backend.



32
33
34
# File 'lib/lemans/config/environment.rb', line 32

def backend
  @backend
end

#build_timeoutObject

Returns the value of attribute build_timeout.



32
33
34
# File 'lib/lemans/config/environment.rb', line 32

def build_timeout
  @build_timeout
end

#dockerfileObject

Returns the value of attribute dockerfile.



32
33
34
# File 'lib/lemans/config/environment.rb', line 32

def dockerfile
  @dockerfile
end

#imageObject

Returns the value of attribute image.



32
33
34
# File 'lib/lemans/config/environment.rb', line 32

def image
  @image
end

#networkObject

Returns the value of attribute network.



32
33
34
# File 'lib/lemans/config/environment.rb', line 32

def network
  @network
end

#resourcesObject

Returns the value of attribute resources.



32
33
34
# File 'lib/lemans/config/environment.rb', line 32

def resources
  @resources
end

#workdirObject

Returns the value of attribute workdir.



32
33
34
# File 'lib/lemans/config/environment.rb', line 32

def workdir
  @workdir
end

Class Method Details

.from_config(data) ⇒ Object

Raises:



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/lemans/config/environment.rb', line 11

def from_config(data)
  return if data.nil?

  conf = new
  conf.backend = data["backend"] if data["backend"]
  conf.image = data["image"] if data["image"]
  conf.dockerfile = data["dockerfile"] if data["dockerfile"]
  raise ConfigError, "environment.image and environment.dockerfile are mutually exclusive" if conf.image && conf.dockerfile

  conf.workdir = absolute_path!(data["workdir"]) if data["workdir"]
  conf.build_timeout = seconds!(data["build_timeout"]) if data["build_timeout"]
  conf.network = NetworkPolicy.from_config(data["network"]) if data["network"]

  conf.resources.cpus = integer!(data.dig("resources", "cpus")) if data.dig("resources", "cpus")
  conf.resources.memory = megabytes!(data.dig("resources", "memory")) if data.dig("resources", "memory")
  conf.resources.storage = megabytes!(data.dig("resources", "storage")) if data.dig("resources", "storage")

  conf
end