Class: KumoDockerCloud::Stack

Inherits:
Object
  • Object
show all
Defined in:
lib/kumo_dockercloud/stack.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app_name, env_name, options = { contactable: true }) ⇒ Stack

TODO delete options



8
9
10
11
12
# File 'lib/kumo_dockercloud/stack.rb', line 8

def initialize(app_name, env_name, options = { contactable: true })
  @app_name = app_name
  @stack_name = "#{app_name}-#{env_name}"
  @options = options
end

Instance Attribute Details

#app_nameObject (readonly)

Returns the value of attribute app_name.



5
6
7
# File 'lib/kumo_dockercloud/stack.rb', line 5

def app_name
  @app_name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/kumo_dockercloud/stack.rb', line 5

def options
  @options
end

#stack_nameObject (readonly)

Returns the value of attribute stack_name.



5
6
7
# File 'lib/kumo_dockercloud/stack.rb', line 5

def stack_name
  @stack_name
end

Instance Method Details

#deploy(service_name, version, checker = ServiceChecker.new) ⇒ Object



14
15
16
17
18
19
20
21
# File 'lib/kumo_dockercloud/stack.rb', line 14

def deploy(service_name, version, checker = ServiceChecker.new)
  validate_params(service_name, 'Service name')
  validate_params(version, 'Version')

  service = Service.new(stack_name, service_name)
  service.deploy(version)
  checker.verify(service)
end

#deploy_blue_green(service_names, version, checker = ServiceChecker.new) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/kumo_dockercloud/stack.rb', line 23

def deploy_blue_green(service_names, version, checker = ServiceChecker.new)
  haproxy_service = HaproxyService.new(@stack_name)

  services = service_names.map { |name| Service.new(stack_name, name) }
  ordered_deployment(services).each do |service|
    begin
      haproxy_service.disable_service(service) unless service.state == "Stopped"
      service.deploy(version)
      checker.verify(service)
      haproxy_service.enable_service(service)
    rescue HAProxyStateError => e
      raise ServiceDeployError.new("Unable to place service #{service.name} into maintainance mode on HAProxy with message: #{e.message}")
    rescue ServiceDeployError => e
      haproxy_service.disable_service(service)
      raise ServiceDeployError.new("Deployment or verification of service #{service.name} failed with message: #{e.message}")
    end
  end
end

#servicesObject



42
43
44
45
# File 'lib/kumo_dockercloud/stack.rb', line 42

def services
  services = docker_cloud_api.services_by_stack_name(stack_name)
  services.map { |service| Service.new(stack_name, service.name) }
end