helm-wrapper 1.6.2 → 1.7.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d0c6825235f55e18927bc81c56ee25b1a2da087cb13abc76c331b262a21e4948
4
- data.tar.gz: c884c4abc0009521dfdc11d5a8a4c71e8839a45012a0165d6dcdeceb31314601
3
+ metadata.gz: 141b2ae006039883e281b95616f3ee6f44da3623e4bccf38c50a616f896ef25b
4
+ data.tar.gz: ac1155aaa3afce63dd46b3502fb6f412e0da6a4b2809c3dc04d22c4766d38b7c
5
5
  SHA512:
6
- metadata.gz: 20da545ab1511ef1220b31d21aeca1b35f0f0967dbd96dfb8086d023f372960b6f135c6203c2e500a92989e2e802110864be49dc4643684f36cab278583b1b02
7
- data.tar.gz: ce9bd34edf9c901d5e711e67ce6002acd0d70f03d3dbcb6b94b30f971721bf3592cede7595df3eefb6f0b6c235bae707e5a7b72bc6460bb9cf7aab84c4eb2204
6
+ metadata.gz: f19b2c92e6685320a8d335729402377c28a2a80ae9d4d6f5a1a61943bfaee94fec8f0d4531e1c712fad1cde8431b4d93427b75463cf41ef30dc336b7232e7f9c
7
+ data.tar.gz: ef40889f9d01ae740ad1e367c7fd37a38d99eea9a2700937d0534c7597afbcd0b901209b1d80791a429bc39485af50534ea1577c8601d352dc2cba2631f8650f
@@ -14,6 +14,10 @@ module HelmWrapper
14
14
 
15
15
  include HelmWrapper::Shared::Logging
16
16
 
17
+ ###############################################################################
18
+
19
+ @@chart_metadata_file = "Chart.yaml"
20
+
17
21
  ###############################################################################
18
22
 
19
23
  attr_reader :artefact
@@ -25,22 +29,24 @@ module HelmWrapper
25
29
  ###############################################################################
26
30
 
27
31
  def initialize(options:)
28
- logger.fatal("Chart name must be a string!") unless options["name"].kind_of?(String)
29
- logger.fatal("Chart name must not be blank!") if options["name"].strip.empty?
32
+ if options["path"].nil? then
33
+ @path = options["path"]
30
34
 
31
- @name = options["name"]
35
+ logger.fatal("Chart name must be a string!") unless options["name"].kind_of?(String)
36
+ logger.fatal("Chart name must not be blank!") if options["name"].strip.empty?
37
+ @name = options["name"]
32
38
 
33
- unless options["path"].nil? then
39
+ logger.fatal("Chart version must be a string!") unless options["version"].kind_of?(String)
40
+ @version = options["version"]
41
+ else
34
42
  logger.fatal("Chart path must be a string!") unless options["path"].kind_of?(String)
35
43
  logger.fatal("Chart path must not be blank!") if options["path"].strip.empty?
36
44
  logger.fatal("Chart path must exist!") unless File.directory?(options["path"])
37
- end
38
-
39
- @path = options["path"]
40
45
 
41
- logger.fatal("Chart version must be a string!") unless options["version"].kind_of?(String)
46
+ @path = options["path"]
42
47
 
43
- @version = options["version"]
48
+ load_metadata
49
+ end
44
50
 
45
51
  logger.fatal("Chart repos must be a list of hashes!") unless options["repos"].kind_of?(Array)
46
52
 
@@ -49,11 +55,7 @@ module HelmWrapper
49
55
  @oci = Array.new
50
56
  @artefact = Array.new
51
57
 
52
- repos.each do |repo| logger.fatal("Configuration name must be a string!") unless options["name"].kind_of?(String)
53
- logger.fatal("Configuration name must not be blank!") if options["name"].strip.empty?
54
-
55
- @name = options["name"]
56
-
58
+ repos.each do |repo|
57
59
  logger.fatal("All elements of chart repos must be hashes!") unless repo.kind_of?(Hash)
58
60
 
59
61
  logger.fatal("Chart repo: #{hash["name"]} must have a type attribute!") unless repo.key?("type")
@@ -113,6 +115,39 @@ module HelmWrapper
113
115
  oci[index]["active"] = active
114
116
  end
115
117
 
118
+ ###############################################################################
119
+
120
+ private
121
+
122
+ ###############################################################################
123
+
124
+ def load_metadata
125
+ file = File.join(@path, @@chart_metadata_file)
126
+
127
+ if File.file?(file)
128
+ logger.info("Loading chart metadata from: #{file}...")
129
+ else
130
+ logger.fatal("Chart metadata file: #{file} not found!")
131
+ end
132
+
133
+ yaml = YAML.load(File.read(file))
134
+ logger.fatal("Invalid YAML in chart metadata file: #{file}") unless yaml.kind_of?(Hash)
135
+
136
+ logger.fatal("Chart name is missing from chart metadata file!") unless yaml.key?("name")
137
+ logger.fatal("Chart name is not a string in chart metadata file!") unless yaml["name"].kind_of?(String)
138
+ logger.fatal("Chart name is blank in chart metadata file!") if yaml["name"].strip.empty?
139
+
140
+ @name = yaml["name"]
141
+
142
+ logger.fatal("Chart version is missing from chart metadata file!") unless yaml.key?("version")
143
+ logger.fatal("Chart version is not a string in chart metadata file!") unless yaml["version"].kind_of?(String)
144
+ logger.fatal("Chart version is blank in chart metadata file!") if yaml["version"].strip.empty?
145
+
146
+ @version = yaml["version"]
147
+
148
+ logger.info("Metadata loaded: #{@name} version: #{@version}")
149
+ end
150
+
116
151
  ###############################################################################
117
152
 
118
153
  end
@@ -175,25 +175,29 @@ module HelmWrapper
175
175
 
176
176
  ###############################################################################
177
177
 
178
- def push(tag:)
179
- logger.fatal("Cannot Helm push before initialising repositories!") unless repos
180
-
178
+ def package(destination: ".")
181
179
  parameters = Array.new
182
- parameters.append("push")
183
- parameters.append("\"#{@chart.name}:#{tag}\"")
180
+ parameters.append("--destination=\"#{destination}\"")
181
+ parameters.append("\"#{@chart.path}\"")
184
182
 
185
- logger.fatal("Helm push failed!") unless run(action: "chart", parameters: parameters)
183
+ logger.fatal("Helm package failed!") unless run(action: "package", parameters: parameters)
186
184
  end
187
185
 
188
186
  ###############################################################################
189
187
 
190
- def save(tag:)
188
+ def push(source: ".", destination:)
189
+ logger.fatal("Cannot Helm push before initialising repositories!") unless repos
190
+
191
+ package_name = "#{@chart.name}-#{@chart.version}.tgz"
192
+ package_path = File.join(source, package_name)
193
+
194
+ logger.fatal("Must package before pushing! Package: #{package_path} not found!") unless File.file?(package_path)
195
+
191
196
  parameters = Array.new
192
- parameters.append("save")
193
- parameters.append("\"#{@chart.path}\"")
194
- parameters.append("\"#{@chart.name}:#{tag}\"")
197
+ parameters.append("\"#{package_path}\"")
198
+ parameters.append("\"#{destination}\"")
195
199
 
196
- logger.fatal("Helm save failed!") unless run(action: "chart", parameters: parameters)
200
+ logger.fatal("Helm push failed!") unless run(action: "push", parameters: parameters)
197
201
  end
198
202
 
199
203
  ###############################################################################
@@ -18,12 +18,14 @@ module HelmWrapper
18
18
 
19
19
  @binary
20
20
  @chart
21
+ @destination
21
22
 
22
23
  ###############################################################################
23
24
 
24
- def initialize(binary:, chart:)
25
- @binary = binary
26
- @chart = chart
25
+ def initialize(binary:, chart:, destination:)
26
+ @binary = binary
27
+ @chart = chart
28
+ @destination = destination
27
29
 
28
30
  yield self if block_given?
29
31
 
@@ -34,8 +36,7 @@ module HelmWrapper
34
36
 
35
37
  def push_task
36
38
  desc "Pushes a Helm chart to an OCI Helm repository."
37
- task :push, [:tag, :clean] => :binary do |t, args|
38
- tag = (args[:tag].kind_of?(String) and (not args[:tag].strip.empty?)) ? args[:tag].strip : "latest"
39
+ task :push, [:clean] => :binary do |t, args|
39
40
  clean = args[:clean].kind_of?(String) ? args[:clean].downcase == "true" : true
40
41
 
41
42
  runner = HelmWrapper::Shared::Runner.new(binary: @binary, chart: @chart)
@@ -44,8 +45,8 @@ module HelmWrapper
44
45
 
45
46
  begin
46
47
  runner.init_repos
47
- runner.save(tag: tag)
48
- runner.push(tag: tag)
48
+ runner.package
49
+ runner.push(destination: @destination)
49
50
  ensure
50
51
  runner.clean(repos: clean)
51
52
  end
@@ -4,7 +4,7 @@ module HelmWrapper
4
4
 
5
5
  ###############################################################################
6
6
 
7
- VERSION = "1.6.2"
7
+ VERSION = "1.7.0"
8
8
 
9
9
  ###############################################################################
10
10
 
data/lib/helm-wrapper.rb CHANGED
@@ -25,6 +25,7 @@ module HelmWrapper
25
25
  def self.deployment_tasks(chart:, namespace:, release:, options: Hash.new)
26
26
  @logger.info("Building deployment tasks for release: #{release}...")
27
27
 
28
+ @logger.fatal("Chart must be specified as a string!") unless chart.kind_of?(String)
28
29
  @logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
29
30
 
30
31
  binary_options = Hash.new
@@ -60,9 +61,11 @@ module HelmWrapper
60
61
 
61
62
  ###############################################################################
62
63
 
63
- def self.development_tasks(chart:, path:, oci: false, options: Hash.new)
64
+ def self.development_tasks(path:, destination: String.new, options: Hash.new)
64
65
  @logger.info("Building development tasks for path: #{path}...")
65
66
 
67
+ @logger.fatal("Path must be specified as a string!") unless path.kind_of?(String)
68
+ @logger.fatal("Destination must be specified as a string!") unless destination.kind_of?(String)
66
69
  @logger.fatal("Options must be specified as a hash!") unless options.kind_of?(Hash)
67
70
 
68
71
  binary_options = Hash.new
@@ -70,17 +73,16 @@ module HelmWrapper
70
73
  binary_options["version"] = options.key?("binary-version") ? options["binary-version"] : Shared::Latest.instance.version
71
74
 
72
75
  chart_options = Hash.new
73
- chart_options["name"] = chart
74
- chart_options["path"] = path
75
- chart_options["repos"] = options.key?("chart-repos") ? options["chart-repos"] : Array.new
76
- chart_options["version"] = String.new
76
+ chart_options["name"] = nil
77
+ chart_options["path"] = path
78
+ chart_options["repos"] = options.key?("chart-repos") ? options["chart-repos"] : Array.new
77
79
 
78
80
  binary = HelmWrapper::Shared::Binary.new(options: binary_options)
79
81
  chart = HelmWrapper::Shared::Chart.new(options: chart_options)
80
82
 
81
83
  tasks = Array.new
82
84
  tasks << HelmWrapper::Tasks::Binary.new(binary: binary)
83
- tasks << HelmWrapper::Tasks::Push.new(binary: binary, chart: chart) if oci
85
+ tasks << HelmWrapper::Tasks::Push.new(binary: binary, chart: chart, destination: destination) unless destination.strip.empty?
84
86
  tasks << HelmWrapper::Tasks::Validate.new(binary: binary, chart: chart)
85
87
  return tasks
86
88
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: helm-wrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.2
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Lees
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-24 00:00:00.000000000 Z
11
+ date: 2021-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake