Class: OpsworksShip::Deploy

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

Instance Method Summary collapse

Constructor Details

#initialize(stack_name:, revision:, app_type:, app_layer_name_regex:, hipchat_auth_token: nil, hipchat_room_id: nil) ⇒ Deploy

Returns a new instance of Deploy.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/opsworks_ship/deploy.rb', line 14

def initialize(stack_name:, revision:, app_type:, app_layer_name_regex:, hipchat_auth_token: nil, hipchat_room_id: nil)
  @stack_name = stack_name
  raise "Invalid stack name, valid stacks are: #{all_stack_names}" unless all_stack_names.any?{|available_name| available_name == stack_name}

  @revision = revision

  @app_type = app_type
  raise "Invalid app type #{@app_type}" unless opsworks_app_types.include?(@app_type)

  @app_layer_name_regex = app_layer_name_regex

  @hipchat_auth_token = hipchat_auth_token
  @hipchat_room_id = hipchat_room_id
  raise "Must supply both or neither hipchat params" if [@hipchat_auth_token, @hipchat_room_id].compact.size == 1
end

Instance Method Details

#deployObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/opsworks_ship/deploy.rb', line 30

def deploy
  start_time = Time.now

  puts "\n-------------------------------------"
  puts "Deployment started"
  puts "Revision: #{@revision}"
  puts "Stack: #{@stack_name}"
  puts "-------------------------------------\n\n"

  set_revision_in_opsworks_app

  deployment_id = start_deployment({ :Name => "deploy" }.to_json.gsub('"', "\\\""))
  final_status = monitor_deployment(deployment_id)

  if final_status.downcase =~ /successful/
    msg = "#{@app_type} deployment successful! Layers #{@app_layer_name_regex} now on #{@revision} deployed to #{@stack_name} by #{deployed_by}"
    post_deployment_to_hipchat(msg)
  else
    raise "Deployment failed, status: #{final_status}"
  end

  run_time_seconds = Time.now.to_i - start_time.to_i
  timestamped_puts "Deployment time #{run_time_seconds / 60}:%02i" % (run_time_seconds % 60)
end

#set_revision_in_opsworks_appObject



55
56
57
58
59
60
# File 'lib/opsworks_ship/deploy.rb', line 55

def set_revision_in_opsworks_app
  timestamped_puts "Setting revision #{@revision}"
  cmd = "aws opsworks update-app --app-id #{app_id(stack_id)} --app-source Revision=#{@revision}"
  timestamped_puts "#{cmd}"
  `#{cmd}`
end