helmsnap 0.4.0 → 0.5.1

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: ae526f7e855d2833a340fc35f9363f212fcfe687aebca504dc0e99e704c6393e
4
- data.tar.gz: 41787e81ec544fc491d2273763a837594415a7792c823faf07fab94e72388845
3
+ metadata.gz: 5f9aee0530e4f99cd1d96fbc07be33606ed5462ebbc08540c568a30848274b85
4
+ data.tar.gz: e2937f100b5e2008d3db5d720a3e4d79393cc760da004bb1453ddab3485a5d50
5
5
  SHA512:
6
- metadata.gz: 65fc8371b350ab030be1503d392b0a2fd5abbe9d68c64bffa1b44662d1c8339e3358b3e15d63de723498732e67540c8d1768272983213cbd7d0f0be47a6c4b1b
7
- data.tar.gz: 3370e09e93f1a0d6b43eb2913046ce44c73905c8f61f6ce79601b627795b2aa69f67c1f7f110fa0f9ef39e0eabe6bf926633d2431d7250ac714d94ed819db3b0
6
+ metadata.gz: 872efd529c6367ca4dfe4468eae9a9d2164e844273a14e9cacea55e07c5c5a795509c7ece536c83e0be75e319651f44ef55d05816e967c4e841b4007d74d67c2
7
+ data.tar.gz: fdb9c9d45daea1554f0d03083e582b6f57be0f78da265b39e4eb11f62e54a0b02fdb5e5abc91f6881c041aad3c47e5501736bd97bc244e0341342d6a4c33dce5
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- helmsnap (0.4.0)
4
+ helmsnap (0.5.1)
5
5
  colorize
6
6
 
7
7
  GEM
@@ -1,35 +1,31 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Helmsnap::Check
4
- def self.call(...)
5
- new(...).call
6
- end
7
-
3
+ class Helmsnap::Check < Helmsnap::Service
8
4
  def initialize(chart_path:, snapshots_path:, values_path:)
5
+ super()
9
6
  self.chart_path = chart_path
10
7
  self.snapshots_path = snapshots_path
11
8
  self.values_path = values_path
12
9
  end
13
10
 
14
11
  def call
15
- Dir.mktmpdir do |temp_dir|
16
- temp_dir_path = Pathname.new(temp_dir)
12
+ temp_dir_path = Pathname.new(Dir.mktmpdir)
17
13
 
18
- Helmsnap::Generate.call(
19
- chart_path: chart_path,
20
- snapshots_path: temp_dir_path,
21
- values_path: values_path,
22
- )
14
+ Helmsnap::Generate.call(
15
+ chart_path: chart_path,
16
+ snapshots_path: temp_dir_path,
17
+ values_path: values_path,
18
+ )
23
19
 
24
- result = Helmsnap.run_cmd("which", "colordiff", allow_failure: true)
25
- util = result.success ? "colordiff" : "diff"
20
+ result = run_cmd("which", "colordiff", allow_failure: true)
21
+ util = result.success ? "colordiff" : "diff"
26
22
 
27
- diff = Helmsnap.run_cmd(
28
- util, "--unified", "--recursive", snapshots_path, temp_dir_path, allow_failure: true
29
- ).output
23
+ cmd_parts = [util, "--unified", "--recursive", snapshots_path, temp_dir_path]
24
+ diff = run_cmd(*cmd_parts, allow_failure: true).output
30
25
 
31
- diff.strip.empty?
32
- end
26
+ diff.strip.empty?
27
+ ensure
28
+ FileUtils.rmtree(temp_dir_path)
33
29
  end
34
30
 
35
31
  private
@@ -1,14 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Helmsnap::Command
3
+ class Helmsnap::Command < Helmsnap::Service
4
4
  Result = Struct.new(:success, :output)
5
5
 
6
- def self.call(...)
7
- new(...).call
8
- end
9
-
10
6
  def initialize(cmd, stdout: $stdout, stderr: $stderr, allow_failure: false)
7
+ super()
11
8
  self.cmd = cmd
9
+ self.output = +""
12
10
  self.stdout = stdout
13
11
  self.stderr = stderr
14
12
  self.allow_failure = allow_failure
@@ -21,12 +19,10 @@ class Helmsnap::Command
21
19
 
22
20
  private
23
21
 
24
- attr_accessor :cmd, :stdout, :stderr, :allow_failure
22
+ attr_accessor :cmd, :output, :stdout, :stderr, :allow_failure
25
23
 
26
24
  def run_command
27
25
  Open3.popen3(cmd) do |_in, out, err, wait_thr|
28
- output = +""
29
-
30
26
  while (chunk = out.gets)
31
27
  Helmsnap::Console.print(stdout, chunk)
32
28
  output << chunk
@@ -34,15 +30,24 @@ class Helmsnap::Command
34
30
 
35
31
  exit_status = wait_thr.value
36
32
  success = exit_status.success?
37
-
38
- if !success && !allow_failure
39
- Helmsnap::Console.error(stderr, err.read)
40
- Helmsnap::Console.error(stderr, "Command failed with status #{exit_status.to_i}")
41
- abort
42
- end
33
+ handle_error!(exit_status, err.read) unless success
43
34
 
