Class: Opsup::StackOperator::CommandDeployer

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/opsup/stack_operator/command_deployer.rb

Defined Under Namespace

Classes: Config

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config:, opsworks:, logger:) ⇒ CommandDeployer

Returns a new instance of CommandDeployer.



35
36
37
38
39
# File 'lib/opsup/stack_operator/command_deployer.rb', line 35

def initialize(config:, opsworks:, logger:)
  @config = T.let(config, Config)
  @opsworks = T.let(opsworks, Aws::OpsWorks::Client)
  @logger = T.let(logger, ::Logger)
end

Class Method Details

.create(config:, opsworks:, logger:) ⇒ Object



24
25
26
# File 'lib/opsup/stack_operator/command_deployer.rb', line 24

def self.create(config:, opsworks:, logger:)
  new(config: config, opsworks: opsworks, logger: logger)
end

Instance Method Details

#run_command(command) ⇒ Object



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
68
69
70
71
72
# File 'lib/opsup/stack_operator/command_deployer.rb', line 42

def run_command(command)
  mode = @config.mode
  instance_ids = @config.instance_ids
  dryrun = @config.dryrun

  @logger.info("Running #{command} command in #{mode} mode...")

  case mode
  when :parallel
    @logger.info("Creating single deployment for the #{instance_ids.size} instances...")
    create_deployment(command, instance_ids) unless dryrun
  when :serial
    instance_ids.each.with_index do |id, i|
      @logger.info("Creating deployment for instances[#{i}] (#{id})...")
      create_deployment(command, [id]) unless dryrun
    end
  when :one_then_all
    @logger.info("Creating deployment for the first instance (#{instance_ids[0]})...")
    create_deployment(command, [T.must(instance_ids[0])]) unless dryrun

    rest = T.must(instance_ids[1..-1])
    if !rest.empty?
      @logger.info("Creating deployment for the other #{rest.size} instances...")
      create_deployment(command, rest) unless dryrun
    else
      @logger.info('No other instances exist.')
    end
  else
    raise "Unknown running mode: #{mode}"
  end
end