opswalrus 1.0.58 → 1.0.59

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 561e5d52fb2898d5c93e6a1b683194ed4dccf1ba476f68be79261cd58de8afba
4
- data.tar.gz: 0cddaa43d4fac68a82c4dd0755486a8dd25c229e46e55c9698e74e69c7eef2bd
3
+ metadata.gz: 7c02e6cf3098713124796fdaddf3630d91434d40a6f0df607cf4184e5cd060c3
4
+ data.tar.gz: bedbfd919aba32a943ac22a1596c439d74879f1e88b0f42a1062dd6fe3c5cc08
5
5
  SHA512:
6
- metadata.gz: 258d673028667b25f58cdf93b2d4fd82dfca0c6058687bccd3f4267d935f807c83ffc7981cbd638099186b6f93ab965a4b3d6f4bd7da2c26018e8378249bc57e
7
- data.tar.gz: 8d234040ba815a0e83cbe15338c51cfdafee068720417ed2ce384e03bb7295a4b7b2ac68a6eca4555a52d56c2656ccc49e5a99887f013c25f4dcd7fe19f1c32c
6
+ metadata.gz: 79e953bac9a4c83104431d0c2ccf871b684810a81283b52ad677d4bff7bee27c804f93ec94be43b3b24a7b6504a40419c6932de1525ed7d1fbc5a4b0293036a6
7
+ data.tar.gz: 1ed925365dd182c27dc922da7aa99319566aefc01154dd8227253bfcf2798f6fc92686c6832941dddb0d55ce1d28148b2e7a3c341c5a4d1c80fa1ba739a74ace
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- opswalrus (1.0.58)
4
+ opswalrus (1.0.59)
5
5
  activesupport (~> 7.0)
6
6
  bcrypt_pbkdf (~> 1.1)
7
7
  binding_of_caller (~> 1.0)
data/lib/opswalrus/app.rb CHANGED
@@ -32,7 +32,7 @@ module OpsWalrus
32
32
  end
33
33
 
34
34
  LOCAL_SUDO_PASSWORD_PROMPT = "[opswalrus] Please enter sudo password to run sudo in local environment: "
35
-
35
+ SCRIPT_RESULT_HEADER = "#### OpsWalrus Script Result JSON ".ljust(80, '#')
36
36
 
37
37
  attr_reader :local_hostname
38
38
  attr_reader :identity_file_paths
@@ -58,7 +58,7 @@ module OpsWalrus
58
58
  @pwd = pwd.to_pathname
59
59
  @bundler = Bundler.new(self, @pwd)
60
60
  @local_hostname = "localhost"
61
- @mode = :report # :report | :script
61
+ @script_mode = false
62
62
  @dry_run = false
63
63
  @zip_mutex = Thread::Mutex.new
64
64
  end
@@ -72,15 +72,11 @@ module OpsWalrus
72
72
  end
73
73
 
74
74
  def script_mode!
75
- @mode = :script
76
- end
77
-
78
- def report_mode?
79
- @mode == :report
75
+ @script_mode = true
80
76
  end
81
77
 
82
78
  def script_mode?
83
- @mode == :script
79
+ @script_mode
84
80
  end
85
81
 
86
82
  def dry_run?
@@ -269,13 +265,7 @@ module OpsWalrus
269
265
  result = op.run([], params_json_hash: {ops_file: ops_file, operation_kv_args: operation_kv_args}.stringify_keys)
270
266
  exit_status = result.exit_status
271
267
 
272
- debug "Op exit_status"
273
- debug exit_status
274
-
275
- debug "Op output"
276
- debug JSON.pretty_generate(result.value)
277
-
278
- puts JSON.pretty_generate(result.value)
268
+ print_script_result(result)
279
269
 
280
270
  exit_status
281
271
  rescue Error => e
@@ -305,13 +295,7 @@ module OpsWalrus
305
295
  result = op.run(operation_kv_args, params_json_hash: @params)
306
296
  exit_status = result.exit_status
307
297
 
