kamal-backup 0.3.0.beta15 → 0.3.0.beta16
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 +34 -0
- data/lib/kamal_backup/kamal_bridge.rb +14 -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: 4459cc1c5b400de2e07ab808a8788c3364965bf5f332cc45fafe8388e04e2d59
|
|
4
|
+
data.tar.gz: 1fc19515ad7da4d62f21b8437e58f70e4af65954cdcb2953e5e820c298935476
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: cb97e1c203a0078a1023e30e2f0206a28fd1020edee11108bd88ac081fb35909eb8637d616e1e81b0390ad54905573534147d3e57a660695c033b129113fbaec
|
|
7
|
+
data.tar.gz: aa521cc3dc479d4b37cb9447b7ff2985b96c68323c586d060911d94b445edd1bf680b7094ab88b4a2cca0ebf6f6e0424f0e941d85155a14e7085db114ef9a22b
|
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"
|
|
@@ -250,6 +251,39 @@ module KamalBackup
|
|
|
250
251
|
raise command_not_found(spec, e)
|
|
251
252
|
end
|
|
252
253
|
|
|
254
|
+
def capture_pty(spec, redactor:, tee_stdout: nil)
|
|
255
|
+
output = +""
|
|
256
|
+
tee_buffer = +""
|
|
257
|
+
result = nil
|
|
258
|
+
|
|
259
|
+
PTY.spawn(spec.env, *spec.argv) do |reader, writer, pid|
|
|
260
|
+
writer.close
|
|
261
|
+
|
|
262
|
+
begin
|
|
263
|
+
loop do
|
|
264
|
+
chunk = reader.readpartial(16 * 1024)
|
|
265
|
+
output << chunk
|
|
266
|
+
tee_buffer = tee_stream(tee_stdout, redactor, tee_buffer, chunk) if tee_stdout
|
|
267
|
+
end
|
|
268
|
+
rescue EOFError, Errno::EIO
|
|
269
|
+
flush_tee_stream(tee_stdout, redactor, tee_buffer) if tee_stdout
|
|
270
|
+
ensure
|
|
271
|
+
reader.close unless reader.closed?
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
_, status = Process.wait2(pid)
|
|
275
|
+
result = CommandResult.new(stdout: output, stderr: "", status: status.exitstatus, streamed: !!tee_stdout)
|
|
276
|
+
|
|
277
|
+
unless status.success?
|
|
278
|
+
raise command_failure(spec, status.exitstatus, output, output, redactor)
|
|
279
|
+
end
|
|
280
|
+
end
|
|
281
|
+
|
|
282
|
+
result
|
|
283
|
+
rescue Errno::ENOENT => e
|
|
284
|
+
raise command_not_found(spec, e)
|
|
285
|
+
end
|
|
286
|
+
|
|
253
287
|
def collect_stream(io, command_output: self.output, context: nil, stream: :stdout, log_output: true, tee_io: nil, redactor: nil)
|
|
254
288
|
captured_output = +""
|
|
255
289
|
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,8 @@ 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..."
|
|
264
274
|
end
|
|
265
275
|
end
|
|
266
276
|
|
data/lib/kamal_backup/version.rb
CHANGED