Class: GV::Valley::Deployer

Inherits:
Bedrock::Service
  • Object
show all
Includes:
Common::PipeHelper
Defined in:
lib/gv/valley/deployer.rb

Instance Method Summary collapse

Instance Method Details

#deploy(name, &block) ⇒ Object

deploys app



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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
59
60
61
# File 'lib/gv/valley/deployer.rb', line 18

def deploy name, &block
  
  # find or create app
  unless app = App.find(name)
    app = App.create(name)
  end
  
  # set block for output helpers
  @block = block
    
  indicate "Deploying App"
  
  # read procfile  
  host = GV::Valley::Runner.random_service
  procfile = host.run(app["name"], "cat /app/Procfile")
  procfile_types = YAML.load(procfile).keys
  
  stop app
    
  # add new Procfile process types or reset jobs array for existing types
  procfile_types.each do |type|
    unless app["ps"].keys.include? type
      app["ps"][type] = {"scale" => 1, "containers" => []}
    else
      app["ps"][type]["containers"] = []
    end
  end
  
  app.save
    
  # remove the old types
  app["ps"].keys.each do |type|
    unless procfile_types.include? type
      app["ps"].delete(type)
    end
  end
  
  app.save
  
  start app
    
  app.save
    
end

#start(app, &block) ⇒ Object

starts all procfile processes



79
80
81
82
83
84
85
86
87
# File 'lib/gv/valley/deployer.rb', line 79

def start app, &block
  # run available process types
  app["ps"].each do |type,ps|
    ps["scale"].times do |index|
      host = GV::Valley::Runner.random_service                
      app["ps"][type]["containers"] << host.start(app["name"], type, index, &block)
    end
  end
end

#stop(app, &block) ⇒ Object

stops all running procfile processes



66
67
68
69
70
71
72
73
74
# File 'lib/gv/valley/deployer.rb', line 66

def stop app, &block
  # stop and remove all running procfile processes
  tuple = [:ps, /#{app['name']}\./, nil, nil ]
  while (self.class.space.read(tuple,0) rescue nil) do
    if host = (self.class.space.take(tuple,0)[2] rescue nil)
      host.remove app["name"]
    end
  end
end