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
    @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



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

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



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

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



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

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

#update_cookbooksObject



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

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



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

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