308
- debug "Op exit_status"
309
- debug exit_status
310
-
311
- debug "Op output"
312
- debug JSON.pretty_generate(result.value)
313
-
314
- puts JSON.pretty_generate(result.value)
298
+ print_script_result(result)
315
299
 
316
300
  exit_status
317
301
  rescue Error => e
@@ -321,6 +305,17 @@ module OpsWalrus
321
305
  FileUtils.remove_entry(tmp_bundle_root_dir) if tmp_bundle_root_dir
322
306
  end
323
307
 
308
+ def print_script_result(result)
309
+ if script_mode?
310
+ output = StringIO.open do |io|
311
+ io.print(SCRIPT_RESULT_HEADER)
312
+ io.puts JSON.pretty_generate(result.value)
313
+ io.string
314
+ end
315
+ puts output
316
+ end
317
+ end
318
+
324
319
  def load_entry_point_ops_file(ops_file_path, tmp_bundle_root_dir)
325
320
  ops_file = OpsFile.new(self, ops_file_path)
326
321
 
@@ -449,8 +444,8 @@ module OpsWalrus
449
444
  def bundle_status
450
445
  end
451
446
 
452
- def bundle_update
453
- bundler.update
447
+ def bundle_update(force = false)
448
+ bundler.update(force)
454
449
  end
455
450
 
456
451
  def report_inventory(host_references, tags: nil)
@@ -55,7 +55,7 @@ module OpsWalrus
55
55
  # bundler_for_package.include_directory_in_bundle_as_self_pkg(pwd)
56
56
  # end
57
57
 
58
- def update()
58
+ def update(force = false)
59
59
  # delete_pwd_bundle_directory # this was causing problems when we do: ops run -r -b ... because a dynamic package reference was being
60
60
  # downloaded to the bundle dir, and then update was being called afterward, which was blowing away
61
61
  # the entire bundle dir, so when the bundle dir was copied to the remote host, the ops file being
@@ -66,22 +66,22 @@ module OpsWalrus
66
66
  package_yaml_files = pwd.glob("./**/package.yaml") - pwd.glob("./**/#{BUNDLE_DIR}/**/package.yaml")
67
67
  package_files_within_pwd = package_yaml_files.map {|path| PackageFile.new(path.realpath) }
68
68
 
69
- download_package_dependency_tree(package_files_within_pwd)
69
+ download_package_dependency_tree(package_files_within_pwd, force: force)
70
70
 
71
71
  ops_files = pwd.glob("./**/*.ops") - pwd.glob("./**/#{BUNDLE_DIR}/**/*.ops")
72
72
  ops_files_within_pwd = ops_files.map {|path| OpsFile.new(@app, path.realpath) }
73
73
 
74
- download_import_dependencies(ops_files_within_pwd)
74
+ download_import_dependencies(ops_files_within_pwd, force: force)
75
75
  end
76
76
 
77
77
  # downloads all transitive package dependencies associated with ops_files_and_package_files
78
78
  # all downloaded packages are placed into @bundle_dir
79
- def download_package_dependency_tree(*ops_files_and_package_files)
79
+ def download_package_dependency_tree(*ops_files_and_package_files, force: false)
80
80
  package_files = ops_files_and_package_files.flatten.map(&:package_file).compact.uniq
81
81
 
82
82
  package_files.each do |root_package_file|
83
83
  pre_order_traverse(root_package_file) do |package_file|
84
- download_package_dependencies(package_file).map do |downloaded_package_directory_path|
84
+ download_package_dependencies(package_file, force: force).map do |downloaded_package_directory_path|
85
85
  package_file_path = File.join(downloaded_package_directory_path, "package.yaml")
86
86
  PackageFile.new(package_file_path)
87
87
  end
@@ -89,13 +89,13 @@ module OpsWalrus
89
89
  end
90
90
  end
91
91
 
92
- def download_import_dependencies(*ops_files)
92
+ def download_import_dependencies(*ops_files, force: false)
93
93
  ops_files.flatten.each do |ops_file|
