kuby-core 0.11.1 → 0.11.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -0
- data/lib/kuby/basic_logger.rb +56 -8
- data/lib/kuby/cli_base.rb +51 -12
- data/lib/kuby/docker/cli.rb +10 -10
- data/lib/kuby/kubernetes/spec.rb +18 -3
- data/lib/kuby/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3a59a9d3e923807647da18d834d994cc7b2d149f4c82d6d9966d72748d7bcd5
|
4
|
+
data.tar.gz: 2bbd8e7d1c92ed3d0eb7d6d05420d7119d6f20a249f4401e52191868baeb0996
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8bf5fce8051029c8231e915035ec6c704ab361a6008b5335bf8a6747fb106ed55869164bb15eb704ecd72e6366ee320664d23d128a74726b6ca320edcb5c442
|
7
|
+
data.tar.gz: 679ad59207c201fb710e47e69c4682676a6fb12c826b59350a74d98c48f212d358c50fde0f8da0a5804391738d442a839cb4560d2cebd61ec7e7955677bd8e53
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,7 @@
|
|
1
|
+
## 0.11.2
|
2
|
+
* Attempt to auto-require the requested provider if it isn't registered.
|
3
|
+
* Adjust error message when provider can't be found to include reminder to add a require statement.
|
4
|
+
|
1
5
|
## 0.11.1
|
2
6
|
* Use integers for ports instead of strings to appease Kubernetes.
|
3
7
|
|
data/lib/kuby/basic_logger.rb
CHANGED
@@ -1,10 +1,30 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
|
+
|
2
3
|
require 'logger'
|
3
4
|
require 'colorized_string'
|
4
5
|
|
5
6
|
module Kuby
|
6
7
|
class BasicLogger < Logger
|
7
|
-
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig {
|
11
|
+
override.params(
|
12
|
+
logdev: T.any(String, IO, StringIO, NilClass),
|
13
|
+
shift_age: Integer,
|
14
|
+
shift_size: Integer,
|
15
|
+
level: Integer,
|
16
|
+
progname: T.nilable(String),
|
17
|
+
formatter: T.nilable(FormatterProcType),
|
18
|
+
datetime_format: T.nilable(String),
|
19
|
+
shift_period_suffix: T.nilable(String)
|
20
|
+
).void
|
21
|
+
}
|
22
|
+
def initialize(
|
23
|
+
logdev, shift_age = 0, shift_size = 1048576, level: DEBUG,
|
24
|
+
progname: nil, formatter: nil, datetime_format: nil,
|
25
|
+
shift_period_suffix: '%Y%m%d')
|
26
|
+
@logdev = T.let(@logdev, T.nilable(Logger::LogDevice))
|
27
|
+
|
8
28
|
super
|
9
29
|
|
10
30
|
self.formatter = proc do |_severity, _datetime, _progname, msg|
|
@@ -12,23 +32,51 @@ module Kuby
|
|
12
32
|
end
|
13
33
|
end
|
14
34
|
|
15
|
-
|
16
|
-
|
35
|
+
sig {
|
36
|
+
override.params(
|
37
|
+
progname_or_msg: T.untyped,
|
38
|
+
block: T.nilable(T.proc.returns(T.untyped))
|
39
|
+
).void
|
40
|
+
}
|
41
|
+
def info(progname_or_msg = nil, &block)
|
42
|
+
if block
|
43
|
+
super(progname_or_msg) { ColorizedString[block.call].yellow }
|
44
|
+
else
|
45
|
+
super(ColorizedString[progname_or_msg].yellow)
|
46
|
+
end
|
17
47
|
end
|
18
48
|
|
19
|
-
|
20
|
-
|
49
|
+
sig {
|
50
|
+
override.params(
|
51
|
+
progname_or_msg: T.untyped,
|
52
|
+
block: T.nilable(T.proc.returns(T.untyped))
|
53
|
+
).void
|
54
|
+
}
|
55
|
+
def fatal(progname_or_msg, &block)
|
56
|
+
if block
|
57
|
+
super(progname_or_msg) { ColorizedString[block.call].red }
|
58
|
+
else
|
59
|
+
super(ColorizedString[progname_or_msg].red)
|
60
|
+
end
|
21
61
|
end
|
22
62
|
|
23
63
|
# adhere to the "CLI" interface
|
24
|
-
|
25
|
-
|
64
|
+
sig {
|
65
|
+
params(
|
66
|
+
out: T.any(IO, StringIO),
|
67
|
+
err: T.any(IO, StringIO),
|
68
|
+
block: T.proc.void
|
69
|
+
).void
|
70
|
+
}
|
71
|
+
def with_pipes(out = STDOUT, err = STDERR, &block)
|
72
|
+
previous_logdev = @logdev&.dev || STDERR
|
26
73
|
reopen(err)
|
27
74
|
yield
|
28
75
|
ensure
|
29
76
|
reopen(previous_logdev)
|
30
77
|
end
|
31
78
|
|
79
|
+
sig { returns(T.nilable(Process::Status)) }
|
32
80
|
def last_status
|
33
81
|
nil
|
34
82
|
end
|
data/lib/kuby/cli_base.rb
CHANGED
@@ -1,24 +1,39 @@
|
|
1
|
-
# typed:
|
1
|
+
# typed: strict
|
2
|
+
|
2
3
|
require 'open3'
|
3
4
|
require 'thread'
|
4
5
|
|
5
6
|
module Kuby
|
6
7
|
class CLIBase
|
8
|
+
extend T::Sig
|
9
|
+
|
10
|
+
sig { returns(T.nilable(Process::Status)) }
|
7
11
|
def last_status
|
8
12
|
Thread.current[status_key]
|
9
13
|
end
|
10
14
|
|
15
|
+
sig { params(block: T.proc.params(cmd: String).void).void }
|
11
16
|
def before_execute(&block)
|
17
|
+
@before_execute = T.let(@before_execute, T.nilable(T::Array[T.proc.params(cmd: String).void]))
|
12
18
|
@before_execute ||= []
|
13
19
|
@before_execute << block
|
14
20
|
end
|
15
21
|
|
22
|
+
sig { params(block: T.proc.params(cmd: String).void).void }
|
16
23
|
def after_execute(&block)
|
24
|
+
@after_execute = T.let(@after_execute, T.nilable(T::Array[T.proc.params(cmd: String).void]))
|
17
25
|
@after_execute ||= []
|
18
26
|
@after_execute << block
|
19
27
|
end
|
20
28
|
|
21
|
-
|
29
|
+
sig {
|
30
|
+
params(
|
31
|
+
out: T.any(IO, StringIO),
|
32
|
+
err: T.any(IO, StringIO),
|
33
|
+
block: T.proc.void
|
34
|
+
).void
|
35
|
+
}
|
36
|
+
def with_pipes(out = STDOUT, err = STDERR, &block)
|
22
37
|
previous_stdout = self.stdout
|
23
38
|
previous_stderr = self.stderr
|
24
39
|
self.stdout = out
|
@@ -29,29 +44,39 @@ module Kuby
|
|
29
44
|
self.stderr = previous_stderr
|
30
45
|
end
|
31
46
|
|
47
|
+
sig { returns(T.nilable(T.any(IO, StringIO))) }
|
32
48
|
def stdout
|
33
49
|
Thread.current[stdout_key] || STDOUT
|
34
50
|
end
|
35
51
|
|
52
|
+
sig { params(new_stdout: T.nilable(T.any(IO, StringIO))).void }
|
36
53
|
def stdout=(new_stdout)
|
37
54
|
Thread.current[stdout_key] = new_stdout
|
38
55
|
end
|
39
56
|
|
57
|
+
sig { returns(T.nilable(T.any(IO, StringIO))) }
|
40
58
|
def stderr
|
41
59
|
Thread.current[stderr_key] || STDERR
|
42
60
|
end
|
43
61
|
|
62
|
+
sig { params(new_stderr: T.nilable(T.any(IO, StringIO))).void }
|
44
63
|
def stderr=(new_stderr)
|
45
64
|
Thread.current[stderr_key] = new_stderr
|
46
65
|
end
|
47
66
|
|
48
67
|
private
|
49
68
|
|
50
|
-
|
69
|
+
sig {
|
70
|
+
params(
|
71
|
+
cmd: T::Array[String],
|
72
|
+
block: T.proc.params(stdin: IO).void
|
73
|
+
).void
|
74
|
+
}
|
75
|
+
def open3_w(cmd, &block)
|
51
76
|
run_before_callbacks(cmd)
|
52
77
|
cmd_s = cmd.join(' ')
|
53
78
|
|
54
|
-
Open3.popen3(
|
79
|
+
Open3.popen3(cmd_s) do |p_stdin, p_stdout, p_stderr, wait_thread|
|
55
80
|
Thread.new(stdout) do |t_stdout|
|
56
81
|
begin
|
57
82
|
p_stdout.each { |line| t_stdout.puts(line) }
|
@@ -66,21 +91,23 @@ module Kuby
|
|
66
91
|
end
|
67
92
|
end
|
68
93
|
|
69
|
-
yield(p_stdin)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
94
|
+
yield(p_stdin)
|
95
|
+
|
96
|
+
p_stdin.close
|
97
|
+
self.last_status = T.cast(wait_thread.value, Process::Status)
|
98
|
+
run_after_callbacks(cmd)
|
99
|
+
wait_thread.join
|
75
100
|
end
|
76
101
|
end
|
77
102
|
|
103
|
+
sig { params(cmd: T::Array[String]).void }
|
78
104
|
def execc(cmd)
|
79
105
|
run_before_callbacks(cmd)
|
80
106
|
cmd_s = cmd.join(' ')
|
81
107
|
exec(cmd_s)
|
82
108
|
end
|
83
109
|
|
110
|
+
sig { params(cmd: T::Array[String]).void }
|
84
111
|
def systemm(cmd)
|
85
112
|
if stdout == STDOUT && stderr == STDERR
|
86
113
|
systemm_default(cmd)
|
@@ -89,6 +116,7 @@ module Kuby
|
|
89
116
|
end
|
90
117
|
end
|
91
118
|
|
119
|
+
sig { params(cmd: T::Array[String]).void }
|
92
120
|
def systemm_default(cmd)
|
93
121
|
run_before_callbacks(cmd)
|
94
122
|
cmd_s = cmd.join(' ')
|
@@ -98,6 +126,7 @@ module Kuby
|
|
98
126
|
end
|
99
127
|
end
|
100
128
|
|
129
|
+
sig { params(cmd: T::Array[String]).void }
|
101
130
|
def systemm_open3(cmd)
|
102
131
|
run_before_callbacks(cmd)
|
103
132
|
cmd_s = cmd.join(' ')
|
@@ -118,12 +147,14 @@ module Kuby
|
|
118
147
|
end
|
119
148
|
|
120
149
|
p_stdin.close
|
121
|
-
self.last_status = wait_thread.value
|
150
|
+
self.last_status = T.cast(wait_thread.value, Process::Status)
|
122
151
|
run_after_callbacks(cmd)
|
123
152
|
wait_thread.join
|
124
153
|
end
|
125
154
|
end
|
126
155
|
|
156
|
+
|
157
|
+
sig { params(cmd: T::Array[String]).returns(String) }
|
127
158
|
def backticks(cmd)
|
128
159
|
if stdout == STDOUT && stderr == STDERR
|
129
160
|
backticks_default(cmd)
|
@@ -132,6 +163,7 @@ module Kuby
|
|
132
163
|
end
|
133
164
|
end
|
134
165
|
|
166
|
+
sig { params(cmd: T::Array[String]).returns(String) }
|
135
167
|
def backticks_default(cmd)
|
136
168
|
run_before_callbacks(cmd)
|
137
169
|
cmd_s = cmd.join(' ')
|
@@ -141,6 +173,7 @@ module Kuby
|
|
141
173
|
end
|
142
174
|
end
|
143
175
|
|
176
|
+
sig { params(cmd: T::Array[String]).returns(String) }
|
144
177
|
def backticks_open3(cmd)
|
145
178
|
run_before_callbacks(cmd)
|
146
179
|
cmd_s = cmd.join(' ')
|
@@ -162,7 +195,7 @@ module Kuby
|
|
162
195
|
end
|
163
196
|
|
164
197
|
p_stdin.close
|
165
|
-
self.last_status = wait_thread.value
|
198
|
+
self.last_status = T.cast(wait_thread.value, Process::Status)
|
166
199
|
run_after_callbacks(cmd)
|
167
200
|
wait_thread.join
|
168
201
|
end
|
@@ -170,26 +203,32 @@ module Kuby
|
|
170
203
|
result.string
|
171
204
|
end
|
172
205
|
|
206
|
+
sig { params(cmd: T::Array[String]).void }
|
173
207
|
def run_before_callbacks(cmd)
|
174
208
|
(@before_execute || []).each { |cb| cb.call(cmd) }
|
175
209
|
end
|
176
210
|
|
211
|
+
sig { params(cmd: T::Array[String]).void }
|
177
212
|
def run_after_callbacks(cmd)
|
178
213
|
(@after_execute || []).each { |cb| cb.call(cmd, last_status) }
|
179
214
|
end
|
180
215
|
|
216
|
+
sig { params(status: Process::Status).void }
|
181
217
|
def last_status=(status)
|
182
218
|
Thread.current[status_key] = status
|
183
219
|
end
|
184
220
|
|
221
|
+
sig { returns(Symbol) }
|
185
222
|
def status_key
|
186
223
|
raise NotImplementedError, "#{__method__} must be defined in derived classes"
|
187
224
|
end
|
188
225
|
|
226
|
+
sig { returns(Symbol) }
|
189
227
|
def stdout_key
|
190
228
|
raise NotImplementedError, "#{__method__} must be defined in derived classes"
|
191
229
|
end
|
192
230
|
|
231
|
+
sig { returns(Symbol) }
|
193
232
|
def stderr_key
|
194
233
|
raise NotImplementedError, "#{__method__} must be defined in derived classes"
|
195
234
|
end
|
data/lib/kuby/docker/cli.rb
CHANGED
@@ -35,13 +35,13 @@ module Kuby
|
|
35
35
|
executable, 'login', url, '--username', username, '--password-stdin'
|
36
36
|
]
|
37
37
|
|
38
|
-
open3_w(
|
38
|
+
open3_w(cmd) do |stdin, _wait_threads|
|
39
39
|
stdin.puts(password)
|
40
40
|
end
|
41
41
|
|
42
|
-
unless last_status.success?
|
42
|
+
unless T.must(last_status).success?
|
43
43
|
raise LoginError, 'build failed: docker command exited with '\
|
44
|
-
"status code #{last_status.exitstatus}"
|
44
|
+
"status code #{T.must(last_status).exitstatus}"
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
@@ -72,13 +72,13 @@ module Kuby
|
|
72
72
|
'-f-', '.'
|
73
73
|
]
|
74
74
|
|
75
|
-
open3_w(
|
75
|
+
open3_w(cmd) do |stdin, _wait_threads|
|
76
76
|
stdin.puts(dockerfile.to_s)
|
77
77
|
end
|
78
78
|
|
79
|
-
unless last_status.success?
|
79
|
+
unless T.must(last_status).success?
|
80
80
|
raise BuildError, 'build failed: docker command exited with '\
|
81
|
-
"status code #{last_status.exitstatus}"
|
81
|
+
"status code #{T.must(last_status).exitstatus}"
|
82
82
|
end
|
83
83
|
end
|
84
84
|
|
@@ -124,9 +124,9 @@ module Kuby
|
|
124
124
|
executable, 'push', "#{image_url}:#{tag}"
|
125
125
|
])
|
126
126
|
|
127
|
-
unless last_status.success?
|
127
|
+
unless T.must(last_status).success?
|
128
128
|
raise PushError, 'push failed: docker command exited with '\
|
129
|
-
"status code #{last_status.exitstatus}"
|
129
|
+
"status code #{T.must(last_status).exitstatus}"
|
130
130
|
end
|
131
131
|
end
|
132
132
|
|
@@ -136,9 +136,9 @@ module Kuby
|
|
136
136
|
executable, 'pull', "#{image_url}:#{tag}"
|
137
137
|
])
|
138
138
|
|
139
|
-
unless last_status.success?
|
139
|
+
unless T.must(last_status).success?
|
140
140
|
raise PullError, 'pull failed: docker command exited with '\
|
141
|
-
"status code #{last_status.exitstatus}"
|
141
|
+
"status code #{T.must(last_status).exitstatus}"
|
142
142
|
end
|
143
143
|
end
|
144
144
|
|
data/lib/kuby/kubernetes/spec.rb
CHANGED
@@ -18,13 +18,28 @@ module Kuby
|
|
18
18
|
|
19
19
|
def provider(provider_name = nil, &block)
|
20
20
|
if provider_name
|
21
|
-
|
22
|
-
|
21
|
+
provider_klass = Kuby.providers[provider_name]
|
22
|
+
|
23
|
+
unless provider_klass
|
24
|
+
begin
|
25
|
+
# attempt to auto-require
|
26
|
+
require "kuby/#{provider_name}"
|
27
|
+
provider_klass = Kuby.providers[provider_name]
|
28
|
+
rescue LoadError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
if provider_klass
|
33
|
+
if !@provider || !@provider.is_a?(provider_klass)
|
34
|
+
@provider = provider_klass.new(environment)
|
35
|
+
end
|
36
|
+
|
23
37
|
@provider.configure(&block)
|
24
38
|
else
|
25
39
|
msg = if provider_name
|
26
40
|
"no provider registered with name #{provider_name}, "\
|
27
|
-
'do you need to add a gem to your Gemfile
|
41
|
+
'do you need to add a gem to your Gemfile and/or a '\
|
42
|
+
'require statement to your Kuby config?'
|
28
43
|
else
|
29
44
|
'no provider configured'
|
30
45
|
end
|
data/lib/kuby/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuby-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.11.
|
4
|
+
version: 0.11.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Cameron Dutro
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-10-
|
11
|
+
date: 2020-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: colorize
|