Sha256: 3d9bb3a6091008128337f53f867ffef0c9516435ebea2eddafa9bff525ec25a5

Contents?: true

Size: 1.58 KB

Versions: 2

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

require 'capistrano/plugin'

module Capistrano
  module ASG
    module Rolling
      # Load this Capistrano Plugin in your Capfile:
      #
      # require 'capistrano/asg/rolling'
      # install_plugin Capistrano::ASG::Rolling::Plugin
      #
      class Plugin < Capistrano::Plugin
        def set_defaults
          set_if_empty :asg_rolling_group_name, ENV.fetch('asg_name', nil)
          set_if_empty :asg_rolling_use_private_ip_address, true
          set_if_empty :asg_rolling_verbose, true
          set_if_empty :asg_rolling_update, true
        end

        def register_hooks
          Capistrano::DSL.stages.each do |stage|
            after stage, 'rolling:setup'
          end

          after 'deploy', 'rolling:update'
          after 'deploy:failed', 'rolling:cleanup'

          after 'rolling:update', 'rolling:cleanup'
          after 'rolling:create_ami', 'rolling:cleanup'

          # Register an exit hook to do some cleanup when Capistrano
          # terminates without calling our after cleanup hook.
          at_exit { cleanup }
        end

        def define_tasks
          eval_rakefile File.expand_path('../tasks/rolling.rake', __dir__)
        end

        def logger
          @logger ||= Logger.new(verbose: config.verbose?)
        end

        def config
          Capistrano::ASG::Rolling::Configuration
        end

        def cleanup
          instances = config.instances.auto_terminate
          return if instances.empty?

          logger.info 'Terminating instance(s)...'
          instances.terminate
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
capistrano-asg-rolling-0.3.0 lib/capistrano/asg/rolling/plugin.rb
capistrano-asg-rolling-0.2.1 lib/capistrano/asg/rolling/plugin.rb