94
94
  ops_file.imports.each do |local_name, import_reference|
95
95
  case import_reference
96
96
  when PackageDependencyReference, DynamicPackageImportReference
97
97
  package_reference = import_reference.package_reference
98
- download_package(ops_file.dirname, ops_file.ops_file_path, package_reference)
98
+ download_package(ops_file.dirname, ops_file.ops_file_path, package_reference, force: force)
99
99
  when DirectoryReference
100
100
  # noop
101
101
  when OpsFileReference
@@ -107,11 +107,11 @@ module OpsWalrus
107
107
 
108
108
  # returns the array of the destination directories that the packages that ops_file depend on were downloaded to
109
109
  # e.g. [dir_path1, dir_path2, dir_path3, ...]
110
- def download_package_dependencies(package_file)
110
+ def download_package_dependencies(package_file, force: false)
111
111
  containing_directory = package_file.containing_directory
112
112
  package_file_source = package_file.package_file_path
113
113
  package_file.dependencies.map do |local_name, package_reference|
114
- download_package(containing_directory, package_file_source, package_reference)
114
+ download_package(containing_directory, package_file_source, package_reference, force: force)
115
115
  end
116
116
  end
117
117
 
@@ -138,7 +138,7 @@ module OpsWalrus
138
138
  # returns the destination directory that the package was downloaded to
139
139
  #
140
140
  # relative_base_path is the relative base path that any relative file paths captured in the package_reference should be evaluated relative to
141
- def download_package(relative_base_path, source_of_package_reference, package_reference)
141
+ def download_package(relative_base_path, source_of_package_reference, package_reference, force: false)
142
142
  ensure_pwd_bundle_directory_exists
143
143
 
144
144
  local_name = package_reference.local_name
@@ -152,11 +152,11 @@ module OpsWalrus
152
152
 
153
153
  # we return early here under the assumption that an already downloaded package/version combo will not
154
154
  # differ if we download it again multiple times to the same location
155
- if destination_package_path.exist?
155
+ if destination_package_path.exist? && !force
156
156
  App.instance.log("Skipping #{package_reference} referenced in #{source_of_package_reference} since it already has been downloaded to #{destination_package_path}")
157
157
  return destination_package_path
158
158
  end
159
- # FileUtils.remove_dir(destination_package_path) if destination_package_path.exist?
159
+ FileUtils.remove_dir(destination_package_path) if destination_package_path.exist?
160
160
 
161
161
  # download_package_contents(package_file.containing_directory, local_name, package_url, version, destination_package_path)
162
162
  download_package_contents(relative_base_path, local_name, package_url, version, destination_package_path)
data/lib/opswalrus/cli.rb CHANGED
@@ -275,10 +275,12 @@ module OpsWalrus
275
275
  desc 'Update bundle dependencies'
276
276
  long_desc 'Download and bundle the latest versions of dependencies for the current package'
277
277
  c.command :update do |update|
278
+ update.switch [:f, :force], desc: "Force update even if the package has already been downloaded"
279
+
278
280
  update.action do |global_options, options, args|
279
281
  $app.set_log_level(global_options[:loudest] && :trace || global_options[:louder] && :debug || global_options[:loud] && :info || :warn)
280
282
 
281
- $app.bundle_update
283
+ $app.bundle_update(options[:force])
282
284
  end
283
285
  end
284
286
 
@@ -122,8 +122,8 @@ module OpsWalrus
122
122
  end
123
123
 
124
124
  # invoke the ops command on the remote host to run the specified ops script on the remote host
125
- ops_command_options = ""
126
- ops_command_options << "--pass" if @ops_prompt_for_sudo_password
125
+ ops_command_options = "--script"
126
+ ops_command_options << " --pass" if @ops_prompt_for_sudo_password
127
127
  ops_command_options << " --params #{remote_json_kwargs_tempfile_basename}" if remote_json_kwargs_tempfile_basename
128
128
  retval = if ops_command_options.empty?
129
129
  @host_proxy.run_ops(:run, remote_run_command_args, ops_prompt_for_sudo_password: @ops_prompt_for_sudo_password)
@@ -232,8 +232,8 @@ module OpsWalrus
232
232
  end
233
233
 
234
234
  # invoke the ops command on the remote host to run the specified ops script on the remote host
235
- ops_command_options = ""
236
- ops_command_options << "--pass" if @ops_prompt_for_sudo_password
235
+ ops_command_options = "--script"
236
+ ops_command_options << " --pass" if @ops_prompt_for_sudo_password
237
237
  ops_command_options << " --params #{remote_json_kwargs_tempfile_basename}" if remote_json_kwargs_tempfile_basename
238
238
  retval = if ops_command_options.empty?
239
239
  @host_proxy.run_ops(:run, remote_run_command_args, ops_prompt_for_sudo_password: @ops_prompt_for_sudo_password)
@@ -110,13 +110,6 @@ module OpsWalrus
110
110
  Invocation::Error.new(e)
111
111
  end
112
112
 
113
- # if result.failure?
114
- # App.instance.debug "Ops script error details:"
115
- # App.instance.debug "Error: #{result.value}"
116
- # App.instance.debug "Status code: #{result.exit_status}"
117
- # App.instance.debug @entry_point_ops_file.script.to_s
118
- # end
119
-
120
113
  result
121
114
  end
122
115
  end
@@ -322,21 +322,23 @@ module OpsWalrus
322
322
  puts output_block unless output_block.empty?
323
323
 
324
324
  t1 = Time.now
325
- out, err, exit_status = yield
325
+ output, stderr, exit_status = yield
326
326
  t2 = Time.now
327
327
  seconds = t2 - t1
328
328
 
329
+ stdout, remote_ops_script_retval = parse_stdout_and_script_return_value(output)
330
+
329
331
  output_block = StringIO.open do |io|
330
332
  if App.instance.info? # this is true if log_level is trace, debug, info
331
333
  if App.instance.trace?
332
- io.puts Style.cyan(out)
333
- io.puts Style.red(err)
334
+ io.puts Style.cyan(stdout)
335
+ io.puts Style.red(stderr)
334
336
  elsif App.instance.debug?
335
- io.puts Style.cyan(out)
336
- io.puts Style.red(err)
337
+ io.puts Style.cyan(stdout)
338
+ io.puts Style.red(stderr)
337
339
  elsif App.instance.info?
338
- io.puts Style.cyan(out)
339
- io.puts Style.red(err)
340
+ io.puts Style.cyan(stdout)
341
+ io.puts Style.red(stderr)
340
342
  end
341
343
  io.print Style.yellow(cmd_id)
342
344
  io.print Style.blue(" | Finished in #{seconds} seconds with exit status ")
@@ -359,7 +361,23 @@ module OpsWalrus
359
361
  end
360
362
  puts output_block unless output_block.empty?
361
363
 
362
- [out, err, exit_status]
364
+ out = remote_ops_script_retval || stdout
365
+ [out, stderr, exit_status]
366
+ end
367
+
368
+ def parse_stdout_and_script_return_value(command_output)
369
+ output_sections = command_output.split(/^#{::OpsWalrus::App::SCRIPT_RESULT_HEADER}$/)
370
+ case output_sections.count
371
+ when 1
372
+ stdout, ops_script_retval = output_sections.first, nil
373
+ when 2
374
+ stdout, ops_script_retval = *output_sections
375
+ else
376
+ # this is unexpected
377
+ ops_script_retval = output_sections.pop
378
+ stdout = output_sections.join(::OpsWalrus::App::SCRIPT_RESULT_HEADER)
379
+ end
380
+ [stdout, ops_script_retval]
363
381
  end
364
382
 
365
383
  end
@@ -1,3 +1,3 @@
1
1
  module OpsWalrus
2
- VERSION = "1.0.58"
2
+ VERSION = "1.0.59"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: opswalrus
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.58
4
+ version: 1.0.59
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Ellis
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-09-23 00:00:00.000000000 Z
11
+ date: 2023-09-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport