Class: OpsTasks::Deployment

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

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Deployment



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

def initialize(args)
  if args.size > 0
    @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]
  else
    puts "No args given"
    exit
  end
end

Instance Method Details

#deployObject



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/ops_tasks.rb', line 28

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



22
23
24
25
26
# File 'lib/ops_tasks.rb', line 22

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

#status(deployment_id) ⇒ Object



55
56
57
# File 'lib/ops_tasks.rb', line 55

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

#update_cookbooksObject



42
43
44
45
46
47
48
49
50
51
52
# File 'lib/ops_tasks.rb', line 42

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



59
60
61
62
63
64
65
66
67
68
# File 'lib/ops_tasks.rb', line 59

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