Sha256: 736c561bea5fa6eac4d44125f87d91a707216dab6c978769f3155a876aa2b6a5

Contents?: true

Size: 1.05 KB

Versions: 9

Compression:

Stored size: 1.05 KB

Contents

module Pipedream
  class Deploy < Stack
    def run
      handle_rollback_completed!
      if stack_exists?(@stack_name)
        Update.new(@options).run
      else
        Create.new(@options).run
      end
    end

    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

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

    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
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
pipedream-0.4.8 lib/pipedream/deploy.rb
pipedream-0.4.7 lib/pipedream/deploy.rb
pipedream-0.4.6 lib/pipedream/deploy.rb
pipedream-0.4.5 lib/pipedream/deploy.rb
pipedream-0.4.4 lib/pipedream/deploy.rb
pipedream-0.4.3 lib/pipedream/deploy.rb
pipedream-0.4.2 lib/pipedream/deploy.rb
pipedream-0.4.1 lib/pipedream/deploy.rb
pipedream-0.4.0 lib/pipedream/deploy.rb