Class: Nvoi::Configuration::Service

Inherits:
Object
  • Object
show all
Defined in:
lib/nvoi/configuration/service.rb

Overview

Service defines a generic service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(data = nil) ⇒ Service

Returns a new instance of Service.



9
10
11
12
13
14
15
16
17
# File 'lib/nvoi/configuration/service.rb', line 9

def initialize(data = nil)
  data ||= {}
  @servers = data["servers"] || []
  @image = data["image"]
  @port = data["port"]&.to_i
  @command = data["command"]
  @env = data["env"] || {}
  @mount = data["mount"] || {}
end

Instance Attribute Details

#commandObject

Returns the value of attribute command.



7
8
9
# File 'lib/nvoi/configuration/service.rb', line 7

def command
  @command
end

#envObject

Returns the value of attribute env.



7
8
9
# File 'lib/nvoi/configuration/service.rb', line 7

def env
  @env
end

#imageObject

Returns the value of attribute image.



7
8
9
# File 'lib/nvoi/configuration/service.rb', line 7

def image
  @image
end

#mountObject

Returns the value of attribute mount.



7
8
9
# File 'lib/nvoi/configuration/service.rb', line 7

def mount
  @mount
end

#portObject

Returns the value of attribute port.



7
8
9
# File 'lib/nvoi/configuration/service.rb', line 7

def port
  @port
end

#serversObject

Returns the value of attribute servers.



7
8
9
# File 'lib/nvoi/configuration/service.rb', line 7

def servers
  @servers
end

Instance Method Details

#to_service_spec(app_name, service_name) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/nvoi/configuration/service.rb', line 19

def to_service_spec(app_name, service_name)
  cmd = @command ? @command.split : []
  port = @port && @port.positive? ? @port : infer_port_from_image

  Configuration::Deployment.new(
    name: "#{app_name}-#{service_name}",
    image: @image,
    port:,
    command: cmd,
    env: @env,
    mounts: @mount,
    replicas: 1,
    stateful_set: false,
    servers: @servers
  )
end