Class: OpsworksHelpers::Deployment

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

Instance Method Summary collapse

Methods inherited from OpsworksResource

all, #initialize, #inspect, #name

Constructor Details

This class inherits a constructor from OpsworksHelpers::OpsworksResource

Instance Method Details

#command_nameObject



14
15
16
# File 'lib/opsworks_helpers/deployment.rb', line 14

def command_name
  command[:name]
end

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



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

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



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

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



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

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



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

def id
  opsworks_resource.deployment_id
end