Class: OpsworksHelpers::Deployment

Inherits:
OpsworksResource show all
Defined in:
lib/opsworks_helpers/deployment.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from OpsworksResource

all, #initialize, #inspect, #name

Constructor Details

This class inherits a constructor from OpsworksHelpers::OpsworksResource

Instance Attribute Details

#commandObject

Returns the value of attribute command.



10
11
12
# File 'lib/opsworks_helpers/deployment.rb', line 10

def command
  @command
end

Instance Method Details

#command_nameObject



16
17
18
# File 'lib/opsworks_helpers/deployment.rb', line 16

def command_name
  command[:name]
end

#create(command, comment: 'Run via in-app rake task') ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/opsworks_helpers/deployment.rb', line 20

def create(command, comment: 'Run via in-app rake task')
  @command = command

  @opsworks_resource = opsworks.create_deployment(
    stack_id: stack_id,
    app_id: app_id,
    command: command,
    comment: comment
  )
end

#deploy(stack: nil, app: nil, comment: nil) ⇒ Object



31
32
33
34
35
36
37
38
39
40
# File 'lib/opsworks_helpers/deployment.rb', line 31

def deploy(stack:nil, app:nil, comment:nil)
  @stack_id = stack if stack
  @app_id = app if app

  @command = {
    name: 'deploy',
    args: { migrate: ['true'] }
  }
  create(command, comment: comment)
end

#display_deployment_resultObject



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

def display_deployment_result
  begin
    puts "[#{id}] Waiting for command '#{command_name}' to finish..."
    opsworks.wait_until(:deployment_successful, deployment_ids: [id])
    puts "[#{id}] Command '#{command_name}' successful."
    true
  rescue ::Aws::Waiters::Errors::WaiterFailed => e
    puts "[#{id}] Command '#{command_name}' failed. Message: #{e.message}"
    false
  end
end

#idObject



12
13
14
# File 'lib/opsworks_helpers/deployment.rb', line 12

def id
  opsworks_resource.deployment_id
end