minfra-cli 1.0.2 → 1.1.0

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: 5c2cd6c0f9b45301e739a4bd6498b506268d3ea4f668d9c5437d2f39c0e4cc30
4
- data.tar.gz: 9d6dbf72959dcb9fa91787ddb2fb54610a3d8b1d6b023f09d5339e939e24e212
3
+ metadata.gz: ad8c40bad784c7d620305dd1f0b352e96c51d21a985017cbf98550b110d8ee6d
4
+ data.tar.gz: 7f5895eeaf923585c2e7072d09b3bac513228662c09761c89af81ec442a374d2
5
5
  SHA512:
6
- metadata.gz: ca47a07f705b40f20a27372ce57c574db9e0dce1ef35a8c07b94858119bda680fe27201d8767ea482268ea856211e3bd3d8f0d1e58126e6feb4ced103d5da99a
7
- data.tar.gz: 5085dce8b8d6cf68fd572dbba57a4587088d49c65a6dcd7669d5cdd4f43f71c15874022775be78e1808a91a25ed4b539d1ac55078e090aa4ecc2e302755ac208
6
+ metadata.gz: 599880ad0ff8161584e13abdd479371c793cc551ef6f788d556bd5ae5f4e742399539a150ca896f84781a9796ac91e7c0134172d53e952106cb9067c7cd0d91c
7
+ data.tar.gz: 1cf840dac8f60258804e20ffeee65b3c41e6c6248ff9a08b187000ad145bd498ca540b0be090739e12b135f8a68a5b443f662be6d684e087316dc667a9772351
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 1.1.0
2
+ * adding state path so stacks/ is now read only and all generated states are in state/
3
+ * logger's output always goes to STDERR
4
+
1
5
  # 1.0.2
2
6
  * looking up cluster name by hiera cluster.id
3
7
  # 1.0.1
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # minfra-cli
2
+
3
+ Is a KIND (k8s in docker) based development environment.
4
+
5
+
6
+
7
+ ## Expected hiera data
8
+
9
+ * l("cluster").id: the k8s name of the cluster
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+ # Orchparty
25
+
26
+ It's a fork of the original orchparty. TBD: see
27
+
28
+ The base is an application
29
+
30
+ an application can have
31
+ * services
32
+ * apply
33
+ * environment
34
+ * variables
35
+ * configurations
36
+ * secrets
@@ -86,18 +86,21 @@ module Minfra
86
86
  cluster = stack.cluster_name
87
87
 
88
88
  method = options["install"] ? "install" : "upgrade"
89
- File.open(stack.compose_path(blank: true),"w") do |f|
89
+
90
+ stack.release_path.mkpath
91
+
92
+ File.open(stack.compose_path,"w") do |f|
90
93
  Orchparty::App.new(cluster_name: cluster,
91
94
  application_name: stack.name,
92
95
  force_variable_definition: false,
93
96
  file_name: stack.stack_rb_path.to_s,
97
+ status_dir: stack.release_path,
94
98
  options: options
95
99
  ).
96
100
  print( method: method, out_io: f)
97
101
  end
98
102
  #run_cmd(generate_cmd, :bash)
99
103
  bash_cmd = ["cd #{stack.release_path}"]
100
- bash_cmd << "cp #{stack.compose_path(blank: true)} #{stack.compose_path}"
101
104
  run_cmd(bash_cmd, :bash)
102
105
 
103
106
 
@@ -132,6 +135,7 @@ module Minfra
132
135
  application_name: stack.name,
133
136
  force_variable_definition: false,
134
137
  file_name: stack.stack_rb_path.to_s,
138
+ status_dir: stack.release_path,
135
139
  options: options
136
140
  )
137
141
  orch.send(method)
@@ -5,16 +5,17 @@ module Minfra
5
5
  class KubeStackTemplate
6
6
  include ::Minfra::Cli::Logging
7
7
 
8
- attr_reader :name, :env, :deployment
8
+ attr_reader :name, :env, :deployment, :config_path
9
9
  def initialize(name, config, deployment: '', cluster:)
10
10
  @name = name
