Sha256: 47538f89c32128cd3f846130d11bd8e69a084b81b3216003fa28fe51ad7c410c

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

Stored size: 1.05 KB

Contents

module Cody
  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

20 entries across 20 versions & 1 rubygems

Version Path
cody-0.9.8 lib/cody/deploy.rb
cody-0.9.7 lib/cody/deploy.rb
cody-0.9.6 lib/cody/deploy.rb
cody-0.9.5 lib/cody/deploy.rb
cody-0.9.4 lib/cody/deploy.rb
cody-0.9.3 lib/cody/deploy.rb
cody-0.9.2 lib/cody/deploy.rb
cody-0.9.1 lib/cody/deploy.rb
cody-0.9.0 lib/cody/deploy.rb
cody-0.8.6 lib/cody/deploy.rb
cody-0.8.5 lib/cody/deploy.rb
cody-0.8.4 lib/cody/deploy.rb
cody-0.8.3 lib/cody/deploy.rb
cody-0.8.2 lib/cody/deploy.rb
cody-0.8.1 lib/cody/deploy.rb
cody-0.8.0 lib/cody/deploy.rb
cody-0.7.3 lib/cody/deploy.rb
cody-0.7.2 lib/cody/deploy.rb
cody-0.7.1 lib/cody/deploy.rb
cody-0.7.0 lib/cody/deploy.rb