Class: OpsTasks::Deployment

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Deployment

Returns a new instance of Deployment.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/ops_tasks.rb', line 7

def initialize(args)
  if args.size > 0
    @client = AWS::OpsWorks::Client.new
    @instance_ids = args[:layer_id].instances.map{|i| i.instance_id}
    @recipe = args[:recipe]
    @stack_id = args[:stack_id]
    @slack_channel = args[:room]
    @project = args[:project]
  else
    puts "No args given"
    exit
  end
end

Instance Method Details

#deployObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/ops_tasks.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

#status(deployment_id) ⇒ Object



48
49
50
# File 'lib/ops_tasks.rb', line 48

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

#update_cookbooksObject



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

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

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

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



52
53
54
55
56
57
58
59
60
61
# File 'lib/ops_tasks.rb', line 52

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)
  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)
end