kamal-backup 0.3.0.beta15 → 0.3.0.beta17
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 +4 -4
- data/lib/kamal_backup/command.rb +38 -0
- data/lib/kamal_backup/kamal_bridge.rb +15 -4
- data/lib/kamal_backup/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 88d55c67a4d6276ea516c9d3149ee486c3da3587a438856fa08ba0050f0b99d0
|
|
4
|
+
data.tar.gz: '09290fe105b1ef100c9d59f8631426f86ee169977cb5561e4308aec05f3e3eb5'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f0de6a3b23a06e127b860b63d2227ba154272ef6da3e011943f8d82fae445b4f676ae89e8f52931aaf11ea142c73d5fb417e8e360c04912bb42604d2fcf6b76
|
|
7
|
+
data.tar.gz: a26fb0fbc1b23f03a0e3316606e07c3df718368e42bb3ac8d082218dc9c1bf4e3ff010695812e3532b1f09bd1c878b979aaff0098b9c04389c07abd097a38354
|
data/lib/kamal_backup/command.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "open3"
|
|
2
|
+
require "pty"
|
|
2
3
|
require "securerandom"
|
|
3
4
|
require "shellwords"
|
|
4
5
|
require_relative "errors"
|
|
@@ -169,6 +170,10 @@ module KamalBackup
|
|
|
169
170
|
end
|
|
170
171
|
|
|
171
172
|
def local_target
|
|
173
|
+
if remote_host = @env["KAMAL_HOST"].to_s
|
|
174
|
+
return "on #{colorize(remote_host, :blue)}" unless remote_host.empty?
|
|
175
|
+
end
|
|
176
|
+
|
|
172
177
|
user = @env["USER"].to_s.empty? ? @env["USERNAME"].to_s : @env["USER"].to_s
|
|
173
178
|
|
|
174
179
|
if user.empty?
|
|
@@ -250,6 +255,39 @@ module KamalBackup
|
|
|
250
255
|
raise command_not_found(spec, e)
|
|
251
256
|
end
|
|
252
257
|
|
|
258
|
+
def capture_pty(spec, redactor:, tee_stdout: nil)
|
|
259
|
+
output = +""
|
|
260
|
+
tee_buffer = +""
|
|
261
|
+
result = nil
|
|
262
|
+
|
|
263
|
+
PTY.spawn(spec.env, *spec.argv) do |reader, writer, pid|
|
|
264
|
+
writer.close
|
|
265
|
+
|
|
266
|
+
begin
|
|
267
|
+
loop do
|
|
268
|
+
chunk = reader.readpartial(16 * 1024)
|
|
269
|
+
output << chunk
|
|
270
|
+
tee_buffer = tee_stream(tee_stdout, redactor, tee_buffer, chunk) if tee_stdout
|
|
271
|
+
end
|
|
272
|
+
rescue EOFError, Errno::EIO
|
|
273
|
+
flush_tee_stream(tee_stdout, redactor, tee_buffer) if tee_stdout
|
|
274
|
+
ensure
|
|
275
|
+
reader.close unless reader.closed?
|
|
276
|
+
end
|
|
277
|
+
|
|
278
|
+
_, status = Process.wait2(pid)
|
|
279
|
+
result = CommandResult.new(stdout: output, stderr: "", status: status.exitstatus, streamed: !!tee_stdout)
|
|
280
|
+
|
|
281
|
+
unless status.success?
|
|
282
|
+
raise command_failure(spec, status.exitstatus, output, output, redactor)
|
|
283
|
+
end
|
|
284
|
+
end
|
|
285
|
+
|
|
286
|
+
result
|
|
287
|
+
rescue Errno::ENOENT => e
|
|
288
|
+
raise command_not_found(spec, e)
|
|
289
|
+
end
|
|
290
|
+
|
|
253
291
|
def collect_stream(io, command_output: self.output, context: nil, stream: :stdout, log_output: true, tee_io: nil, redactor: nil)
|
|
254
292
|
captured_output = +""
|
|
255
293
|
tee_buffer = +""
|
|
@@ -219,7 +219,7 @@ module KamalBackup
|
|
|
219
219
|
argv
|
|
220
220
|
end
|
|
221
221
|
|
|
222
|
-
def capture_kamal(argv, stream: false, log: !stream, stdout: @stdout, stderr: @stderr)
|
|
222
|
+
def capture_kamal(argv, stream: false, log: !stream, stdout: @stdout, stderr: @stderr, pty: false)
|
|
223
223
|
spec = CommandSpec.new(argv: argv, env: kamal_stream_env(stream))
|
|
224
224
|
options = {
|
|
225
225
|
redactor: @redactor,
|
|
@@ -230,7 +230,15 @@ module KamalBackup
|
|
|
230
230
|
}
|
|
231
231
|
|
|
232
232
|
if defined?(Bundler)
|
|
233
|
-
Bundler.with_unbundled_env {
|
|
233
|
+
Bundler.with_unbundled_env { capture_command(spec, options, pty: pty) }
|
|
234
|
+
else
|
|
235
|
+
capture_command(spec, options, pty: pty)
|
|
236
|
+
end
|
|
237
|
+
end
|
|
238
|
+
|
|
239
|
+
def capture_command(spec, options, pty:)
|
|
240
|
+
if pty
|
|
241
|
+
Command.capture_pty(spec, redactor: options.fetch(:redactor), tee_stdout: options[:tee_stdout])
|
|
234
242
|
else
|
|
235
243
|
Command.capture(spec, **options)
|
|
236
244
|
end
|
|
@@ -249,7 +257,8 @@ module KamalBackup
|
|
|
249
257
|
kamal_exec_argv(accessory_name, command, interactive: true),
|
|
250
258
|
stream: true,
|
|
251
259
|
log: false,
|
|
252
|
-
stdout: filtered_interactive_stdout
|
|
260
|
+
stdout: filtered_interactive_stdout,
|
|
261
|
+
pty: true
|
|
253
262
|
)
|
|
254
263
|
Command.output&.command_exit(context, result.status) if context
|
|
255
264
|
result
|
|
@@ -260,7 +269,9 @@ module KamalBackup
|
|
|
260
269
|
|
|
261
270
|
def filtered_interactive_stdout
|
|
262
271
|
FilteringIO.new(@stdout) do |output|
|
|
263
|
-
|
|
272
|
+
stripped = output.to_s.gsub(/\e\[[0-9;]*m/, "").delete("\r").strip
|
|
273
|
+
stripped == "Launching interactive command via SSH from existing container..." ||
|
|
274
|
+
stripped.match?(/\AConnection to .+ closed\.\z/)
|
|
264
275
|
end
|
|
265
276
|
end
|
|
266
277
|
|
data/lib/kamal_backup/version.rb
CHANGED