kamal-backup 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7135af9b16454829f69ed19ca84d58045232e5db583cc54cbc1fe623bf80c4f6
4
- data.tar.gz: 8f70a9143faec5b730e3e9d70a33b4bed4f1f650815f81c97c303766151fd2af
3
+ metadata.gz: 67d289224a384dc9f1546799c15b1bf69649060d49ff8018869b098924104704
4
+ data.tar.gz: 4307158e1472c2aeafbab424fbb1d2af50a1a1cc6a43b2b11ea6dfae5e3b1d42
5
5
  SHA512:
6
- metadata.gz: a919c1e57b6061ce588bd73d00b87eeff13e7b312b3da1bf05d8263116eadc119facc2fedadcba62d21a4d0983835bb52b89486eb13beeeffb3673588ec39845
7
- data.tar.gz: 64739bbaac082b4266d37b2dfbd70d4ad53c7010a825a037126ff4b9cfb828c0968d2dd1045c25cd82fab5371864a2405c10c0edee99152948131f8d8112bf38
6
+ metadata.gz: cba47d9ebf7771e7513e24ca6e7c1d30c5bc3660caeb6ab0f4ed945203baadf370778af5b887a7eb39a82664709f9210179c847c1983d29318befe03abe0e8fa
7
+ data.tar.gz: ff55565395d49eca645732276db416aa2f240b7511468f7d96296821c776937404862835ba977bd7005efba7ea91fb2269f7e7b0f7f4db7e751cb1b375da9ea2
data/README.md CHANGED
@@ -145,6 +145,8 @@ kamal-backup version
145
145
 
146
146
  Production-side commands shell out through Kamal when you pass `-d` or `-c`. Local commands run on your machine.
147
147
 
148
+ Remote-backed commands require the local gem version and the backup accessory version to match. If they drift, `kamal-backup` fails fast and tells you to reboot the accessory so it pulls the current `latest` image. `version` is the diagnostic exception: from an app checkout with `config/deploy.yml`, it shows both versions and the sync status even without `-d`.
149
+
148
150
  Common examples:
149
151
 
150
152
  ```sh
@@ -50,11 +50,25 @@ module KamalBackup
50
50
  !options[:destination].to_s.strip.empty? || !options[:config_file].to_s.strip.empty?
51
51
  end
52
52
 
53
+ def default_deploy_config?
54
+ File.file?(File.expand_path(KamalBridge::DEFAULT_CONFIG_FILE))
55
+ end
56
+
57
+ def version_remote_mode?
58
+ deployment_mode? || default_deploy_config?
59
+ end
60
+
53
61
  def accessory_name
54
62
  @accessory_name ||= bridge.accessory_name(preferred: local_preferences.accessory_name)
55
63
  end
56
64
 
57
- def exec_remote(argv)
65
+ def remote_version
66
+ @remote_version ||= bridge.remote_version(accessory_name: accessory_name)
67
+ end
68
+
69
+ def exec_remote(argv, require_version_match: true)
70
+ ensure_remote_version_match! if require_version_match
71
+
58
72
  result = bridge.execute_on_accessory(
59
73
  accessory_name: accessory_name,
60
74
  command: Shellwords.join(argv)
@@ -63,6 +77,32 @@ module KamalBackup
63
77
  result
64
78
  end
65
79
 
80
+ def ensure_remote_version_match!
81
+ return if remote_version == VERSION
82
+
83
+ raise ConfigurationError, <<~MESSAGE.strip
84
+ local gem version #{VERSION} does not match remote accessory version #{remote_version}.
85
+ Reboot the backup accessory to pick up the latest image:
86
+ #{accessory_reboot_command}
87
+ MESSAGE
88
+ end
89
+
90
+ def accessory_reboot_command
91
+ argv = ["bin/kamal", "accessory", "reboot", accessory_name]
92
+ argv.concat(["-c", options[:config_file]]) if options[:config_file]
93
+ argv.concat(["-d", options[:destination]]) if options[:destination]
94
+ Shellwords.join(argv)
95
+ end
96
+
97
+ def print_remote_version_status
98
+ status = remote_version == VERSION ? "in sync" : "out of sync"
99
+
100
+ puts("local: #{VERSION}")
101
+ puts("remote: #{remote_version}")
102
+ puts("status: #{status}")
103
+ puts("fix: #{accessory_reboot_command}") if status == "out of sync"
104
+ end
105
+
66
106
  def confirm!(message)
67
107
  return if options[:yes]
68
108
 
@@ -344,8 +384,8 @@ module KamalBackup
344
384
 
345
385
  desc "version", "Print the running kamal-backup version"
346
386
  def version
347
- if deployment_mode?
348
- exec_remote(["kamal-backup", "version"])
387
+ if version_remote_mode?
388
+ print_remote_version_status
349
389
  else
350
390
  puts(VERSION)
351
391
  end
@@ -46,6 +46,17 @@ module KamalBackup
46
46
  capture_kamal(kamal_exec_argv(accessory_name, command))
47
47
  end
48
48
 
49
+ def remote_version(accessory_name:)
50
+ result = execute_on_accessory(accessory_name: accessory_name, command: "kamal-backup version")
51
+ version = result.stdout.to_s.strip
52
+
53
+ if version.empty?
54
+ raise ConfigurationError, "could not determine remote kamal-backup version from accessory #{accessory_name}"
55
+ else
56
+ version
57
+ end
58
+ end
59
+
49
60
  private
50
61
  def config
51
62
  @config ||= begin
@@ -1,3 +1,3 @@
1
1
  module KamalBackup
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kamal-backup
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - crmne