minfra-cli 0.1.0 → 0.2.2

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: fdef57265500c1ab2f82470de61a21d1d604d4cdbc198f2acbcafdab9cb37548
4
- data.tar.gz: f7a25a0c65239ccaa49331a0e94d14494b92a44927df112c2258d6b42ef51420
3
+ metadata.gz: 4c095831fd4a669abd1381046091e615395c93e367051ee051bf48c458167d63
4
+ data.tar.gz: 3b7219fba8adb56249c8be8f249751613c9f9e529d7a8d9341f44c32e69271ac
5
5
  SHA512:
6
- metadata.gz: e2875bcf474cbed4017f6fb5e7188745b04357e0181a9ab1d8641d041d880e3152624e21f4fed4317a9c4a24c1c1e3d00c552f4fcaf558324a78d74d08de8930
7
- data.tar.gz: f6ae3c0c3a82ca453a886a8d1bfc6ea2170a967f42094a482d769cbb40f60706416f2592465202afc2e04f7bd957068730d8da1420b14b6c13c331864770e1ca
6
+ metadata.gz: 45aacbd112f2797e1b177f477b9456cb955a20576a11442c8c4799609bbe6a226177d29c3ac1ff27a9b2270a1fd2fd2ac6fe4bd1ab5e813e823ff13bfd1e960c
7
+ data.tar.gz: 81bd7e7366bf87ca8c048289e74ec3bc2e5819456c6b386063e1831d8465bb2cb4cc18cd573ada93a5aefdd0c5392bba50be02348a31616ff447f60975ab65e2
data/CHANGELOG.md CHANGED
@@ -1,2 +1,4 @@
1
+ # 0.2.2 Secrets support in charts
2
+
1
3
  # 0.1.0 Initial
2
4
  * opensourcing a base state, still WIP!
data/bin/run_tests CHANGED
@@ -61,7 +61,7 @@ volumes << "..:/code" unless ENV["BUILD_ID"]
61
61
 
62
62
  # Run docker pull on cache
63
63
  if @cache_tag
64
- run("docker pull 858049876441.dkr.ecr.eu-west-1.amazonaws.com/#{@project_name}:#{@cache_tag}")
64
+ run("docker pull TBD/#{@project_name}:#{@cache_tag}")
65
65
  end
66
66
 
67
67
  erb = ERB.new(File.open("#{__dir__}/../spec/docker-compose.yml").read, 0, '>')
@@ -87,13 +87,13 @@ module Minfra
87
87
 
88
88
  method = options["install"] ? "install" : "upgrade"
89
89
  File.open(stack.compose_path(blank: true),"w") do |f|
90
- Orchparty.print(cluster_name: cluster,
91
- application_name: stack.name,
92
- force_variable_definition: false,
93
- file_name: stack.stack_rb_path.to_s,
94
- method: method,
95
- options: options,
96
- out_io: f)
90
+ Orchparty::App.new(cluster_name: cluster,
91
+ application_name: stack.name,
92
+ force_variable_definition: false,
93
+ file_name: stack.stack_rb_path.to_s,
94
+ options: options
95
+ ).
96
+ print( method: method, out_io: f)
97
97
  end
98
98
  #run_cmd(generate_cmd, :bash)
99
99
  bash_cmd = ["cd #{stack.release_path}"]
@@ -128,7 +128,13 @@ module Minfra
128
128
 
129
129
  message = "deploying stack #{stack.name}: #{reason_message}."
130
130
  Minfra::Cli::Document.document(@config,"started #{message}")
131
- Orchparty.send(method, cluster_name: cluster, application_name: stack.name, force_variable_definition: false, file_name: stack.stack_rb_path.to_s, options: options)
131
+ orch=Orchparty::App.new(cluster_name: cluster,
132
+ application_name: stack.name,
133
+ force_variable_definition: false,
134
+ file_name: stack.stack_rb_path.to_s,
135
+ options: options
136
+ )
137
+ orch.send(method)
132
138
  Minfra::Cli::Document.document(@config,"finished #{message}")
133
139
  end
134
140
  end
