minfra-cli 1.3.0 → 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 +5 -0
- 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 +22 -11
- metadata +3 -2
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,3 +1,8 @@
|
|
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
|
1
6
|
# 1.3.0
|
2
7
|
* deep lookup value like "env.cluster.name"
|
3
8
|
# 1.2.2
|
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,7 +76,8 @@ 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
82
|
scope={ "hieraroot" => @hiera_root.to_s, "env" => env}
|
72
83
|
special_lookups=hiera.lookup("lookup_options", {}, scope, nil, :priority)
|
@@ -88,7 +99,7 @@ module Minfra
|
|
88
99
|
end
|
89
100
|
|
90
101
|
result=hiera.lookup(value, default, scope, nil, lookup_type)
|
91
|
-
|
102
|
+
if !values.empty? && result.kind_of?(Hash) # we return nil or the scalar value and only drill down on hashes
|
92
103
|
result=result.dig(*values)
|
93
104
|
end
|
94
105
|
|
@@ -107,17 +118,17 @@ module Minfra
|
|
107
118
|
def self.config
|
108
119
|
@config
|
109
120
|
end
|
121
|
+
|
110
122
|
def self.scan
|
123
|
+
#loading built in commands
|
111
124
|
root_path.join("lib/minfra/cli/commands").each_child do |command_path|
|
112
125
|
require command_path if command_path.to_s.match(/\.rb$/) && !command_path.to_s.match(/\#/)
|
113
126
|
end
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
end
|
127
|
+
@plugins.setup
|
128
|
+
end
|
129
|
+
|
130
|
+
def self.plugins
|
131
|
+
@plugins
|
121
132
|
end
|
122
133
|
|
123
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
|