kuber_kit 0.5.8 → 0.5.9
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/Gemfile.lock +1 -1
- data/example/app_data/service.yml +2 -1
- data/example/images/failing_app/Dockerfile +5 -0
- data/example/images/failing_app/image.rb +4 -0
- data/example/services/failing_app.rb +6 -0
- data/lib/kuber_kit.rb +6 -0
- data/lib/kuber_kit/actions/action_result.rb +32 -0
- data/lib/kuber_kit/actions/image_compiler.rb +18 -12
- data/lib/kuber_kit/actions/service_deployer.rb +16 -15
- data/lib/kuber_kit/cli.rb +17 -23
- data/lib/kuber_kit/service_deployer/strategies/docker.rb +6 -1
- data/lib/kuber_kit/version.rb +1 -1
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fa75f8b61926a3178d1592ceb81a35945a073b38d34c80c246872bae6b357d1f
|
4
|
+
data.tar.gz: fc41c9917961f9bff18ac03a60a16a77f094deae51abc6e28d80524fab793968
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb947b2cf303ef0f04a77364c0b6ea4043b2cf6f2b29cea0da1cd5d2808c7f2103799ad711e191e859bce59177372ac795460a1ed13589a6f62f536f4b23eb0
|
7
|
+
data.tar.gz: 324b1de9e8e762a5bce7bebf29ff9cc0317814f924be886fd10434f2ed2ffc8376025200f7ed2e35e2300bbbb2968061775c6e1f1c07f4a0ad2a61038225e66f
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/lib/kuber_kit.rb
CHANGED
@@ -170,6 +170,7 @@ module KuberKit
|
|
170
170
|
end
|
171
171
|
|
172
172
|
module Actions
|
173
|
+
autoload :ActionResult, 'actions/action_result'
|
173
174
|
autoload :ImageCompiler, 'actions/image_compiler'
|
174
175
|
autoload :EnvFileReader, 'actions/env_file_reader'
|
175
176
|
autoload :TemplateReader, 'actions/template_reader'
|
@@ -275,6 +276,11 @@ module KuberKit
|
|
275
276
|
KuberKit::Core::ContextHelper::BaseHelper.class_exec(&proc)
|
276
277
|
end
|
277
278
|
|
279
|
+
def set_user(value)
|
280
|
+
@user = value
|
281
|
+
@user_id = nil
|
282
|
+
end
|
283
|
+
|
278
284
|
def user
|
279
285
|
@user ||= ENV["KUBER_KIT_USERNAME"] || `whoami`.chomp
|
280
286
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class KuberKit::Actions::ActionResult
|
2
|
+
attr_reader :finished_tasks, :result, :error
|
3
|
+
|
4
|
+
def initialize()
|
5
|
+
@results = {}
|
6
|
+
@started_tasks = []
|
7
|
+
@finished_tasks = []
|
8
|
+
@mutex = Mutex.new
|
9
|
+
end
|
10
|
+
|
11
|
+
def start_task(task)
|
12
|
+
@mutex.synchronize do
|
13
|
+
@started_tasks.push(task)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def finish_task(task, result)
|
18
|
+
@mutex.synchronize do
|
19
|
+
@started_tasks.delete(task)
|
20
|
+
@finished_tasks.push(task)
|
21
|
+
@results[task] = result
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def failed!(error)
|
26
|
+
@error = error
|
27
|
+
end
|
28
|
+
|
29
|
+
def succeeded?
|
30
|
+
@error.nil? && @started_tasks.empty?
|
31
|
+
end
|
32
|
+
end
|
@@ -10,38 +10,40 @@ class KuberKit::Actions::ImageCompiler
|
|
10
10
|
|
11
11
|
Contract ArrayOf[Symbol], Hash => Any
|
12
12
|
def call(image_names, options)
|
13
|
+
compilation_result = KuberKit::Actions::ActionResult.new()
|
14
|
+
|
13
15
|
build_id = generate_build_id
|
14
16
|
build_server_pool = build_server_pool_factory.create()
|
15
17
|
|
16
|
-
compiled_images = []
|
17
|
-
compilation_result = {}
|
18
18
|
image_dependency_resolver.each_with_deps(image_names) do |dep_image_names|
|
19
19
|
ui.print_debug("ImageCompiler", "Scheduling to compile: #{dep_image_names.inspect}. Limit: #{configs.compile_simultaneous_limit}")
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
|
21
|
+
if compilation_result.succeeded?
|
22
|
+
compile_simultaneously(dep_image_names, build_id, build_server_pool, compilation_result)
|
23
|
+
end
|
23
24
|
end
|
24
25
|
|
25
26
|
build_server_pool.disconnect_all
|
26
27
|
|
27
|
-
|
28
|
+
compilation_result
|
28
29
|
rescue KuberKit::Error => e
|
29
30
|
ui.print_error("Error", e.message)
|
30
31
|
|
32
|
+
compilation_result.failed!(e.message)
|
33
|
+
|
31
34
|
false
|
32
35
|
end
|
33
36
|
|
34
37
|
private
|
35
|
-
def compile_simultaneously(image_names, build_id, build_server_pool)
|
38
|
+
def compile_simultaneously(image_names, build_id, build_server_pool, compilation_result)
|
36
39
|
task_group = ui.create_task_group
|
37
|
-
compiler_result = {}
|
38
40
|
image_names.map do |image_name|
|
39
41
|
|
40
42
|
ui.print_debug("ImageCompiler", "Started compiling: #{image_name.to_s.green}")
|
41
43
|
task_group.add("Compiling #{image_name.to_s.yellow}") do |task|
|
42
|
-
|
43
|
-
|
44
|
-
|
44
|
+
compilation_result.start_task(image_name)
|
45
|
+
image_result = compile_one(image_name, build_id, build_server_pool)
|
46
|
+
compilation_result.finish_task(image_name, image_result)
|
45
47
|
|
46
48
|
task.update_title("Compiled #{image_name.to_s.green}")
|
47
49
|
ui.print_debug("ImageCompiler", "Finished compiling: #{image_name}")
|
@@ -49,7 +51,11 @@ class KuberKit::Actions::ImageCompiler
|
|
49
51
|
|
50
52
|
end
|
51
53
|
task_group.wait
|
52
|
-
|
54
|
+
end
|
55
|
+
|
56
|
+
def compile_one(image_name, build_id, build_server_pool)
|
57
|
+
shell = build_server_pool.get_shell
|
58
|
+
image_compiler.call(shell, image_name, build_id)
|
53
59
|
end
|
54
60
|
|
55
61
|
def generate_build_id
|
@@ -19,6 +19,7 @@ class KuberKit::Actions::ServiceDeployer
|
|
19
19
|
require_confirmation: Maybe[Bool],
|
20
20
|
] => Any
|
21
21
|
def call(services:, tags:, skip_services: nil, skip_compile: false, require_confirmation: false)
|
22
|
+
deployment_result = KuberKit::Actions::ActionResult.new()
|
22
23
|
current_configuration = KuberKit.current_configuration
|
23
24
|
|
24
25
|
if services.empty? && tags.empty?
|
@@ -59,39 +60,41 @@ class KuberKit::Actions::ServiceDeployer
|
|
59
60
|
images_names = services.map(&:images).flatten.uniq
|
60
61
|
|
61
62
|
unless skip_compile
|
62
|
-
|
63
|
-
|
63
|
+
compilation_result = compile_images(images_names)
|
64
|
+
|
65
|
+
return false unless compilation_result && compilation_result.succeeded?
|
64
66
|
end
|
65
67
|
|
66
|
-
deployed_services = []
|
67
|
-
deployment_result = {}
|
68
68
|
service_dependency_resolver.each_with_deps(service_names) do |dep_service_names|
|
69
69
|
ui.print_debug("ServiceDeployer", "Scheduling to compile: #{dep_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
|
70
|
-
|
71
|
-
|
72
|
-
|
70
|
+
|
71
|
+
if deployment_result.succeeded?
|
72
|
+
deploy_simultaneously(dep_service_names, deployment_result)
|
73
|
+
end
|
73
74
|
end
|
74
75
|
|
75
|
-
|
76
|
+
deployment_result
|
76
77
|
rescue KuberKit::Error => e
|
77
78
|
ui.print_error("Error", e.message)
|
78
79
|
|
80
|
+
compilation_result.failed!(e.message)
|
81
|
+
|
79
82
|
false
|
80
83
|
rescue Interrupt => e
|
81
84
|
process_cleaner.clean
|
82
85
|
end
|
83
86
|
|
84
87
|
private
|
85
|
-
def deploy_simultaneously(service_names)
|
88
|
+
def deploy_simultaneously(service_names, deployment_result)
|
86
89
|
task_group = ui.create_task_group
|
87
90
|
|
88
|
-
deployer_result = {}
|
89
|
-
|
90
91
|
service_names.each do |service_name|
|
91
92
|
|
92
93
|
ui.print_debug("ServiceDeployer", "Started deploying: #{service_name.to_s.green}")
|
93
94
|
task_group.add("Deploying #{service_name.to_s.yellow}") do |task|
|
94
|
-
|
95
|
+
deployment_result.start_task(service_name)
|
96
|
+
service_result = service_deployer.call(local_shell, service_name.to_sym)
|
97
|
+
deployment_result.finish_task(service_name, service_result)
|
95
98
|
|
96
99
|
task.update_title("Deployed #{service_name.to_s.green}")
|
97
100
|
ui.print_debug("ServiceDeployer", "Finished deploying: #{service_name.to_s.green}")
|
@@ -99,12 +102,10 @@ class KuberKit::Actions::ServiceDeployer
|
|
99
102
|
end
|
100
103
|
|
101
104
|
task_group.wait
|
102
|
-
|
103
|
-
deployer_result
|
104
105
|
end
|
105
106
|
|
106
107
|
def compile_images(images_names)
|
107
|
-
return
|
108
|
+
return KuberKit::Actions::ActionResult.new if images_names.empty?
|
108
109
|
image_compiler.call(images_names, {})
|
109
110
|
end
|
110
111
|
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -10,6 +10,7 @@ class KuberKit::CLI < Thor
|
|
10
10
|
class_option :ui, :type => :string, :desc => "UI mode (interactive|debug|simple)"
|
11
11
|
class_option :debug, :type => :boolean, aliases: ["-d"]
|
12
12
|
class_option :configuration, :type => :string, aliases: ["-C"]
|
13
|
+
class_option :user, :type => :string, aliases: ["-u"]
|
13
14
|
|
14
15
|
desc "compile IMAGE_NAMES", "Compile image with IMAGE_NAMES (comma-separated)"
|
15
16
|
def compile(image_names_str)
|
@@ -19,12 +20,15 @@ class KuberKit::CLI < Thor
|
|
19
20
|
image_names = image_names_str.split(",").map(&:strip).map(&:to_sym)
|
20
21
|
|
21
22
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
22
|
-
|
23
|
+
action_result = KuberKit::Container['actions.image_compiler'].call(image_names, options)
|
23
24
|
end
|
24
25
|
|
25
|
-
if
|
26
|
+
if action_result && action_result.succeeded?
|
26
27
|
time = (Time.now.to_i - started_at)
|
27
|
-
print_result("Image compilation finished! (#{time}s)", result:
|
28
|
+
print_result("Image compilation finished! (#{time}s)", result: {
|
29
|
+
images: action_result.finished_tasks,
|
30
|
+
compilation: action_result.result
|
31
|
+
})
|
28
32
|
else
|
29
33
|
exit 1
|
30
34
|
end
|
@@ -44,7 +48,7 @@ class KuberKit::CLI < Thor
|
|
44
48
|
KuberKit.current_configuration.deployer_require_confirimation ||
|
45
49
|
false
|
46
50
|
started_at = Time.now.to_i
|
47
|
-
|
51
|
+
action_result = KuberKit::Container['actions.service_deployer'].call(
|
48
52
|
services: (options[:services] || []).flatten.uniq,
|
49
53
|
tags: (options[:tags] || []).flatten.uniq,
|
50
54
|
skip_services: (options[:skip_services] || []).flatten.uniq,
|
@@ -53,9 +57,12 @@ class KuberKit::CLI < Thor
|
|
53
57
|
)
|
54
58
|
end
|
55
59
|
|
56
|
-
if
|
60
|
+
if action_result && action_result.succeeded?
|
57
61
|
time = (Time.now.to_i - started_at)
|
58
|
-
print_result("Service deployment finished! (#{time}s)", result:
|
62
|
+
print_result("Service deployment finished! (#{time}s)", result: {
|
63
|
+
services: action_result.finished_tasks,
|
64
|
+
deployment: action_result.result
|
65
|
+
})
|
59
66
|
else
|
60
67
|
exit 1
|
61
68
|
end
|
@@ -178,6 +185,10 @@ class KuberKit::CLI < Thor
|
|
178
185
|
KuberKit.set_ui_mode(options[:ui].to_sym)
|
179
186
|
end
|
180
187
|
|
188
|
+
if options[:user]
|
189
|
+
KuberKit.set_user(options[:user])
|
190
|
+
end
|
191
|
+
|
181
192
|
# We should load config before loading any bean, to make sure that bean won't be built with default config
|
182
193
|
root_path = KuberKit::Container['tools.workdir_detector'].call(options)
|
183
194
|
config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
|
@@ -189,21 +200,4 @@ class KuberKit::CLI < Thor
|
|
189
200
|
def print_result(message, data = {})
|
190
201
|
KuberKit::Container['ui'].print_result(message, data)
|
191
202
|
end
|
192
|
-
|
193
|
-
def cleanup_processes
|
194
|
-
# Stop all threads
|
195
|
-
Thread.list.each do |t|
|
196
|
-
t.abort_on_exception = false
|
197
|
-
t.report_on_exception = false
|
198
|
-
Thread.kill(t) if t != Thread.current
|
199
|
-
end
|
200
|
-
|
201
|
-
# Find all system calls
|
202
|
-
child_pids_raw = `ps auxww | grep '[K]IT=#{Process.pid}' | awk '{print $2}'`
|
203
|
-
child_pids = child_pids_raw.to_s.split("\n").reject(&:empty?)
|
204
|
-
child_pids.each do |pid|
|
205
|
-
puts "Killing child process: #{pid}"
|
206
|
-
Process.kill("SIGHUP", pid.to_i)
|
207
|
-
end
|
208
|
-
end
|
209
203
|
end
|
@@ -20,7 +20,8 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
20
20
|
:networks,
|
21
21
|
:expose,
|
22
22
|
:publish,
|
23
|
-
:env_file_names
|
23
|
+
:env_file_names,
|
24
|
+
:env_vars
|
24
25
|
]
|
25
26
|
|
26
27
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
|
@@ -44,6 +45,7 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
44
45
|
|
45
46
|
env_file_names = strategy_options.fetch(:env_file_names, [])
|
46
47
|
env_files = prepare_env_files(shell, env_file_names)
|
48
|
+
env_vars = strategy_options.fetch(:env_vars, {})
|
47
49
|
|
48
50
|
image_name = strategy_options.fetch(:image_name, nil)
|
49
51
|
if image_name.nil?
|
@@ -84,6 +86,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
84
86
|
Array(env_files).each do |env_file|
|
85
87
|
custom_args << "--env-file #{env_file}"
|
86
88
|
end
|
89
|
+
env_vars.each do |key, value|
|
90
|
+
custom_args << "--env #{key}=#{value}"
|
91
|
+
end
|
87
92
|
|
88
93
|
docker_commands.run(
|
89
94
|
shell, image.remote_registry_url,
|
data/lib/kuber_kit/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kuber_kit
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -198,6 +198,8 @@ files:
|
|
198
198
|
- example/images/app_sources/Dockerfile
|
199
199
|
- example/images/app_sources/build_context/source.rb
|
200
200
|
- example/images/app_sources/image.rb
|
201
|
+
- example/images/failing_app/Dockerfile
|
202
|
+
- example/images/failing_app/image.rb
|
201
203
|
- example/images/ruby/Dockerfile
|
202
204
|
- example/images/ruby/image.rb
|
203
205
|
- example/images/ruby_app/Dockerfile
|
@@ -214,9 +216,11 @@ files:
|
|
214
216
|
- example/services/compose_app.rb
|
215
217
|
- example/services/docker_app.rb
|
216
218
|
- example/services/env_file.rb
|
219
|
+
- example/services/failing_app.rb
|
217
220
|
- example/services/ruby_app.rb
|
218
221
|
- kuber_kit.gemspec
|
219
222
|
- lib/kuber_kit.rb
|
223
|
+
- lib/kuber_kit/actions/action_result.rb
|
220
224
|
- lib/kuber_kit/actions/configuration_loader.rb
|
221
225
|
- lib/kuber_kit/actions/env_file_reader.rb
|
222
226
|
- lib/kuber_kit/actions/image_compiler.rb
|