@@ -1,5 +1,5 @@
1
1
  module Minfra
2
2
  module Cli
3
- VERSION = '0.1.0'.freeze
3
+ VERSION = '0.2.2'.freeze
4
4
  end
5
5
  end
data/lib/minfra/cli.rb CHANGED
@@ -19,7 +19,7 @@ require_relative 'cli/plugins'
19
19
  require 'active_support'
20
20
  require 'active_support/core_ext'
21
21
 
22
- require "ENV['MINFRA_PATH']/config/preload.rb" if File.exist?("ENV['MINFRA_PATH']/config/preload.rb")
22
+ require "#{ENV['MINFRA_PATH']}/config/preload.rb" if File.exist?("#{ENV['MINFRA_PATH']}/config/preload.rb")
23
23
 
24
24
  module Minfra
25
25
  module Cli
@@ -188,6 +188,7 @@ module Orchparty
188
188
  self
189
189
  end
190
190
 
191
+
191
192
  def wait(&block)
192
193
  name = SecureRandom.hex
193
194
  result = ServiceBuilder.build(name, "wait", block)
@@ -214,7 +215,6 @@ module Orchparty
214
215
  end
215
216
 
216
217
  def service(name, &block)
217
-
218
218
  chart_name = @application.name
219
219
  unless @application.services[chart_name]
220
220
  @application.services[chart_name] = AST.chart(name: chart_name, _type: "chart" )
@@ -332,6 +332,14 @@ module Orchparty
332
332
  def initialize(name, type)
333
333
  super AST.service(name: name, _type: type)
334
334
  end
335
+
336
+ # 1. rememebring the secrets in environment_secrets (so these environments can be created differentyly
337
+ # 2. create Secret sections
338
+ def environment_secrets(&block)
339
+ result = HashBuilder.build(block)
340
+ @node.environment_secrets = result
341
+ self
342
+ end
335
343
  end
336
344
 
337
345
  class ServiceMixinBuilder < CommonBuilder
@@ -356,6 +364,15 @@ module Orchparty
356
364
  @node._services << name
357
365
  self
358
366
  end
367
+
368
+ def secrets(name, &block)
369
+ result = ServiceBuilder.build(name, "chart-secret", block)
370
+ @application.services[name] = result
371
+ @application._service_order << name
372
+ @node._services << name
373
+ self
374
+ end
375
+
359
376
  end
360
377
  end
361
378
  end
@@ -32,6 +32,7 @@ module Orchparty
32
32
  if(file_path.end_with?(".erb"))
33
33
  helm.application = OpenStruct.new(cluster_name: cluster_name, namespace: namespace)
34
34
  template = Erubis::Eruby.new(File.read(file_path))
35
+ template.filename = file_path
35
36
  yaml = template.result(helm.get_binding)
36
37
  file = Tempfile.new("kube-deploy.yaml")
37
38
  file.write(yaml)
@@ -117,14 +118,6 @@ module Orchparty
117
118
  @out_io.puts upgrade_cmd(label)
118
119
  end
119
120
 
120
- def upgrade(label)
121
- @out_io.puts system(upgrade_cmd(label))
122
- end
123
-
124
- def install(label)
125
- @out_io.puts system(install_cmd(label))
126
- end
127
-
128
121
  def upgrade_cmd(label)
129
122
  "kubectl --namespace #{namespace} --context #{cluster_name} label --overwrite #{label[:resource]} #{label[:name]} #{label["value"]}"
130
123
  end
@@ -184,7 +177,6 @@ module Orchparty
184
177
  output_chart_path: output_chart_path,
185
178
  chart_name: chart.name,
186
179
  )
187
-
188
180
  params.each do |app_name, subparams|
189
181
  subparams[:chart] = chart
190
182
  generate_documents_from_erbs(
@@ -203,12 +195,13 @@ module Orchparty
203
195
  end
204
196
 
205
197
  kind = params.fetch(:kind)
206
-
207
198
  Dir[File.join(templates_path, kind, '*.erb')].each do |template_path|
199
+ puts "Rendering Template: #{template_path}"
208
200
  template_name = File.basename(template_path, '.erb')
209
201
  output_path = File.join(output_chart_path, 'templates', "#{app_name}-#{template_name}")
210
202
 
211
203
  template = Erubis::Eruby.new(File.read(template_path))
204
+ template.filename = template_path
212
205
  params.app_name = app_name
213
206
  params.templates_path = templates_path
214
207
  begin
@@ -216,7 +209,7 @@ module Orchparty
216
209
  rescue Exception
217
210
  puts "#{template_path} has a problem: #{$!.inspect}"
218
211
  raise
219
- end
212
+ end
220
213
  File.write(output_path, document)
221
214
  end
222
215
  end
@@ -226,6 +219,7 @@ module Orchparty
226
219
  output_path = File.join(output_chart_path, 'Chart.yaml')
227
220
 
228
221
  template = Erubis::Eruby.new(File.read(template_path))
222
+ template.filename = template_path
229
223
  params = Hashie::Mash.new(chart_name: chart_name)
230
224
  document = template.result(CleanBinding.new.get_binding(params))
231
225
  File.write(output_path, document)
@@ -249,6 +243,7 @@ module Orchparty
249
243
 
250
244
  def upgrade(chart)
251
245
  build_chart(chart) do |chart_path|
246
+ system("cp -a #{chart_path} /tmp/latest-chart")
252
247
  @out_io.puts system("helm upgrade --namespace #{namespace} --kube-context #{cluster_name} #{chart.name} #{chart_path}")
253
248
  end
254
249
  end
@@ -299,6 +294,7 @@ class KubernetesApplication
299
294
  services = combine_charts(app_config)
300
295
  services.each do |name|
301
296
  service = app_config[:services][name]
297
+ puts "Service: #{name} #{method}"
302
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)
303
299
  end
304
300
  end
data/lib/orchparty.rb CHANGED
@@ -1,59 +1,85 @@
1
- require "deep_merge"
2
- require "orchparty/version"
3
- require "orchparty/ast"
4
- require "orchparty/context"
5
- require "orchparty/transformations"
6
- require "orchparty/dsl_parser"
7
- require "orchparty/dsl_parser_kubernetes"
8
- require "orchparty/plugin"
9
- require "orchparty/kubernetes_application"
10
- require "hash"
1
+ # frozen_string_literal: true
11
2
 
12
- module Orchparty
3
+ require 'deep_merge'
4
+ require 'orchparty/version'
5
+ require 'orchparty/ast'
6
+ require 'orchparty/context'
7
+ require 'orchparty/transformations'
8
+ require 'orchparty/dsl_parser'
9
+ require 'orchparty/dsl_parser_kubernetes'
10
+ require 'orchparty/plugin'
11
+ require 'orchparty/kubernetes_application'
12
+ require 'hash'
13
13
 
14
- def self.load_all_available_plugins
15
- Gem::Specification.map {|f| f.matches_for_glob("orchparty/plugins/*.rb") }.flatten.map{|file_name| File.basename(file_name, ".*").to_sym }.each do |plugin_name|
16
- plugin(plugin_name)
17
- end
18
- end
14
+ module Orchparty
19
15
 
20
16
  def self.options
21
- @@options || {}
17
+ @@options
22
18
  end
23
- def self.plugins
24
- Orchparty::Plugin.plugins
19
+ def self.options=(opt)
20
+ @@options=opt
25
21
  end
22
+
23
+ class App
24
+ attr_reader :options
26
25
 
27
- def self.plugin(name)
28
- Orchparty::Plugin.load_plugin(name)
29
- end
26
+ def initialize(cluster_name:, application_name:, force_variable_definition:, file_name:, options: {})
27
+ @cluster_name = cluster_name
28
+ @application_name = application_name
29
+ @force_variable_definiton = force_variable_definition
30
+ @file_name = file_name
31
+ @options = options
32
+ Orchparty.options=options
33
+
34
+ load_plugins
35
+ end
30
36
 
31
- def self.ast(filename: , application:, force_variable_definition: nil )
32
- Transformations.transform(Orchparty::DSLParser.new(filename).parse, force_variable_definition: force_variable_definition).applications[application]
33
- end
37
+ def plugins
38
+ Orchparty::Plugin.plugins
39
+ end
34
40
 
35
- def self.generate(plugin_name, options, plugin_options)
36
- plugins[plugin_name].generate(ast(options), plugin_options)
37
- end
41
+ def print(method:, out_io:)
42
+ app(out_io: out_io).print(method)
43
+ end
38
44
 
39
- def self.install(cluster_name: , application_name: , force_variable_definition:, file_name:, options: )
40
- @@options= options
41
- app_config = Transformations.transform_kubernetes(Orchparty::Kubernetes::DSLParser.new(file_name).parse, force_variable_definition: force_variable_definition).applications[application_name]
42
- app = KubernetesApplication.new(app_config: app_config, namespace: application_name, cluster_name: cluster_name, file_name: file_name)
43
- app.install
44
- end
45
+ def install
46
+ app.install
47
+ end
45
48
 
46
- def self.upgrade(cluster_name: , application_name: , force_variable_definition:, file_name:, options: )
47
- @@options = options
48
- app_config = Transformations.transform_kubernetes(Orchparty::Kubernetes::DSLParser.new(file_name).parse, force_variable_definition: force_variable_definition).applications[application_name]
49
- app = KubernetesApplication.new(app_config: app_config, namespace: application_name, cluster_name: cluster_name, file_name: file_name)
50
- app.upgrade
51
- end
49
+ def upgrade
50
+ app.upgrade
51
+ end
52
+
53
+ private
54
+
55
+ def app(out_io: STDOUT)
56
+ parsed = Orchparty::Kubernetes::DSLParser.new(@file_name).parse
57
+ 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)
59
+ end
60
+
61
+ def generate(plugin_name, options, plugin_options)
62
+ plugins[plugin_name].generate(ast(options), plugin_options)
63
+ end
52
64
 
53
- def self.print(cluster_name: , application_name: , force_variable_definition:, file_name:, method:, options:, out_io: )
54
- @@options= options
55
- app_config = Transformations.transform_kubernetes(Orchparty::Kubernetes::DSLParser.new(file_name).parse, force_variable_definition: force_variable_definition).applications[application_name]
56
- app = KubernetesApplication.new(app_config: app_config, namespace: application_name, cluster_name: cluster_name, file_name: file_name, out_io: out_io)
57
- app.print(method)
65
+ def ast(filename:, application:, force_variable_definition: nil)
66
+ Transformations.transform(Orchparty::DSLParser.new(filename).parse,
67
+ force_variable_definition: force_variable_definition).applications[application]
68
+ end
69
+
70
+ def load_plugins
71
+ Gem::Specification.map do |f|
72
+ f.matches_for_glob('orchparty/plugins/*.rb')
73
+ end.flatten.map do |file_name|
74
+ File.basename(file_name,
75
+ '.*').to_sym
76
+ end.each do |plugin_name|
77
+ plugin(plugin_name)
78
+ end
79
+ end
80
+
81
+ def plugin(name)
82
+ Orchparty::Plugin.load_plugin(name)
83
+ end
58
84
  end
59
85
  end
data/minfra-cli.gemspec CHANGED
@@ -33,8 +33,4 @@ Gem::Specification.new do |spec|
33
33
  spec.add_runtime_dependency "hashie", "~>3.5"
34
34
  spec.add_runtime_dependency "activesupport", "~> 6.1"
35
35
  spec.add_runtime_dependency "erubis", "~> 2.7"
36
-
37
- #gem 'byebug', require: true # convenience
38
- #gem 'graphiti'
39
- #gem 'faraday'
40
36
  end
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: 0.1.0
4
+ version: 0.2.2
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-06-03 00:00:00.000000000 Z
11
+ date: 2022-07-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -110,7 +110,6 @@ extra_rdoc_files: []
110
110
  files:
111
111
  - ".dockerignore"
112
112
  - ".gitignore"
113
- - ".rspec"
114
113
  - CHANGELOG.md
115
114
  - Dockerfile
116
115
  - bin/build
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --format progress
2
- --color