Class: OpsworksShip::Chef
- Inherits:
-
Object
- Object
- OpsworksShip::Chef
- Defined in:
- lib/opsworks_ship/chef.rb
Instance Method Summary collapse
- #deploy ⇒ Object
-
#initialize(stack_name:, revision:, app_type:, app_layer_name_regex:, hipchat_auth_token: nil, hipchat_room_id: nil) ⇒ Chef
constructor
A new instance of Chef.
- #run_and_monitor(command) ⇒ Object
- #set_revision_for_stack ⇒ Object
Constructor Details
#initialize(stack_name:, revision:, app_type:, app_layer_name_regex:, hipchat_auth_token: nil, hipchat_room_id: nil) ⇒ Chef
Returns a new instance of Chef.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/opsworks_ship/chef.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
#deploy ⇒ Object
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/chef.rb', line 30 def deploy start_time = Time.now puts "\n-------------------------------------" puts "Full chef run started" puts "Revision: #{@revision}" puts "Stack: #{@stack_name}" puts "-------------------------------------\n\n" set_revision_for_stack [ 'update_custom_cookbooks', 'update_dependencies', 'setup', 'configure', ].each{|command| run_and_monitor(command)} msg = "#{@app_type} -- Full chef run successful! Layers #{@app_layer_name_regex} now on #{@revision} deployed to #{@stack_name} by #{deployed_by}" post_deployment_to_hipchat(msg) run_time_seconds = Time.now.to_i - start_time.to_i "Deployment time #{run_time_seconds / 60}:%02i" % (run_time_seconds % 60) end |
#run_and_monitor(command) ⇒ Object
55 56 57 58 59 60 61 62 |
# File 'lib/opsworks_ship/chef.rb', line 55 def run_and_monitor(command) deployment_id = start_deployment({ :Name => command }.to_json.gsub('"', "\\\"")) final_status = monitor_deployment(deployment_id) unless final_status.downcase =~ /successful/ raise "Deployment failed, status: #{final_status}" end end |
#set_revision_for_stack ⇒ Object
64 65 66 67 68 69 |
# File 'lib/opsworks_ship/chef.rb', line 64 def set_revision_for_stack "Setting revision #{@revision}" cmd = "aws opsworks update-stack --stack-id #{stack_id} --custom-cookbooks-source Revision=#{@revision}" "#{cmd}" `#{cmd}` end |