Class: Pipedream::Deploy

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

Instance Method Summary collapse

Methods inherited from Stack

#initialize

Methods included from AwsServices

#cfn, #codepipeline, #s3

Methods included from AwsServices::Helpers

#are_you_sure?, #inferred_pipeline_name, #inferred_stack_name, #pipeline_name_convention, #stack_exists?

Constructor Details

This class inherits a constructor from Pipedream::Stack

Instance Method Details

#find_stack(stack_name) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/pipedream/deploy.rb', line 27

def find_stack(stack_name)
  return if ENV['TEST']
  resp = cfn.describe_stacks(stack_name: stack_name)
  resp.stacks.first
rescue Aws::CloudFormation::Errors::ValidationError => e
  # example: Stack with id demo-web does not exist
  if e.message =~ /Stack with/ && e.message =~ /does not exist/
    nil
  else
    raise
  end
end

#handle_rollback_completed!Object



12
13
14
15
16
17
18
19
20
21
# File 'lib/pipedream/deploy.rb', line 12

def handle_rollback_completed!
  @stack = find_stack(@stack_name)
  if @stack && rollback_complete?(@stack)
    puts "Existing stack in ROLLBACK_COMPLETE state. Deleting stack before continuing."
    cfn.delete_stack(stack_name: @stack_name)
    status.wait
    status.reset
    @stack = nil # at this point stack has been deleted
  end
end

#rollback_complete?(stack) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/pipedream/deploy.rb', line 23

def rollback_complete?(stack)
  stack.stack_status == 'ROLLBACK_COMPLETE'
end

#runObject



3
4
5
6
7
8
9
10
# File 'lib/pipedream/deploy.rb', line 3

def run
  handle_rollback_completed!
  if stack_exists?(@stack_name)
    Update.new(@options).run
  else
    Create.new(@options).run
  end
end