Class: KamalBackup::KamalBridge

Inherits:
Object
  • Object
show all
Defined in:
lib/kamal_backup/kamal_bridge.rb

Constant Summary collapse

DEFAULT_CONFIG_FILE =
"config/deploy.yml"

Instance Method Summary collapse

Constructor Details

#initialize(redactor:, config_file: nil, destination: nil) ⇒ KamalBridge

Returns a new instance of KamalBridge.



8
9
10
11
12
# File 'lib/kamal_backup/kamal_bridge.rb', line 8

def initialize(redactor:, config_file: nil, destination: nil)
  @redactor = redactor
  @config_file = config_file
  @destination = destination
end

Instance Method Details

#accessory_name(preferred: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kamal_backup/kamal_bridge.rb', line 14

def accessory_name(preferred: nil)
  if preferred && !preferred.to_s.strip.empty?
    accessory_clear_env(preferred)
    return preferred.to_s
  end

  matching = accessories.select do |_name, accessory|
    fetch(accessory, :image).to_s.include?("kamal-backup")
  end

  if matching.size == 1
    matching.keys.first.to_s
  elsif accessories.key?("backup") || accessories.key?(:backup)
    "backup"
  else
    names = accessories.keys.map(&:to_s).sort
    raise ConfigurationError, "could not infer the backup accessory from #{names.join(', ')}; set accessory in config/kamal-backup.yml"
  end
end

#execute_on_accessory(accessory_name:, command:) ⇒ Object



45
46
47
# File 'lib/kamal_backup/kamal_bridge.rb', line 45

def execute_on_accessory(accessory_name:, command:)
  capture_kamal(kamal_exec_argv(accessory_name, command))
end

#local_restore_defaults(accessory_name:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
# File 'lib/kamal_backup/kamal_bridge.rb', line 34

def local_restore_defaults(accessory_name:)
  clear_env = accessory_clear_env(accessory_name)

  {}.tap do |defaults|
    defaults["APP_NAME"] = clear_env["APP_NAME"] if clear_env["APP_NAME"]
    defaults["DATABASE_ADAPTER"] = clear_env["DATABASE_ADAPTER"] if clear_env["DATABASE_ADAPTER"]
    defaults["RESTIC_REPOSITORY"] = clear_env["RESTIC_REPOSITORY"] if clear_env["RESTIC_REPOSITORY"]
    defaults["LOCAL_RESTORE_SOURCE_PATHS"] = clear_env["BACKUP_PATHS"] if clear_env["BACKUP_PATHS"]
  end
end