Class: OpsTasks::Deployment
- Inherits:
-
Object
- Object
- OpsTasks::Deployment
- Defined in:
- lib/ops_tasks/deployment.rb
Instance Method Summary collapse
- #configure ⇒ Object
- #deploy ⇒ Object
-
#initialize(args) ⇒ Deployment
constructor
A new instance of Deployment.
- #instance_ids ⇒ Object
- #notifications_disabled? ⇒ Boolean
- #setup ⇒ Object
- #status(deployment_id) ⇒ Object
- #update_cookbooks ⇒ Object
- #wait_for_completion(deployment_id, task = "deployment") ⇒ Object
Constructor Details
#initialize(args) ⇒ Deployment
Returns a new instance of Deployment.
6 7 8 9 10 11 12 13 |
# File 'lib/ops_tasks/deployment.rb', line 6 def initialize(args) @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] end |
Instance Method Details
#configure ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/ops_tasks/deployment.rb', line 48 def configure print "#{@project}: Preparing configuration... " id = @client.create_deployment( :stack_id => @stack_id, :instance_ids => instance_ids, :command => { name: "configure" } )[:deployment_id] puts "successful" return id end |
#deploy ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/ops_tasks/deployment.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 |
#instance_ids ⇒ Object
15 16 17 18 19 |
# File 'lib/ops_tasks/deployment.rb', line 15 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 |
#notifications_disabled? ⇒ Boolean
73 74 75 |
# File 'lib/ops_tasks/deployment.rb', line 73 def notifications_disabled? ENV["#{@project}_room_notifications"] == 'false' end |
#setup ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/ops_tasks/deployment.rb', line 35 def setup print "#{@project}: Preparing setup... " id = @client.create_deployment( :stack_id => @stack_id, :instance_ids => instance_ids, :command => { name: "setup" } )[:deployment_id] puts "successful" return id end |
#status(deployment_id) ⇒ Object
77 78 79 |
# File 'lib/ops_tasks/deployment.rb', line 77 def status(deployment_id) @client.describe_deployments(:deployment_ids => [deployment_id])[:deployments].first[:status] end |
#update_cookbooks ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ops_tasks/deployment.rb', line 61 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
81 82 83 84 85 86 87 88 89 90 |
# File 'lib/ops_tasks/deployment.rb', line 81 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) unless notifications_disabled? 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) unless notifications_disabled? end |