Class: GV::Valley::Addon

Inherits:
Bedrock::Service
  • Object
show all
Includes:
Common::DockerHelper, Common::HostHelper
Defined in:
lib/gv/valley/addon.rb

Overview

Addon Service

Constant Summary collapse

PORT =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeAddon

Returns a new instance of Addon.



22
23
24
25
26
27
28
29
30
# File 'lib/gv/valley/addon.rb', line 22

def initialize
  super
  
  pull_image_if_does_not_exists self.image
  
  @home = GV::Bedrock::Config.service.get("home")
  @name ||= File.basename(self.image) 
  
end

Instance Attribute Details

#cmdObject (readonly)

Returns the value of attribute cmd.



20
21
22
# File 'lib/gv/valley/addon.rb', line 20

def cmd
  @cmd
end

#imageObject (readonly)

Returns the value of attribute image.



20
21
22
# File 'lib/gv/valley/addon.rb', line 20

def image
  @image
end

#paramsObject (readonly)

Returns the value of attribute params.



20
21
22
# File 'lib/gv/valley/addon.rb', line 20

def params
  @params
end

Instance Method Details

#create(app_name) ⇒ Object



32
33
34
35
36
37
# File 'lib/gv/valley/addon.rb', line 32

def create app_name
  @app_name = app_name
  addon_name = "#{@name}.#{app_name}"
  return nil if ps? addon_name
  pipe "docker run --name #{addon_name} -d -p #{self.external_ip}::#{self.class::PORT} -e PORT=#{self.class::PORT} #{self.params} #{self.image} #{self.cmd}"
end

#destroy(app_name) ⇒ Object



39
40
41
42
43
44
# File 'lib/gv/valley/addon.rb', line 39

def destroy app_name
  @app_name = app_name
  addon_name = "#{@name}.#{app_name}"
  batch addon_name, "stop", true
  batch addon_name, "rm", true        
end

#info(app_name) ⇒ Object



46
47
48
49
50
# File 'lib/gv/valley/addon.rb', line 46

def info app_name
  @app_name = app_name
  addon_name = "#{@name}.#{app_name}"
  info(container_id(addon_name))
end

#port(app_name) ⇒ Object



52
53
54
55
56
# File 'lib/gv/valley/addon.rb', line 52

def port app_name
  @app_name = app_name
  addon_name = "#{@name}.#{app_name}"
  container_port addon_name, self.external_ip, self.class::PORT
end