kuber_kit 0.5.10 → 0.6.0
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/Gemfile.lock +1 -1
- data/TODO.md +0 -2
- data/lib/kuber_kit.rb +2 -0
- data/lib/kuber_kit/actions/image_compiler.rb +1 -1
- data/lib/kuber_kit/actions/service_deployer.rb +23 -52
- data/lib/kuber_kit/container.rb +8 -0
- data/lib/kuber_kit/image_compiler/action_handler.rb +3 -0
- data/lib/kuber_kit/service_deployer/deployment_options_selector.rb +49 -0
- data/lib/kuber_kit/shell/local_shell.rb +12 -0
- data/lib/kuber_kit/tools/build_dir_cleaner.rb +26 -0
- data/lib/kuber_kit/tools/logger_factory.rb +6 -5
- data/lib/kuber_kit/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32c19efd73a0f79e6dd009a9e6700c184b78eacde4be6c7eb3e9571a6aa5977d
|
4
|
+
data.tar.gz: 6c66868a7a280ecaccc6dcb44ee75a929ecbb057545f412dab2f57e4e8c45bc9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8b1316dd6e65c9f81db7450c4e86c398357cd429054965ddff80634744f1ab5b1acedb638cd51c9c65040edd0c09c67429d5f884eef6c443ddb0e6bf558bd878
|
7
|
+
data.tar.gz: dac99cdc86d70f8f9424f6cb9aee0e7f5630e5407f878266c6373740015a5664c3ea6c27a29c9f39985b738bc7665281f9f9ced846436f251598da16bc6517f8
|
data/CHANGELOG.md
CHANGED
data/Gemfile.lock
CHANGED
data/TODO.md
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
- cleanup image builds older than some date
|
2
|
-
- add some rotation for deploy log
|
3
1
|
- env files should use a separate deployment method (with change detection)
|
4
2
|
- add automatical confirmation support for service deployer
|
5
3
|
- template should be able to set default attributes
|
data/lib/kuber_kit.rb
CHANGED
@@ -79,6 +79,7 @@ module KuberKit
|
|
79
79
|
end
|
80
80
|
|
81
81
|
module Tools
|
82
|
+
autoload :BuildDirCleaner, 'tools/build_dir_cleaner'
|
82
83
|
autoload :FilePresenceChecker, 'tools/file_presence_checker'
|
83
84
|
autoload :LoggerFactory, 'tools/logger_factory'
|
84
85
|
autoload :ProcessCleaner, 'tools/process_cleaner'
|
@@ -153,6 +154,7 @@ module KuberKit
|
|
153
154
|
autoload :ActionHandler, 'service_deployer/action_handler'
|
154
155
|
autoload :StrategyDetector, 'service_deployer/strategy_detector'
|
155
156
|
autoload :Deployer, 'service_deployer/deployer'
|
157
|
+
autoload :DeploymentOptionsSelector, 'service_deployer/deployment_options_selector'
|
156
158
|
autoload :ServiceListResolver, 'service_deployer/service_list_resolver'
|
157
159
|
autoload :ServiceDependencyResolver, 'service_deployer/service_dependency_resolver'
|
158
160
|
|
@@ -3,6 +3,7 @@ class KuberKit::Actions::ServiceDeployer
|
|
3
3
|
"actions.image_compiler",
|
4
4
|
"service_deployer.service_list_resolver",
|
5
5
|
"service_deployer.service_dependency_resolver",
|
6
|
+
"service_deployer.deployment_options_selector",
|
6
7
|
"core.service_store",
|
7
8
|
"shell.local_shell",
|
8
9
|
"tools.process_cleaner",
|
@@ -23,10 +24,9 @@ class KuberKit::Actions::ServiceDeployer
|
|
23
24
|
current_configuration = KuberKit.current_configuration
|
24
25
|
|
25
26
|
if services.empty? && tags.empty?
|
26
|
-
services, tags =
|
27
|
+
services, tags = deployment_options_selector.call()
|
27
28
|
end
|
28
29
|
|
29
|
-
|
30
30
|
disabled_services = current_configuration.disabled_services.map(&:to_s)
|
31
31
|
disabled_services += skip_services if skip_services
|
32
32
|
|
@@ -45,20 +45,12 @@ class KuberKit::Actions::ServiceDeployer
|
|
45
45
|
return false
|
46
46
|
end
|
47
47
|
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
if require_confirmation
|
52
|
-
result = ui.prompt("Please confirm to continue deployment", ["confirm".green, "cancel".red])
|
53
|
-
return false unless ["confirm".green, "confirm", "yes"].include?(result)
|
54
|
-
end
|
55
|
-
|
56
|
-
services = all_service_names.map do |service_name|
|
57
|
-
service_store.get_service(service_name.to_sym)
|
48
|
+
unless allow_deployment?(require_confirmation: require_confirmation, service_names: all_service_names)
|
49
|
+
return false
|
58
50
|
end
|
59
51
|
|
60
|
-
|
61
|
-
|
52
|
+
# Compile images for all services and dependencies
|
53
|
+
images_names = get_image_names(service_names: all_service_names)
|
62
54
|
unless skip_compile
|
63
55
|
compilation_result = compile_images(images_names)
|
64
56
|
|
@@ -77,11 +69,13 @@ class KuberKit::Actions::ServiceDeployer
|
|
77
69
|
rescue KuberKit::Error => e
|
78
70
|
ui.print_error("Error", e.message)
|
79
71
|
|
80
|
-
|
81
|
-
|
72
|
+
deployment_result.failed!(e.message)
|
73
|
+
|
82
74
|
false
|
83
75
|
rescue Interrupt => e
|
84
76
|
process_cleaner.clean
|
77
|
+
|
78
|
+
false
|
85
79
|
end
|
86
80
|
|
87
81
|
private
|
@@ -109,46 +103,23 @@ class KuberKit::Actions::ServiceDeployer
|
|
109
103
|
image_compiler.call(images_names, {})
|
110
104
|
end
|
111
105
|
|
112
|
-
def
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
tags = [specific_service_option, all_services_option]
|
117
|
-
tags += service_store
|
118
|
-
.all_definitions
|
119
|
-
.values
|
120
|
-
.map(&:to_service_attrs)
|
121
|
-
.map(&:tags)
|
122
|
-
.flatten
|
123
|
-
.uniq
|
124
|
-
.sort
|
125
|
-
.map(&:to_s)
|
126
|
-
|
127
|
-
selected_tag = ui.prompt("Please select which tag to deploy", tags)
|
128
|
-
|
129
|
-
if selected_tag == specific_service_option
|
130
|
-
show_service_selection
|
131
|
-
elsif selected_tag == all_services_option
|
132
|
-
[["*"], []]
|
133
|
-
else
|
134
|
-
[[], [selected_tag]]
|
106
|
+
def get_image_names(service_names:)
|
107
|
+
services = service_names.map do |service_name|
|
108
|
+
service_store.get_service(service_name.to_sym)
|
135
109
|
end
|
110
|
+
|
111
|
+
services.map(&:images).flatten.uniq
|
136
112
|
end
|
137
113
|
|
138
|
-
def
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
.sort
|
145
|
-
.map(&:to_s)
|
146
|
-
|
147
|
-
if services.empty?
|
148
|
-
return [[], []]
|
114
|
+
def allow_deployment?(require_confirmation:, service_names:)
|
115
|
+
services_list = service_names.map(&:to_s).map(&:yellow).join(", ")
|
116
|
+
ui.print_info "ServiceDeployer", "The following services will be deployed: #{services_list}"
|
117
|
+
|
118
|
+
unless require_confirmation
|
119
|
+
return true
|
149
120
|
end
|
150
121
|
|
151
|
-
|
152
|
-
[
|
122
|
+
result = ui.prompt("Please confirm to continue deployment", ["confirm".green, "cancel".red])
|
123
|
+
return ["confirm".green, "confirm", "yes"].include?(result)
|
153
124
|
end
|
154
125
|
end
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -121,6 +121,10 @@ class KuberKit::Container
|
|
121
121
|
KuberKit::Core::ContextHelper::ContextHelperFactory.new
|
122
122
|
end
|
123
123
|
|
124
|
+
register "tools.build_dir_cleaner" do
|
125
|
+
KuberKit::Tools::BuildDirCleaner.new
|
126
|
+
end
|
127
|
+
|
124
128
|
register "tools.file_presence_checker" do
|
125
129
|
KuberKit::Tools::FilePresenceChecker.new
|
126
130
|
end
|
@@ -273,6 +277,10 @@ class KuberKit::Container
|
|
273
277
|
KuberKit::ServiceDeployer::Deployer.new
|
274
278
|
end
|
275
279
|
|
280
|
+
register "service_deployer.deployment_options_selector" do
|
281
|
+
KuberKit::ServiceDeployer::DeploymentOptionsSelector.new
|
282
|
+
end
|
283
|
+
|
276
284
|
register "service_deployer.service_list_resolver" do
|
277
285
|
KuberKit::ServiceDeployer::ServiceListResolver.new
|
278
286
|
end
|
@@ -2,12 +2,15 @@ class KuberKit::ImageCompiler::ActionHandler
|
|
2
2
|
include KuberKit::Import[
|
3
3
|
"image_compiler.compiler",
|
4
4
|
"core.image_store",
|
5
|
+
"tools.build_dir_cleaner",
|
5
6
|
"configs",
|
6
7
|
]
|
7
8
|
|
8
9
|
Contract KuberKit::Shell::AbstractShell, Symbol, String => Any
|
9
10
|
def call(shell, image_name, build_id)
|
10
11
|
image = image_store.get_image(image_name)
|
12
|
+
|
13
|
+
build_dir_cleaner.call(parent_dir: configs.image_compile_dir)
|
11
14
|
|
12
15
|
compile_dir = generate_compile_dir(build_id: build_id)
|
13
16
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class KuberKit::ServiceDeployer::DeploymentOptionsSelector
|
2
|
+
include KuberKit::Import[
|
3
|
+
"core.service_store",
|
4
|
+
"ui"
|
5
|
+
]
|
6
|
+
|
7
|
+
OPTION_SPECIFIC_SERVICE = "deploy specific service".freeze
|
8
|
+
OPTION_ALL_SERVICES = "deploy all services"
|
9
|
+
|
10
|
+
def call()
|
11
|
+
tags = [OPTION_SPECIFIC_SERVICE, OPTION_ALL_SERVICES]
|
12
|
+
tags += service_store
|
13
|
+
.all_definitions
|
14
|
+
.values
|
15
|
+
.map(&:to_service_attrs)
|
16
|
+
.map(&:tags)
|
17
|
+
.flatten
|
18
|
+
.uniq
|
19
|
+
.sort
|
20
|
+
.map(&:to_s)
|
21
|
+
|
22
|
+
selected_tag = ui.prompt("Please select which tag to deploy", tags)
|
23
|
+
|
24
|
+
if selected_tag == OPTION_SPECIFIC_SERVICE
|
25
|
+
show_service_selection
|
26
|
+
elsif selected_tag == OPTION_ALL_SERVICES
|
27
|
+
[["*"], []]
|
28
|
+
else
|
29
|
+
[[], [selected_tag]]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def show_service_selection()
|
34
|
+
services = service_store
|
35
|
+
.all_definitions
|
36
|
+
.values
|
37
|
+
.map(&:service_name)
|
38
|
+
.uniq
|
39
|
+
.sort
|
40
|
+
.map(&:to_s)
|
41
|
+
|
42
|
+
if services.empty?
|
43
|
+
return [[], []]
|
44
|
+
end
|
45
|
+
|
46
|
+
selected_service = ui.prompt("Please select which service to deploy", services)
|
47
|
+
[[selected_service], []]
|
48
|
+
end
|
49
|
+
end
|
@@ -100,6 +100,18 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
100
100
|
end
|
101
101
|
end
|
102
102
|
|
103
|
+
def list_dirs(path)
|
104
|
+
command = %Q{find -L #{path} -type f}
|
105
|
+
command += " -name '#{name}'" if name
|
106
|
+
exec!(command).split(/[\r\n]+/)
|
107
|
+
rescue => e
|
108
|
+
if e.message.include?("No such file or directory")
|
109
|
+
raise DirNotFoundError.new("Dir not found: #{path}")
|
110
|
+
else
|
111
|
+
raise e
|
112
|
+
end
|
113
|
+
end
|
114
|
+
|
103
115
|
def wrap_command_with_pid(command)
|
104
116
|
"KIT=#{Process.pid} #{command}"
|
105
117
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
class KuberKit::Tools::BuildDirCleaner
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.bash_commands",
|
4
|
+
"shell.local_shell",
|
5
|
+
]
|
6
|
+
|
7
|
+
KEEP_DIRS_COUNT = 10
|
8
|
+
|
9
|
+
def call(parent_dir:)
|
10
|
+
dirs_to_delete = get_ancient_builds_dirs(parent_dir: parent_dir)
|
11
|
+
|
12
|
+
dirs_to_delete.each do |dir|
|
13
|
+
bash_commands.rm_rf(local_shell, dir)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
def get_ancient_builds_dirs(parent_dir:)
|
19
|
+
all_dirs = Dir.glob("#{parent_dir}/*")
|
20
|
+
skip_dirs = all_dirs
|
21
|
+
.sort_by{ |f| File.ctime(f) }
|
22
|
+
.reverse[0...KEEP_DIRS_COUNT]
|
23
|
+
|
24
|
+
all_dirs - skip_dirs
|
25
|
+
end
|
26
|
+
end
|
@@ -10,16 +10,17 @@ class KuberKit::Tools::LoggerFactory
|
|
10
10
|
Logger::FATAL => String::Colors::PURPLE,
|
11
11
|
}
|
12
12
|
|
13
|
+
MAX_LOGS_TO_KEEP = 3
|
14
|
+
MAX_LOG_FILE_SIZE = 512000
|
15
|
+
|
13
16
|
include KuberKit::Import[
|
14
17
|
"configs",
|
15
18
|
]
|
16
19
|
|
17
|
-
def create(
|
18
|
-
|
19
|
-
prepare_log_file(configs.log_file_path)
|
20
|
-
end
|
20
|
+
def create(level: nil)
|
21
|
+
prepare_log_file(configs.log_file_path)
|
21
22
|
|
22
|
-
logger = Logger.new(
|
23
|
+
logger = Logger.new(configs.log_file_path, MAX_LOGS_TO_KEEP, MAX_LOG_FILE_SIZE)
|
23
24
|
|
24
25
|
logger.level = level || Logger::DEBUG
|
25
26
|
|
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.
|
4
|
+
version: 0.6.0
|
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-
|
11
|
+
date: 2021-07-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -306,6 +306,7 @@ files:
|
|
306
306
|
- lib/kuber_kit/preprocessing/text_preprocessor.rb
|
307
307
|
- lib/kuber_kit/service_deployer/action_handler.rb
|
308
308
|
- lib/kuber_kit/service_deployer/deployer.rb
|
309
|
+
- lib/kuber_kit/service_deployer/deployment_options_selector.rb
|
309
310
|
- lib/kuber_kit/service_deployer/service_dependency_resolver.rb
|
310
311
|
- lib/kuber_kit/service_deployer/service_list_resolver.rb
|
311
312
|
- lib/kuber_kit/service_deployer/strategies/abstract.rb
|
@@ -331,6 +332,7 @@ files:
|
|
331
332
|
- lib/kuber_kit/template_reader/reader.rb
|
332
333
|
- lib/kuber_kit/template_reader/strategies/abstract.rb
|
333
334
|
- lib/kuber_kit/template_reader/strategies/artifact_file.rb
|
335
|
+
- lib/kuber_kit/tools/build_dir_cleaner.rb
|
334
336
|
- lib/kuber_kit/tools/file_presence_checker.rb
|
335
337
|
- lib/kuber_kit/tools/logger_factory.rb
|
336
338
|
- lib/kuber_kit/tools/process_cleaner.rb
|