Class: ConsulStockpile::BootstrapConsulKV

Inherits:
Base
  • Object
show all
Defined in:
lib/consul_stockpile/bootstrap_consul_kv.rb

Constant Summary collapse

LOCK_KEY =
'stockpile/bootstrap'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Base

call

Constructor Details

#initialize(bucket:) ⇒ BootstrapConsulKV

Returns a new instance of BootstrapConsulKV.



16
17
18
# File 'lib/consul_stockpile/bootstrap_consul_kv.rb', line 16

def initialize(bucket:)
  self.bucket = bucket
end

Instance Attribute Details

#bucketObject

Returns the value of attribute bucket.



14
15
16
# File 'lib/consul_stockpile/bootstrap_consul_kv.rb', line 14

def bucket
  @bucket
end

Instance Method Details

#callObject



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/consul_stockpile/bootstrap_consul_kv.rb', line 20

def call
  Logger.tagged('Bootstrap') do
    Logger.info 'Starting Consul KV Bootstrap...'

    ConsulLock.with_lock(key: LOCK_KEY) do
      if DetectCanary.call.exists
        Logger.info 'Canary detected; skipping bootstrap.'
        return OpenStruct.new(ran_bootstrap: false)
      end

      json = DownloadBackup.call(bucket: bucket).json_body
      LoadJsonKV.call(json: json)
      BootstrapExternalServices.call
      PlaceCanary.call
    end

    Logger.info 'Bootstrap complete.'
    OpenStruct.new(ran_bootstrap: true)
  end
end