Class: Opsup::StackOperator
- Inherits:
-
Object
- Object
- Opsup::StackOperator
- Extended by:
- T::Sig
- Defined in:
- lib/opsup/stack_operator.rb,
lib/opsup/stack_operator/command_deployer.rb
Defined Under Namespace
Classes: CommandDeployer
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(opsworks:, logger:) ⇒ StackOperator
constructor
A new instance of StackOperator.
- #new_deployer(stack_name:, mode:, dryrun: false) ⇒ Object
Constructor Details
#initialize(opsworks:, logger:) ⇒ StackOperator
Returns a new instance of StackOperator.
19 20 21 22 |
# File 'lib/opsup/stack_operator.rb', line 19 def initialize(opsworks:, logger:) @opsworks = T.let(opsworks, Aws::OpsWorks::Client) @logger = T.let(logger, ::Logger) end |
Class Method Details
Instance Method Details
#new_deployer(stack_name:, mode:, dryrun: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/opsup/stack_operator.rb', line 31 def new_deployer(stack_name:, mode:, dryrun: false) # Find the target stack. @logger.debug('Verifying the specified stack exists...') stacks = @opsworks.describe_stacks.stacks stack = stacks.find { |s| s.name == stack_name } raise Opsup::Error, "Stack #{stack_name} does not exist" if stack.nil? # Find the stack's apps. @logger.debug('Verifying the stack has at least one app...') apps = @opsworks.describe_apps(stack_id: stack.stack_id).apps raise Opsup::Error, "#{stack_name} has no apps" if apps.empty? # Find the instances to be updated. @logger.debug('Finding all working instances in the stack...') instances = @opsworks.describe_instances(stack_id: stack.stack_id).instances instances = instances.reject { |inst| inst.status == 'stopped' } raise Opsup::Error, 'No available instances found' if instances.empty? @logger.debug( "#{instances.size} #{instances.size == 1 ? 'instance is' : 'instances are'} found", ) config = StackOperator::CommandDeployer::Config.new( stack: stack, mode: mode, # Currently Opsup deploys only the first app by default. app: apps.first, instance_ids: instances.map(&:instance_id), dryrun: dryrun, ) StackOperator::CommandDeployer.create( config: config, opsworks: @opsworks, logger: @logger, ) end |