minfra-cli 1.2.2 → 1.4.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 +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +1 -0
- data/lib/minfra/cli/commands/plugin.rb +21 -0
- data/lib/minfra/cli/commands/setup.rb +1 -1
- data/lib/minfra/cli/config.rb +0 -2
- data/lib/minfra/cli/logging.rb +12 -4
- data/lib/minfra/cli/main_command.rb +3 -4
- data/lib/minfra/cli/plugins.rb +94 -20
- data/lib/minfra/cli/version.rb +1 -1
- data/lib/minfra/cli.rb +30 -12
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 062b08fed3f437e66cba2ea56351bf02e5eb6a7b63d3444be0f1b4251e72f5db
|
4
|
+
data.tar.gz: 0147da78b9f61955e9a5c180a0c6d8a8118c7a66d37cc6c745385e0827de9bfe
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b089c62ba6c7ee464f540324eeb8820e4a5ced14a0f06fdd78afa814dc5b3b1a32408933a34e769ed6f4493cb9ffba3b59d0d02c1f3cb5f48bd073b8eb1cc3bf
|
7
|
+
data.tar.gz: 2941ebd620a97afd4294757a3e28b7b49d669e30703609527d11a2b9ad43aab7410593810bfd127e4a91e118677dd9e8ea561676d41e499907c5549853f41381
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
# 1.
|
1
|
+
# 1.4.0
|
2
|
+
* plugin managment
|
3
|
+
* changed logging (added central logger, and configurable loglevel: MINFRA_LOGGING_LEVEL minfra.logging_level)
|
4
|
+
* hiera main path can be configured (minfra.hiera.env_path)
|
5
|
+
* fixed kube subcommand
|
6
|
+
# 1.3.0
|
7
|
+
* deep lookup value like "env.cluster.name"
|
8
|
+
# 1.2.2
|
2
9
|
* fixing tagging
|
3
10
|
# 1.2.1
|
4
11
|
* fixing merge
|
data/README.md
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
module Minfra
|
2
|
+
module Cli
|
3
|
+
class Plugin < Command
|
4
|
+
|
5
|
+
desc "describe","describe plugins"
|
6
|
+
def describe
|
7
|
+
Minfra::Cli.plugins.each do |plugin|
|
8
|
+
puts "#{plugin.name} (#{plugin.version})"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
desc "install", "install plugins"
|
12
|
+
def install
|
13
|
+
Minfra::Cli.plugins.each do |plugin|
|
14
|
+
puts "setup: #{plugin.name}"
|
15
|
+
plugin.install
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
Minfra::Cli.register("plugin", "dealing wit plugins", Minfra::Cli::Plugin)
|
data/lib/minfra/cli/config.rb
CHANGED
@@ -36,7 +36,6 @@ module Minfra
|
|
36
36
|
end
|
37
37
|
|
38
38
|
def init!(base_path_str=nil)
|
39
|
-
debug( "Config: initializing" )
|
40
39
|
@base_path = Pathname.new(base_path_str || ENV["MINFRA_PATH"]).expand_path
|
41
40
|
@me_path = @base_path.join('me')
|
42
41
|
@project_config_path=@base_path.join("config","project.json")
|
@@ -62,7 +61,6 @@ module Minfra
|
|
62
61
|
end
|
63
62
|
|
64
63
|
def load(orch_env)
|
65
|
-
debug( "loading config env: #{orch_env} #{@orch_env}" )
|
66
64
|
return self if defined?(@orch_env)
|
67
65
|
@orch_env = orch_env
|
68
66
|
@orch_env_config=Hashie::Mash.new
|
data/lib/minfra/cli/logging.rb
CHANGED
@@ -2,7 +2,7 @@ module Minfra
|
|
2
2
|
module Cli
|
3
3
|
module Logging
|
4
4
|
def error(str)
|
5
|
-
|
5
|
+
logger.error str
|
6
6
|
end
|
7
7
|
|
8
8
|
def exit_error(str)
|
@@ -11,15 +11,23 @@ module Minfra
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def info(str)
|
14
|
-
|
14
|
+
logger.info str
|
15
|
+
end
|
16
|
+
|
17
|
+
def warn(str)
|
18
|
+
logger.warn str
|
15
19
|
end
|
16
20
|
|
17
21
|
def debug(str)
|
18
|
-
|
22
|
+
logger.debug str
|
19
23
|
end
|
20
24
|
|
21
25
|
def deprecated(comment)
|
22
|
-
|
26
|
+
logger.warn "DEPRECATED: #{comment}"
|
27
|
+
end
|
28
|
+
private
|
29
|
+
def logger
|
30
|
+
Minfra::Cli.logger
|
23
31
|
end
|
24
32
|
end
|
25
33
|
end
|
@@ -3,12 +3,11 @@ module Minfra
|
|
3
3
|
class Main < Command
|
4
4
|
|
5
5
|
desc 'kube', 'kubectl wrapper and other features'
|
6
|
-
long_desc '
|
7
|
-
'
|
8
|
-
option :environment, required: false, aliases: ['-e']
|
9
6
|
option :cluster
|
7
|
+
option :stack, required: true
|
10
8
|
def kube(*args)
|
11
|
-
|
9
|
+
kube = Kube.new(options, @minfra_config)
|
10
|
+
kube.kubectl_command(args)
|
12
11
|
end
|
13
12
|
|
14
13
|
# tbd: move this to project
|
data/lib/minfra/cli/plugins.rb
CHANGED
@@ -1,34 +1,108 @@
|
|
1
1
|
module Minfra
|
2
2
|
module Cli
|
3
3
|
class Plugins
|
4
|
+
class Plugin
|
5
|
+
include Logging
|
6
|
+
attr_reader :name, :version, :opts, :path
|
7
|
+
|
8
|
+
|
9
|
+
def initialize(name:, version:, opts:, disabled:)
|
10
|
+
@name= name
|
11
|
+
@version = version
|
12
|
+
@opts = opts.merge(require: false)
|
13
|
+
@disabled= disabled
|
14
|
+
if opts["path"]
|
15
|
+
@path= Minfra::Cli.config.base_path.join(opts["path"])
|
16
|
+
end
|
17
|
+
end
|
18
|
+
def disabled?
|
19
|
+
@disabled
|
20
|
+
end
|
21
|
+
|
22
|
+
#adds the plugin to the
|
23
|
+
def prepare
|
24
|
+
debug("plugin prepare: #{name}, #{version}, disabled: #{disabled?}")
|
25
|
+
return if disabled?
|
26
|
+
if path
|
27
|
+
begin
|
28
|
+
lib_path=path.join('lib')
|
29
|
+
$LOAD_PATH.unshift lib_path
|
30
|
+
require name
|
31
|
+
rescue Gem::Requirement::BadRequirementError, LoadError
|
32
|
+
warn("plugin prepare path: #{name} (#{$!})")
|
33
|
+
end
|
34
|
+
else
|
35
|
+
begin
|
36
|
+
@gem_spec=Gem::Specification.find_by_name(name)
|
37
|
+
gem name, version
|
38
|
+
rescue Gem::MissingSpecError
|
39
|
+
warn("plugin prepare gem: #{name}, #{version} (#{$!})")
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def setup
|
45
|
+
return if disabled?
|
46
|
+
if path
|
47
|
+
minfra_path = Pathname.new(path).join("minfracs","init.rb")
|
48
|
+
if minfra_path.exist?
|
49
|
+
begin
|
50
|
+
require minfra_path # this should register the command
|
51
|
+
rescue LoadError
|
52
|
+
logger.warn("Minfra plugin detected but dependencies not installed: #{minfra_path} (try: minfra plugin install)")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
else
|
56
|
+
error("Gem based plugins not supported yet")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def install
|
61
|
+
return if disabled?
|
62
|
+
if path
|
63
|
+
system("cd #{path}; bundle install")
|
64
|
+
else
|
65
|
+
system("gem install #{name} --version #{version}")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def initialize(plugins)
|
71
|
+
@plugins=plugins
|
72
|
+
end
|
73
|
+
|
74
|
+
def prepare
|
75
|
+
@plugins.each(&:prepare)
|
76
|
+
end
|
77
|
+
def setup
|
78
|
+
@plugins.each(&:setup)
|
79
|
+
end
|
80
|
+
|
81
|
+
def install
|
82
|
+
if path
|
83
|
+
system("cd #{path}; bundle install")
|
84
|
+
else
|
85
|
+
system("gem install #{name} --version #{version}")
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
def each(&block)
|
90
|
+
@plugins.each(&block)
|
91
|
+
end
|
92
|
+
|
4
93
|
def self.load
|
94
|
+
found=[]
|
5
95
|
[Pathname.new(ENV["MINFRA_PATH"]).join("config","minfra_plugins.json"),
|
6
96
|
Pathname.new(ENV["MINFRA_PATH"]).join("me","minfra_plugins.json")].each do |file|
|
7
|
-
|
8
97
|
next unless File.exist?(file)
|
9
|
-
|
10
98
|
plugins=JSON.parse(File.read(file))
|
11
99
|
plugins["plugins"].each do |spec|
|
12
|
-
opts
|
13
|
-
|
14
|
-
if opts["path"]
|
15
|
-
begin
|
16
|
-
$LOAD_PATH.unshift opts["path"]+"/lib"
|
17
|
-
require spec["name"]
|
18
|
-
rescue Gem::Requirement::BadRequirementError
|
19
|
-
STDERR.puts("Can't load plugin: #{spec["name"]}")
|
20
|
-
end
|
21
|
-
else
|
22
|
-
begin
|
23
|
-
Gem::Specification.find_by_name(spec["name"])
|
24
|
-
gem spec["name"], spec["version"]
|
25
|
-
rescue Gem::MissingSpecError
|
26
|
-
STDERR.puts("Can't load plugin: #{spec["name"]}, #{spec["version"]}; run 'minfra plugin setup'")
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
100
|
+
found << Plugin.new(name: spec['name'], opts: spec['opts'] || {}, version: spec['version'], disabled: spec['disabled'])
|
101
|
+
end
|
30
102
|
end
|
103
|
+
new(found)
|
31
104
|
end
|
105
|
+
|
32
106
|
end
|
33
107
|
end
|
34
108
|
end
|
data/lib/minfra/cli/version.rb
CHANGED
data/lib/minfra/cli.rb
CHANGED
@@ -24,9 +24,13 @@ require "#{ENV['MINFRA_PATH']}/config/preload.rb" if File.exist?("#{ENV['MINFRA_
|
|
24
24
|
|
25
25
|
module Minfra
|
26
26
|
module Cli
|
27
|
-
extend Minfra::Cli::Logging
|
28
27
|
|
28
|
+
extend Minfra::Cli::Logging
|
29
29
|
|
30
|
+
def self.logger
|
31
|
+
@logger
|
32
|
+
end
|
33
|
+
|
30
34
|
def self.init(argv)
|
31
35
|
@argv = argv
|
32
36
|
# we'll set the context very early!
|
@@ -39,9 +43,15 @@ module Minfra
|
|
39
43
|
@config = Config.load('dev')
|
40
44
|
end
|
41
45
|
|
46
|
+
@logger=Logger.new(STDERR)
|
47
|
+
logger.level=ENV["MINFRA_LOGGING_LEVEL"] || @config.project.minfra.logging_level || 'warn'
|
48
|
+
@logger.debug("Minfra: loglevel: #{@logger.level}, env: #{@config.orch_env}")
|
49
|
+
|
42
50
|
hiera_init
|
43
51
|
|
44
|
-
Minfra::Cli::Plugins.load
|
52
|
+
@plugins = Minfra::Cli::Plugins.load
|
53
|
+
@plugins.prepare
|
54
|
+
|
45
55
|
Minfra::Cli.scan
|
46
56
|
require_relative 'cli/main_command'
|
47
57
|
Minfra::Cli.resolve
|
@@ -66,9 +76,9 @@ module Minfra
|
|
66
76
|
hiera = Hiera.new(:config => @hiera_root.join('hiera.yaml').to_s)
|
67
77
|
Hiera.logger=:noop
|
68
78
|
env= @config.orch_env
|
69
|
-
|
79
|
+
hiera_main_path=@hiera_root.join("hieradata/#{config.project.minfra.hiera.env_path}/#{env}.eyaml")
|
80
|
+
raise("unknown environment #{env}, I expact a file at #{hiera_main_path}") unless hiera_main_path.exist?
|
70
81
|
|
71
|
-
|
72
82
|
scope={ "hieraroot" => @hiera_root.to_s, "env" => env}
|
73
83
|
special_lookups=hiera.lookup("lookup_options", {}, scope, nil, :priority)
|
74
84
|
|
@@ -76,15 +86,23 @@ module Minfra
|
|
76
86
|
scope=scope.merge(node_scope)
|
77
87
|
cache={}
|
78
88
|
Kernel.define_method(:l) do |value,default=nil|
|
89
|
+
|
79
90
|
return cache[value] if cache.has_key?(value)
|
80
91
|
|
92
|
+
values=value.split(".")
|
93
|
+
value=values.shift
|
94
|
+
|
81
95
|
if special_lookups[value]
|
82
96
|
lookup_type={ merge_behavior: special_lookups[value]["merge"].to_sym }
|
83
97
|
else
|
84
|
-
lookup_type=:
|
98
|
+
lookup_type=:deep
|
85
99
|
end
|
86
100
|
|
87
101
|
result=hiera.lookup(value, default, scope, nil, lookup_type)
|
102
|
+
if !values.empty? && result.kind_of?(Hash) # we return nil or the scalar value and only drill down on hashes
|
103
|
+
result=result.dig(*values)
|
104
|
+
end
|
105
|
+
|
88
106
|
result=Hashie::Mash.new(result) if result.kind_of?(Hash)
|
89
107
|
cache[value] = result
|
90
108
|
result
|
@@ -100,17 +118,17 @@ module Minfra
|
|
100
118
|
def self.config
|
101
119
|
@config
|
102
120
|
end
|
121
|
+
|
103
122
|
def self.scan
|
123
|
+
#loading built in commands
|
104
124
|
root_path.join("lib/minfra/cli/commands").each_child do |command_path|
|
105
125
|
require command_path if command_path.to_s.match(/\.rb$/) && !command_path.to_s.match(/\#/)
|
106
126
|
end
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
end
|
113
|
-
end
|
127
|
+
@plugins.setup
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.plugins
|
131
|
+
@plugins
|
114
132
|
end
|
115
133
|
|
116
134
|
def self.register(subcommand,info,command)
|
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.
|
4
|
+
version: 1.4.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-
|
11
|
+
date: 2022-11-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -170,6 +170,7 @@ files:
|
|
170
170
|
- lib/minfra/cli/command.rb
|
171
171
|
- lib/minfra/cli/commands/dev.rb
|
172
172
|
- lib/minfra/cli/commands/kube.rb
|
173
|
+
- lib/minfra/cli/commands/plugin.rb
|
173
174
|
- lib/minfra/cli/commands/project.rb
|
174
175
|
- lib/minfra/cli/commands/project/branch.rb
|
175
176
|
- lib/minfra/cli/commands/project/tag.rb
|
@@ -233,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
234
|
- !ruby/object:Gem::Version
|
234
235
|
version: '0'
|
235
236
|
requirements: []
|
236
|
-
rubygems_version: 3.
|
237
|
+
rubygems_version: 3.1.6
|
237
238
|
signing_key:
|
238
239
|
specification_version: 4
|
239
240
|
summary: A cli framework for k8s based development and deployment.
|