Class: OpsTasks::Deployment

Inherits:
Object
  • Object
show all
Defined in:
lib/ops_tasks/deployment.rb

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Deployment

Returns a new instance of Deployment.



6
7
8
9
10
11
12
13
# File 'lib/ops_tasks/deployment.rb', line 6

def initialize(args)
  @client = AWS::OpsWorks::Client.new
  @layer_id = args[:layer_id]
  @recipe = args[:recipe]
  @stack_id = args[:stack_id]
  @slack_channel = args[:room]
  @project = args[:project]
end

Instance Method Details

#configureObject



48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/ops_tasks/deployment.rb', line 48

def configure
  print "#{@project}: Preparing configuration... "
  id = @client.create_deployment(
    :stack_id => @stack_id,
    :instance_ids => instance_ids,
    :command => {
      name: "configure"
    }
  )[:deployment_id]
  puts "successful"
  return id
end

#deployObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ops_tasks/deployment.rb', line 21

def deploy
  print "#{@project}: Preparing deployment... "
  id = @client.create_deployment(
    :stack_id => @stack_id,
    :instance_ids => instance_ids,
    :command => {
      name: "execute_recipes",
      args: {"recipes" => [@recipe]}
    }
  )[:deployment_id]
  puts "successful"
  return id
end

#instance_idsObject



15
16
17
18
19
# File 'lib/ops_tasks/deployment.rb', line 15

def instance_ids
  client = AWS::OpsWorks::Client.new
  instance_objects = client.describe_instances(:layer_id => @layer_id)
  return instance_objects.instances.map{|i| i.instance_id}.to_a
end

#notifications_disabled?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/ops_tasks/deployment.rb', line 73

def notifications_disabled?
  ENV["#{@project}_room_notifications"] == 'false'
end

#setupObject



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/ops_tasks/deployment.rb', line 35

def setup
  print "#{@project}: Preparing setup... "
  id = @client.create_deployment(
    :stack_id => @stack_id,
    :instance_ids => instance_ids,
    :command => {
      name: "setup"
    }
  )[:deployment_id]
  puts "successful"
  return id
end

#status(deployment_id) ⇒ Object



77
78
79
# File 'lib/ops_tasks/deployment.rb', line 77

def status(deployment_id)
  @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
end

#update_cookbooksObject



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/ops_tasks/deployment.rb', line 61

def update_cookbooks
  print "#{@project}: Preparing cookbook update... "

  id = @client.create_deployment(
    :stack_id => @stack_id,
    :instance_ids => instance_ids,
    :command => {name: 'update_custom_cookbooks'}
  )[:deployment_id]
  puts "successful"
  return id
end

#wait_for_completion(deployment_id, task = "deployment") ⇒ Object



81
82
83
84
85
86
87
88
89
90
# File 'lib/ops_tasks/deployment.rb', line 81

def wait_for_completion(deployment_id, task="deployment")
  print "#{@project}: Running... "
  status = @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
  "Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel) unless notifications_disabled?
  until status != "running"
    status = @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status]
  end
  puts status
  "Chef".says("#{@project} #{task} #{status}").to_channel(@slack_channel) unless notifications_disabled?
end