44
35
  Helmsnap::Console.print(stdout, "\n")
45
36
  Result.new(success, output)
46
37
  end
38
+ rescue SystemCallError => error
39
+ handle_error!(error.errno, error.message)
40
+ Result.new(false, error.message)
41
+ end
42
+
43
+ def handle_error!(exit_status, err_output)
44
+ Helmsnap::Console.error(stderr, err_output)
45
+
46
+ if allow_failure
47
+ output << err_output
48
+ else
49
+ Helmsnap::Console.error(stderr, "Command failed with status #{exit_status.to_i}")
50
+ exit 1
51
+ end
47
52
  end
48
53
  end
@@ -1,28 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Helmsnap::Generate
4
- def self.call(...)
5
- new(...).call
6
- end
7
-
3
+ class Helmsnap::Generate < Helmsnap::Service
8
4
  def initialize(chart_path:, snapshots_path:, values_path:)
5
+ super()
9
6
  self.chart_path = chart_path
10
7
  self.snapshots_path = snapshots_path
11
8
  self.values_path = values_path
12
9
  end
13
10
 
14
11
  def call
15
- dep_list = run_cmd("helm", "dependency", "list", "--max-col-width", 0, chart_path).output
16
-
17
- dep_list.scan(%r{file://(.+?)\t}) do |dep_path|
18
- run_cmd("helm", "dependency", "update", "--skip-refresh", chart_path.join(dep_path.first))
19
- end
20
-
21
- dep_list.scan(%r{(https?://.+?)\t}) do |dep_path|
22
- run_cmd("helm", "repo", "add", Digest::MD5.hexdigest(dep_path.first), dep_path.first)
23
- end
24
-
25
- run_cmd("helm", "dependency", "update", "--skip-refresh", chart_path)
12
+ Helmsnap::SetupDependencies.call(chart_path)
26
13
 
27
14
  FileUtils.rmtree(snapshots_path)
28
15
 
@@ -40,8 +27,4 @@ class Helmsnap::Generate
40
27
  private
41
28
 
42
29
  attr_accessor :chart_path, :snapshots_path, :values_path
43
-
44
- def run_cmd(...)
45
- Helmsnap.run_cmd(...)
46
- end
47
30
  end
@@ -1,11 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Helmsnap::Runner
4
- def self.call(...)
5
- new(...).call
6
- end
7
-
3
+ class Helmsnap::Runner < Helmsnap::Service
8
4
  def initialize(args)
5
+ super()
9
6
  self.args = args.dup
10
7
  end
11
8
 
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Helmsnap::Service
4
+ def self.call(...)
5
+ new(...).call
6
+ end
7
+
8
+ private
9
+
10
+ def run_cmd(...)
11
+ Helmsnap.run_cmd(...)
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Helmsnap::SetupDependencies < Helmsnap::Service
4
+ def initialize(chart_path)
5
+ super()
6
+ self.chart_path = Pathname.new(chart_path)
7
+ end
8
+
9
+ def call
10
+ dep_list = run_cmd("helm", "dependency", "list", "--max-col-width", 0, chart_path).output
11
+
12
+ dep_list.scan(%r{file://(.+?)\t}) do |dep_path|
13
+ run_cmd("helm", "dependency", "update", "--skip-refresh", chart_path.join(dep_path.first))
14
+ end
15
+
16
+ dep_list.scan(%r{(https?://.+?)\t}) do |dep_path|
17
+ run_cmd("helm", "repo", "add", Digest::MD5.hexdigest(dep_path.first), dep_path.first)
18
+ end
19
+
20
+ run_cmd("helm", "dependency", "update", "--skip-refresh", chart_path)
21
+ end
22
+
23
+ private
24
+
25
+ attr_accessor :chart_path
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Helmsnap
4
- VERSION = "0.4.0"
4
+ VERSION = "0.5.1"
5
5
  end
data/lib/helmsnap.rb CHANGED
@@ -11,13 +11,16 @@ require "tmpdir"
11
11
  require "colorized_string"
12
12
 
13
13
  module Helmsnap
14
+ require_relative "helmsnap/service"
15
+ require_relative "helmsnap/version"
16
+
14
17
  require_relative "helmsnap/args_parser"
15
18
  require_relative "helmsnap/check"
16
- require_relative "helmsnap/console"
17
19
  require_relative "helmsnap/command"
20
+ require_relative "helmsnap/console"
18
21
  require_relative "helmsnap/generate"
19
22
  require_relative "helmsnap/runner"
20
- require_relative "helmsnap/version"
23
+ require_relative "helmsnap/setup_dependencies"
21
24
 
22
25
  class Error < StandardError; end
23
26
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helmsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yuri Smirnov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-12-01 00:00:00.000000000 Z
11
+ date: 2021-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: colorize
@@ -66,6 +66,8 @@ files:
66
66
  - lib/helmsnap/console.rb
67
67
  - lib/helmsnap/generate.rb
68
68
  - lib/helmsnap/runner.rb
69
+ - lib/helmsnap/service.rb
70
+ - lib/helmsnap/setup_dependencies.rb
69
71
  - lib/helmsnap/version.rb
70
72
  homepage: https://github.com/tycooon/helmsnap
71
73
  licenses: