kuber_kit 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -2
  3. data/README.md +16 -3
  4. data/TODO.md +5 -4
  5. data/example/app_data/env_file.yml +10 -0
  6. data/example/configurations/review.rb +2 -1
  7. data/example/images/app_sources/Dockerfile +1 -1
  8. data/example/images/ruby_app/image.rb +4 -4
  9. data/example/infrastructure/build_servers.rb +8 -0
  10. data/example/infrastructure/templates.rb +5 -0
  11. data/example/services/env_file.rb +6 -0
  12. data/kuber_kit.gemspec +1 -0
  13. data/lib/kuber_kit.rb +51 -23
  14. data/lib/kuber_kit/actions/configuration_loader.rb +11 -2
  15. data/lib/kuber_kit/actions/env_file_reader.rb +8 -5
  16. data/lib/kuber_kit/actions/image_compiler.rb +18 -22
  17. data/lib/kuber_kit/actions/kubectl_applier.rb +6 -1
  18. data/lib/kuber_kit/actions/kubectl_attacher.rb +19 -0
  19. data/lib/kuber_kit/actions/service_deployer.rb +13 -3
  20. data/lib/kuber_kit/actions/service_reader.rb +9 -6
  21. data/lib/kuber_kit/actions/template_reader.rb +5 -0
  22. data/lib/kuber_kit/cli.rb +51 -20
  23. data/lib/kuber_kit/configs.rb +24 -22
  24. data/lib/kuber_kit/container.rb +43 -19
  25. data/lib/kuber_kit/core/artifacts/artifact_store.rb +12 -23
  26. data/lib/kuber_kit/core/build_servers/abstract_build_server.rb +21 -0
  27. data/lib/kuber_kit/core/build_servers/build_server.rb +24 -0
  28. data/lib/kuber_kit/core/build_servers/build_server_store.rb +18 -0
  29. data/lib/kuber_kit/core/configuration.rb +14 -4
  30. data/lib/kuber_kit/core/configuration_definition.rb +22 -1
  31. data/lib/kuber_kit/core/configuration_factory.rb +11 -1
  32. data/lib/kuber_kit/core/configuration_store.rb +14 -24
  33. data/lib/kuber_kit/core/context_helper/base_helper.rb +12 -7
  34. data/lib/kuber_kit/core/context_helper/context_helper_factory.rb +11 -8
  35. data/lib/kuber_kit/core/context_helper/service_helper.rb +7 -6
  36. data/lib/kuber_kit/core/env_files/env_file_store.rb +8 -23
  37. data/lib/kuber_kit/core/image_store.rb +8 -18
  38. data/lib/kuber_kit/core/registries/registry_store.rb +8 -23
  39. data/lib/kuber_kit/core/service.rb +6 -2
  40. data/lib/kuber_kit/core/service_factory.rb +4 -1
  41. data/lib/kuber_kit/core/service_store.rb +13 -23
  42. data/lib/kuber_kit/core/store.rb +48 -0
  43. data/lib/kuber_kit/core/templates/template_store.rb +12 -23
  44. data/lib/kuber_kit/env_file_reader/action_handler.rb +12 -0
  45. data/lib/kuber_kit/env_file_reader/reader.rb +4 -4
  46. data/lib/kuber_kit/env_file_reader/{abstract_env_file_reader.rb → strategies/abstract.rb} +1 -1
  47. data/lib/kuber_kit/env_file_reader/{artifact_file_reader.rb → strategies/artifact_file.rb} +1 -1
  48. data/lib/kuber_kit/image_compiler/action_handler.rb +21 -0
  49. data/lib/kuber_kit/image_compiler/build_server_pool.rb +30 -0
  50. data/lib/kuber_kit/image_compiler/build_server_pool_factory.rb +13 -0
  51. data/lib/kuber_kit/image_compiler/compiler.rb +2 -5
  52. data/lib/kuber_kit/image_compiler/image_build_dir_creator.rb +13 -7
  53. data/lib/kuber_kit/image_compiler/image_dependency_resolver.rb +25 -5
  54. data/lib/kuber_kit/preprocessing/file_preprocessor.rb +5 -4
  55. data/lib/kuber_kit/preprocessing/text_preprocessor.rb +1 -1
  56. data/lib/kuber_kit/service_deployer/action_handler.rb +16 -0
  57. data/lib/kuber_kit/service_deployer/deployer.rb +28 -6
  58. data/lib/kuber_kit/service_deployer/strategies/abstract.rb +1 -1
  59. data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +9 -4
  60. data/lib/kuber_kit/service_deployer/strategy_detector.rb +6 -0
  61. data/lib/kuber_kit/service_reader/action_handler.rb +13 -0
  62. data/lib/kuber_kit/{service_deployer/service_reader.rb → service_reader/reader.rb} +1 -1
  63. data/lib/kuber_kit/shell/abstract_shell.rb +4 -0
  64. data/lib/kuber_kit/shell/{bash_commands.rb → commands/bash_commands.rb} +1 -1
  65. data/lib/kuber_kit/shell/{docker_commands.rb → commands/docker_commands.rb} +1 -1
  66. data/lib/kuber_kit/shell/{git_commands.rb → commands/git_commands.rb} +1 -1
  67. data/lib/kuber_kit/shell/{kubectl_commands.rb → commands/kubectl_commands.rb} +25 -1
  68. data/lib/kuber_kit/shell/commands/rsync_commands.rb +32 -0
  69. data/lib/kuber_kit/shell/local_shell.rb +24 -5
  70. data/lib/kuber_kit/shell/ssh_session.rb +60 -0
  71. data/lib/kuber_kit/shell/ssh_shell.rb +77 -0
  72. data/lib/kuber_kit/tools/file_presence_checker.rb +6 -2
  73. data/lib/kuber_kit/ui/interactive.rb +8 -0
  74. data/lib/kuber_kit/ui/simple.rb +6 -0
  75. data/lib/kuber_kit/version.rb +2 -2
  76. metadata +41 -13
  77. data/lib/kuber_kit/preprocessing/dir_preprocessor.rb +0 -19
  78. data/lib/kuber_kit/service_deployer/service_restarter.rb +0 -37
  79. data/lib/kuber_kit/shell/rsync_commands.rb +0 -20
  80. data/lib/kuber_kit/tools/files_sync.rb +0 -10
@@ -1,6 +1,10 @@
1
1
  class KuberKit::Tools::FilePresenceChecker
2
2
  FileNotFound = Class.new(KuberKit::Error)
3
3
 
4
+ include KuberKit::Import[
5
+ "shell.local_shell"
6
+ ]
7
+
4
8
  def check_file!(file_path)
5
9
  unless file_exists?(file_path)
6
10
  raise FileNotFound, "File not found at path: #{file_path}"
@@ -9,7 +13,7 @@ class KuberKit::Tools::FilePresenceChecker
9
13
  end
10
14
 
11
15
  def file_exists?(file_path)
12
- File.exists?(file_path)
16
+ local_shell.file_exists?(file_path)
13
17
  end
14
18
 
15
19
  def check_dir!(dir_path)
@@ -20,6 +24,6 @@ class KuberKit::Tools::FilePresenceChecker
20
24
  end
21
25
 
22
26
  def dir_exists?(dir_path)
23
- Dir.exists?(dir_path)
27
+ local_shell.dir_exists?(dir_path)
24
28
  end
25
29
  end
@@ -26,6 +26,14 @@ class KuberKit::UI::Interactive
26
26
  print_in_frame(title, text, color: :yellow)
27
27
  end
28
28
 
29
+ def prompt(text, options, &callback)
30
+ CLI::UI::Prompt.ask(text) do |handler|
31
+ options.each do |option|
32
+ handler.option(option, &callback)
33
+ end
34
+ end
35
+ end
36
+
29
37
  private
30
38
  def init
31
39
  @initialized = true
@@ -68,6 +68,12 @@ class KuberKit::UI::Simple
68
68
  print_text(title, text, color: String::Colors::YELLOW)
69
69
  end
70
70
 
71
+ def prompt(text, options, &callback)
72
+ print_info("Select", text)
73
+ result = $stdin.gets.chomp
74
+ callback.call(result)
75
+ end
76
+
71
77
  private
72
78
  def print_text(title, text, color:)
73
79
  puts "#{title.colorize(color)}\r\n #{text.colorize(color)}"
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.1.5"
3
- end
2
+ VERSION = "0.2.0"
3
+ end
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.1.5
4
+ version: 0.2.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: 2020-11-02 00:00:00.000000000 Z
11
+ date: 2020-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts-lite
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: net-ssh
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -144,6 +158,7 @@ files:
144
158
  - TODO.md
145
159
  - bin/console
146
160
  - bin/kit
161
+ - example/app_data/env_file.yml
147
162
  - example/app_data/service.yml
148
163
  - example/app_data/test.env
149
164
  - example/app_data/test.txt
@@ -160,9 +175,11 @@ files:
160
175
  - example/images/ruby_app2/build_context/example_file.txt
161
176
  - example/images/ruby_app2/image.rb
162
177
  - example/infrastructure/artifacts.rb
178
+ - example/infrastructure/build_servers.rb
163
179
  - example/infrastructure/env_files.rb
164
180
  - example/infrastructure/registries.rb
165
181
  - example/infrastructure/templates.rb
182
+ - example/services/env_file.rb
166
183
  - example/services/ruby_app.rb
167
184
  - kuber_kit.gemspec
168
185
  - lib/kuber_kit.rb
@@ -170,6 +187,7 @@ files:
170
187
  - lib/kuber_kit/actions/env_file_reader.rb
171
188
  - lib/kuber_kit/actions/image_compiler.rb
172
189
  - lib/kuber_kit/actions/kubectl_applier.rb
190
+ - lib/kuber_kit/actions/kubectl_attacher.rb
173
191
  - lib/kuber_kit/actions/service_deployer.rb
174
192
  - lib/kuber_kit/actions/service_reader.rb
175
193
  - lib/kuber_kit/actions/template_reader.rb
@@ -184,6 +202,9 @@ files:
184
202
  - lib/kuber_kit/core/artifacts/artifact_store.rb
185
203
  - lib/kuber_kit/core/artifacts/git.rb
186
204
  - lib/kuber_kit/core/artifacts/local.rb
205
+ - lib/kuber_kit/core/build_servers/abstract_build_server.rb
206
+ - lib/kuber_kit/core/build_servers/build_server.rb
207
+ - lib/kuber_kit/core/build_servers/build_server_store.rb
187
208
  - lib/kuber_kit/core/configuration.rb
188
209
  - lib/kuber_kit/core/configuration_definition.rb
189
210
  - lib/kuber_kit/core/configuration_definition_factory.rb
@@ -209,43 +230,50 @@ files:
209
230
  - lib/kuber_kit/core/service_definition_factory.rb
210
231
  - lib/kuber_kit/core/service_factory.rb
211
232
  - lib/kuber_kit/core/service_store.rb
233
+ - lib/kuber_kit/core/store.rb
212
234
  - lib/kuber_kit/core/templates/abstract_template.rb
213
235
  - lib/kuber_kit/core/templates/artifact_file.rb
214
236
  - lib/kuber_kit/core/templates/template_store.rb
215
- - lib/kuber_kit/env_file_reader/abstract_env_file_reader.rb
216
- - lib/kuber_kit/env_file_reader/artifact_file_reader.rb
237
+ - lib/kuber_kit/env_file_reader/action_handler.rb
217
238
  - lib/kuber_kit/env_file_reader/reader.rb
239
+ - lib/kuber_kit/env_file_reader/strategies/abstract.rb
240
+ - lib/kuber_kit/env_file_reader/strategies/artifact_file.rb
218
241
  - lib/kuber_kit/extensions/colored_string.rb
219
242
  - lib/kuber_kit/extensions/contracts.rb
220
243
  - lib/kuber_kit/extensions/indocker_compat.rb
221
244
  - lib/kuber_kit/extensions/inspectable.rb
245
+ - lib/kuber_kit/image_compiler/action_handler.rb
246
+ - lib/kuber_kit/image_compiler/build_server_pool.rb
247
+ - lib/kuber_kit/image_compiler/build_server_pool_factory.rb
222
248
  - lib/kuber_kit/image_compiler/compiler.rb
223
249
  - lib/kuber_kit/image_compiler/image_build_dir_creator.rb
224
250
  - lib/kuber_kit/image_compiler/image_builder.rb
225
251
  - lib/kuber_kit/image_compiler/image_dependency_resolver.rb
226
252
  - lib/kuber_kit/image_compiler/version_tag_builder.rb
227
- - lib/kuber_kit/preprocessing/dir_preprocessor.rb
228
253
  - lib/kuber_kit/preprocessing/file_preprocessor.rb
229
254
  - lib/kuber_kit/preprocessing/text_preprocessor.rb
255
+ - lib/kuber_kit/service_deployer/action_handler.rb
230
256
  - lib/kuber_kit/service_deployer/deployer.rb
231
257
  - lib/kuber_kit/service_deployer/service_list_resolver.rb
232
- - lib/kuber_kit/service_deployer/service_reader.rb
233
- - lib/kuber_kit/service_deployer/service_restarter.rb
234
258
  - lib/kuber_kit/service_deployer/strategies/abstract.rb
235
259
  - lib/kuber_kit/service_deployer/strategies/kubernetes.rb
260
+ - lib/kuber_kit/service_deployer/strategy_detector.rb
261
+ - lib/kuber_kit/service_reader/action_handler.rb
262
+ - lib/kuber_kit/service_reader/reader.rb
236
263
  - lib/kuber_kit/shell/abstract_shell.rb
237
- - lib/kuber_kit/shell/bash_commands.rb
238
264
  - lib/kuber_kit/shell/command_counter.rb
239
- - lib/kuber_kit/shell/docker_commands.rb
240
- - lib/kuber_kit/shell/git_commands.rb
241
- - lib/kuber_kit/shell/kubectl_commands.rb
265
+ - lib/kuber_kit/shell/commands/bash_commands.rb
266
+ - lib/kuber_kit/shell/commands/docker_commands.rb
267
+ - lib/kuber_kit/shell/commands/git_commands.rb
268
+ - lib/kuber_kit/shell/commands/kubectl_commands.rb
269
+ - lib/kuber_kit/shell/commands/rsync_commands.rb
242
270
  - lib/kuber_kit/shell/local_shell.rb
243
- - lib/kuber_kit/shell/rsync_commands.rb
271
+ - lib/kuber_kit/shell/ssh_session.rb
272
+ - lib/kuber_kit/shell/ssh_shell.rb
244
273
  - lib/kuber_kit/template_reader/abstract_template_reader.rb
245
274
  - lib/kuber_kit/template_reader/artifact_file_reader.rb
246
275
  - lib/kuber_kit/template_reader/reader.rb
247
276
  - lib/kuber_kit/tools/file_presence_checker.rb
248
- - lib/kuber_kit/tools/files_sync.rb
249
277
  - lib/kuber_kit/tools/logger_factory.rb
250
278
  - lib/kuber_kit/ui.rb
251
279
  - lib/kuber_kit/ui/interactive.rb
@@ -1,19 +0,0 @@
1
- class KuberKit::Preprocessing::DirPreprocessor
2
- include KuberKit::Import[
3
- "preprocessing.file_preprocessor",
4
- "shell.bash_commands"
5
- ]
6
-
7
- def compile(shell, source_dir, destination_dir, context_helper: nil)
8
- shell.recursive_list_files(source_dir).each do |source_file_path|
9
- relative_path = source_file_path.sub(source_dir, '')
10
- destination_file_path = File.join(destination_dir, relative_path)
11
-
12
- file_preprocessor.compile(
13
- shell, source_file_path,
14
- destination_path: destination_file_path,
15
- context_helper: context_helper
16
- )
17
- end
18
- end
19
- end
@@ -1,37 +0,0 @@
1
- class KuberKit::ServiceDeployer::ServiceRestarter
2
- StrategyNotFoundError = Class.new(KuberKit::NotFoundError)
3
-
4
- include KuberKit::Import[
5
- "core.service_store",
6
- "service_deployer.strategies.kubernetes"
7
- ]
8
-
9
- def register_strategy(strategy_name, strategy)
10
- @@strategies ||= {}
11
-
12
- if !strategy.is_a?(KuberKit::ServiceDeployer::Strategies::Abstract)
13
- raise ArgumentError.new("should be an instance of KuberKit::ServiceDeployer::Strategies::Abstract, got: #{strategy.inspect}")
14
- end
15
-
16
- @@strategies[strategy_name] = strategy
17
- end
18
-
19
- Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, Symbol => Any
20
- def restart(shell, service, strategy_name)
21
- add_default_strategies
22
-
23
- restarter = @@strategies[strategy_name]
24
-
25
- raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if restarter.nil?
26
-
27
- restarter.restart(shell, service)
28
- end
29
-
30
- def add_default_strategies
31
- register_strategy(:kubernetes, kubernetes)
32
- end
33
-
34
- def reset!
35
- @@strategies = {}
36
- end
37
- end
@@ -1,20 +0,0 @@
1
- class KuberKit::Shell::RsyncCommands
2
- def rsync(shell, source_path, target_path, exclude: nil)
3
- # Add a trailing slash to directory to have behavior similar to CP command
4
- if path_is_directory?(source_path) && !source_path.end_with?("/")
5
- source_path = "#{source_path}/"
6
- end
7
-
8
- args = [source_path, target_path]
9
- if exclude
10
- args << "--exclude=#{exclude}"
11
- end
12
-
13
- shell.exec!(%Q{rsync -a #{args.join(' ')}})
14
- end
15
-
16
- private
17
- def path_is_directory?(path)
18
- File.directory?(path)
19
- end
20
- end
@@ -1,10 +0,0 @@
1
- class KuberKit::Tools::FilesSync
2
- include KuberKit::Import[
3
- "shell.rsync_commands",
4
- "shell.local_shell"
5
- ]
6
-
7
- def sync(from_path, to_path, exclude: nil)
8
- rsync_commands.rsync(local_shell, from_path, to_path, exclude: exclude)
9
- end
10
- end