helmsnap 0.6.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/README.md +9 -3
- data/lib/helmsnap/args_parser.rb +14 -6
- data/lib/helmsnap/config.rb +8 -4
- data/lib/helmsnap/env.rb +9 -8
- data/lib/helmsnap/generate.rb +1 -3
- data/lib/helmsnap/runner.rb +6 -0
- data/lib/helmsnap/setup_dependencies.rb +12 -6
- data/lib/helmsnap/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c06eb415d8391af30d789fdf0a28d93c1fd3eeec961927623ee124f4a97c27da
|
4
|
+
data.tar.gz: 1955829609e08db79e13150e4fc96c3cd30df8242f08e00976040c407d2fba0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8f58ea04641722e5adc18e604eb770e8bc1cf64b3db94fc450cd932d7e79e779c00fe88abbf676377499f6e4ec6179a1831f0688fee26fd77dbdc1d21fc99448
|
7
|
+
data.tar.gz: 11a731bf61117fbd8671b56993860b3fc35367d16699297bd962a61d990b187491199a4b06646c911ead81cb5677d8d259b6917737b9b0b6f48d3cca865ef7e8
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
## About
|
4
4
|
|
5
|
-
Helmsnap is a tool for generating and checking
|
5
|
+
Helmsnap is a tool for generating and checking helmfile snapshots. Example:
|
6
6
|
|
7
7
|
Generate snapshots (uses `helmfile template` under the hood):
|
8
8
|
|
@@ -16,6 +16,12 @@ Generate snapshots in a temporary directory and check (diff) them against existi
|
|
16
16
|
helmsnap check
|
17
17
|
```
|
18
18
|
|
19
|
+
Just build dependencies for each release in a helmfile:
|
20
|
+
|
21
|
+
```sh
|
22
|
+
helmsnap dependencies # or `helmsnap deps`
|
23
|
+
```
|
24
|
+
|
19
25
|
Get the full description of possible arguments:
|
20
26
|
|
21
27
|
```sh
|
@@ -59,13 +65,13 @@ Helmsnap will automically replace all occurencies of patterns that look like tim
|
|
59
65
|
|
60
66
|
## Installation
|
61
67
|
|
62
|
-
Just install
|
68
|
+
Just install the gem and use the provided `helmsnap` binary.
|
63
69
|
|
64
70
|
```sh
|
65
71
|
gem install helmsnap
|
66
72
|
```
|
67
73
|
|
68
|
-
Alaternatively, you can use
|
74
|
+
Alaternatively, you can use the [Docker image](https://github.com/tycooon/helmsnap/pkgs/container/helmsnap) with Ruby, helm and helmsnap gem preinstalled. This is useful for CIs or if you don't want to install Ruby and Helmfile on your machine.
|
69
75
|
|
70
76
|
## CI example
|
71
77
|
|
data/lib/helmsnap/args_parser.rb
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Helmsnap::ArgsParser
|
4
|
+
InvalidConfigPath = Class.new(RuntimeError)
|
5
|
+
|
4
6
|
Args = Struct.new(:config_path)
|
5
7
|
|
6
|
-
DEFAULT_CONFIG_PATH = ".helmsnap.yaml"
|
8
|
+
DEFAULT_CONFIG_PATH = Pathname.new(".helmsnap.yaml")
|
7
9
|
CONFIG_PATH_HELP = %{Path to config (default: "#{DEFAULT_CONFIG_PATH}")}
|
8
10
|
BANNER = "Usage: helmsnap CMD [options]"
|
9
11
|
|
@@ -16,8 +18,8 @@ class Helmsnap::ArgsParser
|
|
16
18
|
def get_options!
|
17
19
|
parser.parse!(options)
|
18
20
|
args
|
19
|
-
rescue OptionParser::ParseError => error
|
20
|
-
print_help!(error)
|
21
|
+
rescue OptionParser::ParseError, InvalidConfigPath => error
|
22
|
+
print_help!(error.message)
|
21
23
|
end
|
22
24
|
|
23
25
|
def print_help!(msg)
|
@@ -32,15 +34,21 @@ class Helmsnap::ArgsParser
|
|
32
34
|
|
33
35
|
def build_parser
|
34
36
|
OptionParser.new(BANNER, 50) do |opts|
|
35
|
-
opts.separator("Supported commands: `generate` and `
|
37
|
+
opts.separator("Supported commands: `generate`, `check` and `dependencies`.")
|
36
38
|
opts.separator("")
|
37
39
|
opts.separator("Specific options:")
|
38
40
|
|
39
41
|
opts.on("-c", "--config CONFIG_PATH", CONFIG_PATH_HELP) do |val|
|
40
|
-
|
42
|
+
path = Pathname.new(val)
|
43
|
+
|
44
|
+
unless path.file? && path.readable?
|
45
|
+
raise InvalidConfigPath, "Not a readable file: #{val}"
|
46
|
+
end
|
47
|
+
|
48
|
+
args.config_path = path
|
41
49
|
end
|
42
50
|
|
43
|
-
opts.on("--version", "Show version") do
|
51
|
+
opts.on("-v", "--version", "Show version") do
|
44
52
|
Helmsnap::Console.print($stdout, "#{Helmsnap::VERSION}\n")
|
45
53
|
exit
|
46
54
|
end
|
data/lib/helmsnap/config.rb
CHANGED
@@ -4,9 +4,15 @@ class Helmsnap::Config
|
|
4
4
|
attr_reader :envs, :snapshots_path
|
5
5
|
|
6
6
|
DEFAULT_ENV = "default"
|
7
|
+
DEFAULT_SNAPSHOTS_PATH = "helm/snapshots"
|
7
8
|
|
8
9
|
def initialize(config_path)
|
9
|
-
|
10
|
+
if config_path.exist?
|
11
|
+
yaml = YAML.load_file(config_path.to_s)
|
12
|
+
else
|
13
|
+
yaml = {}
|
14
|
+
end
|
15
|
+
|
10
16
|
self.envs = parse_envs(yaml)
|
11
17
|
self.snapshots_path = parse_snaphots_path(yaml)
|
12
18
|
end
|
@@ -16,13 +22,11 @@ class Helmsnap::Config
|
|
16
22
|
attr_writer :envs, :snapshots_path
|
17
23
|
|
18
24
|
def parse_envs(yaml)
|
19
|
-
# TODO: check value type
|
20
25
|
value = yaml.fetch("envs", [DEFAULT_ENV])
|
21
26
|
value.map { |x| Helmsnap::Env.new(x) }
|
22
27
|
end
|
23
28
|
|
24
29
|
def parse_snaphots_path(yaml)
|
25
|
-
|
26
|
-
Pathname.new(yaml.fetch("snapshotsPath"))
|
30
|
+
Pathname.new(yaml.fetch("snapshotsPath", DEFAULT_SNAPSHOTS_PATH))
|
27
31
|
end
|
28
32
|
end
|
data/lib/helmsnap/env.rb
CHANGED
@@ -1,19 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Helmsnap::Env
|
4
|
-
attr_reader :name
|
4
|
+
attr_reader :name
|
5
5
|
|
6
6
|
def initialize(name)
|
7
7
|
self.name = name
|
8
|
-
self.release_paths = get_release_paths
|
9
8
|
end
|
10
9
|
|
11
|
-
|
10
|
+
def release_paths
|
11
|
+
@release_paths ||= begin
|
12
|
+
json = Helmsnap.run_cmd("helmfile", "--environment", name, "list", "--output", "json").output
|
13
|
+
YAML.load(json).map { |x| Pathname.new(x.fetch("chart")) }
|
14
|
+
end
|
15
|
+
end
|
12
16
|
|
13
|
-
|
17
|
+
private
|
14
18
|
|
15
|
-
|
16
|
-
json = Helmsnap.run_cmd("helmfile", "--environment", name, "list", "--output", "json").output
|
17
|
-
YAML.load(json).map { |x| x.fetch("chart") }
|
18
|
-
end
|
19
|
+
attr_writer :name
|
19
20
|
end
|
data/lib/helmsnap/generate.rb
CHANGED
@@ -10,9 +10,7 @@ class Helmsnap::Generate < Helmsnap::Service
|
|
10
10
|
def call
|
11
11
|
FileUtils.rmtree(snapshots_path)
|
12
12
|
|
13
|
-
|
14
|
-
Helmsnap::SetupDependencies.call(release_path)
|
15
|
-
end
|
13
|
+
Helmsnap::SetupDependencies.call(config)
|
16
14
|
|
17
15
|
config.envs.each do |env|
|
18
16
|
run_cmd(
|
data/lib/helmsnap/runner.rb
CHANGED
@@ -26,6 +26,8 @@ class Helmsnap::Runner < Helmsnap::Service
|
|
26
26
|
generate!
|
27
27
|
when "check"
|
28
28
|
check!
|
29
|
+
when "dependencies", "deps"
|
30
|
+
setup_deps!
|
29
31
|
else
|
30
32
|
parser.print_help!("Unknown command: #{cmd}.")
|
31
33
|
end
|
@@ -55,4 +57,8 @@ class Helmsnap::Runner < Helmsnap::Service
|
|
55
57
|
exit 1
|
56
58
|
end
|
57
59
|
end
|
60
|
+
|
61
|
+
def setup_deps!
|
62
|
+
Helmsnap::SetupDependencies.call(config)
|
63
|
+
end
|
58
64
|
end
|
@@ -1,12 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
class Helmsnap::SetupDependencies < Helmsnap::Service
|
4
|
-
def initialize(
|
4
|
+
def initialize(config)
|
5
5
|
super()
|
6
|
-
self.
|
6
|
+
self.config = config
|
7
7
|
end
|
8
8
|
|
9
9
|
def call
|
10
|
+
config.envs.flat_map(&:release_paths).uniq.each do |chart_path|
|
11
|
+
setup!(chart_path)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
attr_accessor :config
|
18
|
+
|
19
|
+
def setup!(chart_path)
|
10
20
|
dep_list = run_cmd("helm", "dependency", "list", "--max-col-width", 0, chart_path).output
|
11
21
|
|
12
22
|
dep_list.scan(%r{file://(.+?)\t}) do |dep_path|
|
@@ -19,8 +29,4 @@ class Helmsnap::SetupDependencies < Helmsnap::Service
|
|
19
29
|
|
20
30
|
run_cmd("helm", "dependency", "update", "--skip-refresh", chart_path)
|
21
31
|
end
|
22
|
-
|
23
|
-
private
|
24
|
-
|
25
|
-
attr_accessor :chart_path
|
26
32
|
end
|
data/lib/helmsnap/version.rb
CHANGED
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
|
+
version: 0.7.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-
|
11
|
+
date: 2021-12-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|