Class: Kaiser::Service

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

Overview

This class describes an app-specific service

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(envname, name, service_info) ⇒ Service

Returns a new instance of Service.



8
9
10
11
12
# File 'lib/kaiser/service.rb', line 8

def initialize(envname, name, service_info)
  @envname = envname
  @name = name
  @service_info = service_info
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/kaiser/service.rb', line 6

def name
  @name
end

Instance Method Details

#bindsObject



26
27
28
# File 'lib/kaiser/service.rb', line 26

def binds
  @service_info[:binds] || {}
end

#commandObject



22
23
24
# File 'lib/kaiser/service.rb', line 22

def command
  @service_info[:command].to_s
end

#envObject



30
31
32
# File 'lib/kaiser/service.rb', line 30

def env
  @service_info[:env] || {}
end

#imageObject



18
19
20
# File 'lib/kaiser/service.rb', line 18

def image
  @service_info[:image]
end

#shared_nameObject



14
15
16
# File 'lib/kaiser/service.rb', line 14

def shared_name
  "#{@envname}-#{name}"
end

#start_docker_commandObject



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/kaiser/service.rb', line 34

def start_docker_command
  envstring = env.map do |k, v|
    "-e #{k}=#{v}"
  end.join(' ')

  bindstring = binds.map do |k, v|
    "-v #{k}:#{v}"
  end.join(' ')

  commandstring = command

  cmd_array = [
    'docker run -d',
    "--name #{shared_name}",
    "--network #{Config.config[:networkname]}",
    envstring,
    bindstring,
    image,
    commandstring
  ]

  cmd_array.filter! { |x| !x.empty? }

  cmd_array.join(' ')
end