11
- @path = config.stacks_path.join(name)
11
+ @config_path = config.stacks_path.join(name)
12
12
  @errors = []
13
13
  @config = config
14
14
  @env = config.orch_env
15
15
  @deployment = deployment.freeze
16
16
  @cluster = cluster.freeze || l!("cluster").id
17
- puts "Stack selection: #{@name}, #{@path}, #{@cluster}"
17
+ @result_path = config.status_path.join('stacks', @cluster, name)
18
+ puts "Stack selection: #{@name}, #{@config_path}, #{@cluster}, #{@result_path}"
18
19
  end
19
20
 
20
21
  def cluster_name
@@ -26,8 +27,8 @@ module Minfra
26
27
  end
27
28
 
28
29
  def valid?
29
- unless @path.exist?
30
- @errors << "stack path #{@path} doesn't exist"
30
+ unless @config_path.exist?
31
+ @errors << "stack path #{@config_path} doesn't exist"
31
32
  end
32
33
 
33
34
  unless stack_rb_path.exist?
@@ -37,7 +38,7 @@ module Minfra
37
38
  end
38
39
 
39
40
  def stack_rb_path
40
- release_path.join('stack.rb')
41
+ config_path.join('stack.rb')
41
42
  end
42
43
 
43
44
  def compose_path(blank: false)
@@ -55,7 +56,7 @@ module Minfra
55
56
  end
56
57
 
57
58
  def release_path
58
- @path
59
+ @result_path
59
60
  end
60
61
 
61
62
 
@@ -16,6 +16,7 @@ module Minfra
16
16
  attr_reader :base_path
17
17
  attr_reader :config_path
18
18
  attr_reader :stacks_path
19
+ attr_reader :status_path
19
20
  attr_reader :me_path
20
21
  attr_reader :kube_path
21
22
  attr_reader :kube_config_path
@@ -41,6 +42,7 @@ module Minfra
41
42
  @project_config_path=@base_path.join("config","project.json")
42
43
  @config_path = @me_path.join('config.json')
43
44
  @stacks_path = @base_path.join('stacks')
45
+ @status_path = @base_path.join('state')
44
46
  @kube_path=@me_path.join('kube')
45
47
  @kube_config_path=@kube_path.join('config')
46
48
  @kind_config_path=@me_path.join("kind.yaml.erb")
@@ -11,15 +11,15 @@ module Minfra
11
11
  end
12
12
 
13
13
  def info(str)
14
- STDOUT.puts str
14
+ STDERR.puts str
15
15
  end
16
16
 
17
17
  def debug(str)
18
- STDOUT.puts "Debug: #{str}"
18
+ STDERR.puts "Debug: #{str}"
19
19
  end
20
20
 
21
21
  def deprecated(comment)
22
- puts "DEPRECATED: #{comment}"
22
+ STDERR.puts "DEPRECATED: #{comment}"
23
23
  end
24
24
  end
25
25
  end
@@ -1,5 +1,5 @@
1
1
  module Minfra
2
2
  module Cli
3
- VERSION = '1.0.2'.freeze
3
+ VERSION = '1.1.0'.freeze
4
4
  end
5
5
  end
@@ -16,11 +16,12 @@ module Orchparty
16
16
  attr_accessor :app_config
17
17
  attr_accessor :options
18
18
 
19
- def initialize(cluster_name: , namespace:, file_path: , app_config:, out_io: STDOUT)
19
+ def initialize(cluster_name: , namespace:, file_path: , app_config:, out_io: STDOUT, app: )
20
20
  self.cluster_name = cluster_name
21
21
  self.namespace = namespace
22
22
  self.dir_path = file_path
23
23
  self.app_config = app_config
24
+ @app = app
24
25
  @out_io = out_io
25
26
  self.options=options
26
27
  end
@@ -158,14 +159,13 @@ module Orchparty
158
159
 
159
160
  def build_chart(chart)
160
161
  params = chart._services.map {|s| app_config.services[s.to_sym] }.map{|s| [s.name, s]}.to_h
161
- Dir.mktmpdir("#{chart.name}-") do |dir|
162
- run(templates_path: File.expand_path(chart.template, self.dir_path), params: params, output_chart_path: dir, chart: chart)
163
- yield dir
164
- end
162
+ dir = @app.status_dir.join('helm')
163
+ dir.mkpath
164
+ run(templates_path: File.expand_path(chart.template, self.dir_path), params: params, output_chart_path: dir, chart: chart)
165
+ yield dir
165
166
  end
166
167
 
167
168
  def run(templates_path:, params:, output_chart_path:, chart: )
168
- system("mkdir -p #{output_chart_path}")
169
169
  system("mkdir -p #{File.join(output_chart_path, 'templates')}")
170
170
 
171
171
  system("cp #{File.join(templates_path, 'values.yaml')} #{File.join(output_chart_path, 'values.yaml')}")
@@ -256,12 +256,14 @@ class KubernetesApplication
256
256
  attr_accessor :file_path
257
257
  attr_accessor :namespace
258
258
  attr_accessor :app_config
259
+ attr_reader :status_dir
259
260
 
260
- def initialize(app_config: [], namespace:, cluster_name:, file_name:, out_io: STDOUT)
261
+ def initialize(app_config: [], namespace:, cluster_name:, file_name:, status_dir:, out_io: STDOUT)
261
262
  self.file_path = Pathname.new(file_name).parent.expand_path
262
263
  self.cluster_name = cluster_name
263
264
  self.namespace = namespace
264
265
  self.app_config = app_config
266
+ @status_dir = status_dir
265
267
  @out_io= out_io
266
268
  end
267
269
 
@@ -295,7 +297,7 @@ class KubernetesApplication
295
297
  services.each do |name|
296
298
  service = app_config[:services][name]
297
299
  puts "Service: #{name}(#{service._type}) #{method}"
298
- "::Orchparty::Services::#{service._type.classify}".constantize.new(cluster_name: cluster_name, namespace: namespace, file_path: file_path, app_config: app_config, out_io: @out_io).send(method, service)
300
+ "::Orchparty::Services::#{service._type.classify}".constantize.new(cluster_name: cluster_name, namespace: namespace, file_path: file_path, app_config: app_config, out_io: @out_io, app: self).send(method, service)
299
301
  end
300
302
  end
301
303
  end
data/lib/orchparty.rb CHANGED
@@ -23,12 +23,14 @@ module Orchparty
23
23
  class App
24
24
  attr_reader :options
25
25
 
26
- def initialize(cluster_name:, application_name:, force_variable_definition:, file_name:, options: {})
26
+ def initialize(cluster_name:, application_name:, force_variable_definition:, file_name:, status_dir:, options: {})
27
27
  @cluster_name = cluster_name
28
28
  @application_name = application_name
29
29
  @force_variable_definiton = force_variable_definition
30
30
  @file_name = file_name
31
+ @status_dir = status_dir
31
32
  @options = options
33
+
32
34
  Orchparty.options=options
33
35
 
34
36
  load_plugins
@@ -55,7 +57,14 @@ module Orchparty
55
57
  def app(out_io: STDOUT)
56
58
  parsed = Orchparty::Kubernetes::DSLParser.new(@file_name).parse
57
59
  app_config = Transformations.transform_kubernetes(parsed, force_variable_definition: @force_variable_definition).applications[@application_name]
58
- KubernetesApplication.new(app_config: app_config, namespace: @application_name, cluster_name: @cluster_name, file_name: @file_name, out_io: out_io)
60
+ KubernetesApplication.new(
61
+ app_config: app_config,
62
+ namespace: @application_name,
63
+ cluster_name: @cluster_name,
64
+ file_name: @file_name,
65
+ status_dir: @status_dir,
66
+ out_io: out_io
67
+ )
59
68
  end
60
69
 
61
70
  def generate(plugin_name, options, plugin_options)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: minfra-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Schrammel
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-30 00:00:00.000000000 Z
11
+ date: 2022-10-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -156,6 +156,7 @@ files:
156
156
  - Dockerfile
157
157
  - Gemfile
158
158
  - Gemfile.lock
159
+ - README.md
159
160
  - bin/build
160
161
  - bin/console
161
162
  - bin/container_exec