kuber_kit 0.1.1 → 0.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/TODO.md +5 -1
  4. data/example/app_data/env_file.yml +10 -0
  5. data/example/app_data/service.yml +22 -4
  6. data/example/infrastructure/templates.rb +5 -0
  7. data/example/services/env_file.rb +3 -0
  8. data/example/services/ruby_app.rb +4 -0
  9. data/lib/kuber_kit.rb +21 -5
  10. data/lib/kuber_kit/actions/env_file_reader.rb +3 -5
  11. data/lib/kuber_kit/actions/image_compiler.rb +3 -13
  12. data/lib/kuber_kit/actions/kubectl_applier.rb +2 -2
  13. data/lib/kuber_kit/actions/service_deployer.rb +52 -0
  14. data/lib/kuber_kit/actions/service_reader.rb +3 -6
  15. data/lib/kuber_kit/cli.rb +1 -1
  16. data/lib/kuber_kit/configs.rb +3 -1
  17. data/lib/kuber_kit/container.rb +34 -6
  18. data/lib/kuber_kit/core/configuration.rb +17 -9
  19. data/lib/kuber_kit/core/configuration_definition.rb +26 -8
  20. data/lib/kuber_kit/core/configuration_factory.rb +10 -7
  21. data/lib/kuber_kit/core/configuration_store.rb +2 -0
  22. data/lib/kuber_kit/core/context_helper/base_helper.rb +14 -7
  23. data/lib/kuber_kit/core/context_helper/context_helper_factory.rb +11 -8
  24. data/lib/kuber_kit/core/context_helper/service_helper.rb +10 -6
  25. data/lib/kuber_kit/core/image_store.rb +2 -0
  26. data/lib/kuber_kit/core/service.rb +20 -2
  27. data/lib/kuber_kit/core/service_definition.rb +15 -1
  28. data/lib/kuber_kit/core/service_factory.rb +6 -1
  29. data/lib/kuber_kit/core/service_store.rb +2 -0
  30. data/lib/kuber_kit/env_file_reader/action_handler.rb +12 -0
  31. data/lib/kuber_kit/env_file_reader/reader.rb +4 -4
  32. data/lib/kuber_kit/env_file_reader/{abstract_env_file_reader.rb → strategies/abstract.rb} +1 -1
  33. data/lib/kuber_kit/env_file_reader/{artifact_file_reader.rb → strategies/artifact_file.rb} +1 -1
  34. data/lib/kuber_kit/image_compiler/action_handler.rb +20 -0
  35. data/lib/kuber_kit/image_compiler/compiler.rb +3 -6
  36. data/lib/kuber_kit/image_compiler/image_builder.rb +2 -3
  37. data/lib/kuber_kit/preprocessing/text_preprocessor.rb +1 -1
  38. data/lib/kuber_kit/service_deployer/action_handler.rb +16 -0
  39. data/lib/kuber_kit/service_deployer/deployer.rb +37 -0
  40. data/lib/kuber_kit/service_deployer/strategies/abstract.rb +5 -0
  41. data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +18 -0
  42. data/lib/kuber_kit/service_deployer/strategy_detector.rb +6 -0
  43. data/lib/kuber_kit/service_reader/action_handler.rb +13 -0
  44. data/lib/kuber_kit/{service_deployer/service_reader.rb → service_reader/reader.rb} +2 -1
  45. data/lib/kuber_kit/shell/kubectl_commands.rb +33 -3
  46. data/lib/kuber_kit/version.rb +1 -1
  47. metadata +17 -7
  48. data/example/services/auth_app.rb +0 -3
  49. data/lib/kuber_kit/actions/service_applier.rb +0 -39
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0635a0f1e358b5f29f44badbd6571e0a54c98f16072656c5edb8a19769c7bd92
4
- data.tar.gz: 3c81a6c67d14c5ca7852a856c10e3acb22b57cac835ad26a922c020609e57ea1
3
+ metadata.gz: c345ef3a461e5dc43ff910b8fb2cf4e1b4e306407d24d177ff2d8c0b1c894bcb
4
+ data.tar.gz: 597d9d093ce85c209562104e50763b3711558437baa410fc0d44e491d53f6f4c
5
5
  SHA512:
6
- metadata.gz: 0aa582e58931303efe8a60dfebaa4f1550d3e7f962ac6b1d758ff5398ffc2d61c31288699b931e0127720ff67d8e9de750ea005758282539fb6f37d15509abb6
7
- data.tar.gz: d676378c03ce31d7812edb3c760cbc5b99df7daf54de7109485691634dd173c55ced342c3c87a77ee6fc6e2b969b7d505b950b0fd62cb29dbe7d321d56867fef
6
+ metadata.gz: 240963d8b9452926d6d761b5f47c1464894c2fd115a75905f99b6ceed8ea2f835a97aaa34fa96ddf2dfd5ea22774f3cd5d5df474d7f4f7d99636feebd886c73f
7
+ data.tar.gz: ef2018ef89bad80de6a11bf6d1682ed8f72d24e261a10cd79f018aea5c66930613a9373b2405757070d78017273c302c6a2cdc2f64b05790f032b58a69000a29
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.1.1)
4
+ kuber_kit (0.1.6)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- cli-ui (1.3.0)
13
+ cli-ui (1.4.0)
14
14
  coderay (1.1.3)
15
15
  concurrent-ruby (1.1.7)
16
16
  contracts-lite (0.15.0)
data/TODO.md CHANGED
@@ -1,2 +1,6 @@
1
+ - limit amount of simultaneous image builds
2
+ - list services and require confirmation before deployment
3
+ - service factory should make sure that template exists
1
4
  - add build servers support
2
- - add build vars support (use images instead of containers)
5
+ - add build vars support (use images instead of containers)
6
+ - template should be able to depend on image?
@@ -0,0 +1,10 @@
1
+ ---
2
+ apiVersion: v1
3
+ kind: Secret
4
+ metadata:
5
+ name: env-secret-review
6
+ type: Opaque
7
+ stringData:
8
+ <% env_file(:test).each do |key, value| -%>
9
+ <%= key %>: "<%= value %>"
10
+ <% end -%>
@@ -1,7 +1,25 @@
1
- apiVersion: v1
2
- kind: Service
1
+
2
+ apiVersion: apps/v1
3
+ kind: Deployment
3
4
  metadata:
4
- name: "<%= service_uri %>"
5
+ labels:
6
+ app: <%= service_uri %>
7
+ name: <%= service_uri %>
5
8
  spec:
9
+ replicas: 1
6
10
  selector:
7
- app: test-app
11
+ matchLabels:
12
+ app: <%= service_uri %>
13
+ strategy: {}
14
+ template:
15
+ metadata:
16
+ labels:
17
+ app: <%= service_uri %>
18
+ spec:
19
+ containers:
20
+ - name: <%= service_uri %>
21
+ image: <%= service_name %>:latest
22
+ imagePullPolicy: Always
23
+ restartPolicy: Always
24
+ imagePullSecrets:
25
+ - name: regcred
@@ -1,4 +1,9 @@
1
1
  KuberKit.add_template(
2
2
  KuberKit::Core::Templates::ArtifactFile
3
3
  .new(:service, artifact_name: :kuber_kit_example_data, file_path: "service.yml")
4
+ )
5
+
6
+ KuberKit.add_template(
7
+ KuberKit::Core::Templates::ArtifactFile
8
+ .new(:env_file, artifact_name: :kuber_kit_example_data, file_path: "env_file.yml")
4
9
  )
@@ -0,0 +1,3 @@
1
+ KuberKit
2
+ .define_service(:env_file)
3
+ .template(:env_file)
@@ -0,0 +1,4 @@
1
+ KuberKit
2
+ .define_service(:ruby_app)
3
+ .template(:service)
4
+ .images(:ruby_app)
@@ -82,6 +82,7 @@ module KuberKit
82
82
  end
83
83
 
84
84
  module ImageCompiler
85
+ autoload :ActionHandler, 'image_compiler/action_handler'
85
86
  autoload :Compiler, 'image_compiler/compiler'
86
87
  autoload :ImageBuilder, 'image_compiler/image_builder'
87
88
  autoload :ImageBuildDirCreator, 'image_compiler/image_build_dir_creator'
@@ -103,9 +104,13 @@ module KuberKit
103
104
  end
104
105
 
105
106
  module EnvFileReader
107
+ autoload :ActionHandler, 'env_file_reader/action_handler'
106
108
  autoload :Reader, 'env_file_reader/reader'
107
- autoload :AbstractEnvFileReader, 'env_file_reader/abstract_env_file_reader'
108
- autoload :ArtifactFileReader, 'env_file_reader/artifact_file_reader'
109
+
110
+ module Strategies
111
+ autoload :Abstract, 'env_file_reader/strategies/abstract'
112
+ autoload :ArtifactFile, 'env_file_reader/strategies/artifact_file'
113
+ end
109
114
  end
110
115
 
111
116
  module TemplateReader
@@ -115,9 +120,20 @@ module KuberKit
115
120
  end
116
121
 
117
122
  module ServiceDeployer
118
- autoload :ServiceReader, 'service_deployer/service_reader'
119
- autoload :ServiceApplier, 'service_deployer/service_applier'
123
+ autoload :ActionHandler, 'service_deployer/action_handler'
124
+ autoload :StrategyDetector, 'service_deployer/strategy_detector'
125
+ autoload :Deployer, 'service_deployer/deployer'
120
126
  autoload :ServiceListResolver, 'service_deployer/service_list_resolver'
127
+
128
+ module Strategies
129
+ autoload :Abstract, 'service_deployer/strategies/abstract'
130
+ autoload :Kubernetes, 'service_deployer/strategies/kubernetes'
131
+ end
132
+ end
133
+
134
+ module ServiceReader
135
+ autoload :ActionHandler, 'service_reader/action_handler'
136
+ autoload :Reader, 'service_reader/reader'
121
137
  end
122
138
 
123
139
  module Actions
@@ -125,7 +141,7 @@ module KuberKit
125
141
  autoload :EnvFileReader, 'actions/env_file_reader'
126
142
  autoload :TemplateReader, 'actions/template_reader'
127
143
  autoload :ServiceReader, 'actions/service_reader'
128
- autoload :ServiceApplier, 'actions/service_applier'
144
+ autoload :ServiceDeployer, 'actions/service_deployer'
129
145
  autoload :ConfigurationLoader, 'actions/configuration_loader'
130
146
  autoload :KubectlApplier, 'actions/kubectl_applier'
131
147
  end
@@ -2,16 +2,14 @@ require 'json'
2
2
 
3
3
  class KuberKit::Actions::EnvFileReader
4
4
  include KuberKit::Import[
5
- "core.env_file_store",
6
- "env_file_reader.reader",
7
5
  "shell.local_shell",
8
- "ui"
6
+ "ui",
7
+ env_file_reader: "env_file_reader.action_handler",
9
8
  ]
10
9
 
11
10
  Contract Symbol, Hash => Any
12
11
  def call(env_file_name, options)
13
- env_file = env_file_store.get(env_file_name)
14
- result = reader.read(local_shell, env_file)
12
+ result = env_file_reader.call(local_shell, env_file_name)
15
13
  ui.print_info(env_file_name.to_s, JSON.pretty_generate(result))
16
14
  end
17
15
  end
@@ -1,11 +1,10 @@
1
1
  class KuberKit::Actions::ImageCompiler
2
2
  include KuberKit::Import[
3
- "image_compiler.compiler",
4
3
  "image_compiler.image_dependency_resolver",
5
4
  "shell.local_shell",
6
5
  "tools.logger",
7
- "configs",
8
- "ui"
6
+ "ui",
7
+ image_compiler: "image_compiler.action_handler",
9
8
  ]
10
9
 
11
10
  Contract ArrayOf[Symbol], Hash => Any
@@ -31,7 +30,7 @@ class KuberKit::Actions::ImageCompiler
31
30
 
32
31
  logger.info("Started compiling: #{image_name.to_s.green}")
33
32
  task_group.add("Compiling #{image_name.to_s.yellow}") do |task|
34
- compile_image(image_name, build_id)
33
+ image_compiler.call(local_shell, image_name, build_id)
35
34
 
36
35
  task.update_title("Compiled #{image_name.to_s.green}")
37
36
  logger.info("Finished compiling: #{image_name.to_s.green}")
@@ -41,16 +40,7 @@ class KuberKit::Actions::ImageCompiler
41
40
  task_group.wait
42
41
  end
43
42
 
44
- def compile_image(image_name, build_id)
45
- compile_dir = generate_compile_dir(build_id: build_id)
46
- image_compiler.compile(local_shell, image_name, compile_dir)
47
- end
48
-
49
43
  def generate_build_id
50
44
  Time.now.strftime("%H%M%S")
51
45
  end
52
-
53
- def generate_compile_dir(build_id:)
54
- File.join(configs.image_compile_dir, build_id)
55
- end
56
46
  end
@@ -7,9 +7,9 @@ class KuberKit::Actions::KubectlApplier
7
7
 
8
8
  Contract String, Hash => Any
9
9
  def call(file_path, options)
10
- kubecfg_path = KuberKit.current_configuration.kubecfg_path
10
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
11
11
  ui.create_task("Applying file: #{file_path}") do |task|
12
- kubectl_commands.apply_file(local_shell, file_path, kubecfg_path: kubecfg_path)
12
+ kubectl_commands.apply_file(local_shell, file_path, kubeconfig_path: kubeconfig_path)
13
13
  task.update_title("Applied file: #{file_path}")
14
14
  end
15
15
  nil
@@ -0,0 +1,52 @@
1
+ class KuberKit::Actions::ServiceDeployer
2
+ include KuberKit::Import[
3
+ "actions.image_compiler",
4
+ "service_deployer.service_list_resolver",
5
+ "core.service_store",
6
+ "shell.local_shell",
7
+ "tools.logger",
8
+ "ui",
9
+ service_deployer: "service_deployer.action_handler",
10
+ ]
11
+
12
+ Contract KeywordArgs[
13
+ services: Maybe[ArrayOf[String]],
14
+ tags: Maybe[ArrayOf[String]],
15
+ ] => Any
16
+ def call(services:, tags:)
17
+ service_names = service_list_resolver.resolve(
18
+ services: services || [],
19
+ tags: tags || []
20
+ )
21
+
22
+ services = service_names.map do |service_name|
23
+ service_store.get_service(service_name.to_sym)
24
+ end
25
+
26
+ images_names = services.map(&:images).flatten.uniq
27
+
28
+ compile_images(images_names)
29
+ deploy_services(service_names)
30
+ end
31
+
32
+ def deploy_services(service_names)
33
+ task_group = ui.create_task_group
34
+
35
+ service_names.each do |service_name|
36
+
37
+ logger.info("Started deploying: #{service_name.to_s.green}")
38
+ task_group.add("Deploying #{service_name.to_s.yellow}") do |task|
39
+ service_deployer.call(local_shell, service_name.to_sym)
40
+
41
+ task.update_title("Deployed #{service_name.to_s.green}")
42
+ logger.info("Finished deploying: #{service_name.to_s.green}")
43
+ end
44
+ end
45
+
46
+ task_group.wait
47
+ end
48
+
49
+ def compile_images(images_names)
50
+ image_compiler.call(images_names, {}) if images_names.any?
51
+ end
52
+ end
@@ -1,16 +1,13 @@
1
1
  class KuberKit::Actions::ServiceReader
2
2
  include KuberKit::Import[
3
- "core.service_store",
4
- "service_deployer.service_reader",
5
3
  "shell.local_shell",
6
- "ui"
4
+ "ui",
5
+ service_reader: "service_reader.action_handler",
7
6
  ]
8
7
 
9
8
  Contract Symbol, Hash => Any
10
9
  def call(service_name, options)
11
- service = service_store.get_service(service_name)
12
-
13
- result = service_reader.read(local_shell, service)
10
+ result = service_reader.call(local_shell, service_name)
14
11
 
15
12
  ui.print_info(service_name.to_s, result)
16
13
  end
@@ -63,7 +63,7 @@ class KuberKit::CLI < Thor
63
63
 
64
64
  KuberKit::Container['actions.configuration_loader'].call(options)
65
65
 
66
- KuberKit::Container['actions.service_applier'].call(services: options[:services], tags: options[:tags])
66
+ KuberKit::Container['actions.service_deployer'].call(services: options[:services], tags: options[:tags])
67
67
  end
68
68
 
69
69
  def self.exit_on_failure?
@@ -21,11 +21,12 @@ class KuberKit::Configs
21
21
  CONFIGURATIONS_DIRNAME = "configurations".freeze
22
22
  ARTIFACT_CLONE_DIR = "/tmp/kuber_kit/artifacts"
23
23
  SERVICE_CONFIG_DIR = "/tmp/kuber_kit/services"
24
+ DEPLOY_STRATEGY = :kubernetes
24
25
 
25
26
  attr_accessor :image_dockerfile_name, :image_build_context_dir, :image_tag,
26
27
  :docker_ignore_list, :image_compile_dir,
27
28
  :kuber_kit_dirname, :images_dirname, :services_dirname, :infra_dirname, :configurations_dirname,
28
- :artifact_clone_dir, :service_config_dir
29
+ :artifact_clone_dir, :service_config_dir, :deploy_strategy
29
30
 
30
31
  def initialize
31
32
  @image_dockerfile_name = IMAGE_DOCKERFILE_NAME
@@ -40,5 +41,6 @@ class KuberKit::Configs
40
41
  @configurations_dirname = CONFIGURATIONS_DIRNAME
41
42
  @artifact_clone_dir = ARTIFACT_CLONE_DIR
42
43
  @service_config_dir = SERVICE_CONFIG_DIR
44
+ @deploy_strategy = DEPLOY_STRATEGY
43
45
  end
44
46
  end
@@ -17,8 +17,8 @@ class KuberKit::Container
17
17
  KuberKit::Actions::ServiceReader.new
18
18
  end
19
19
 
20
- register "actions.service_applier" do
21
- KuberKit::Actions::ServiceApplier.new
20
+ register "actions.service_deployer" do
21
+ KuberKit::Actions::ServiceDeployer.new
22
22
  end
23
23
 
24
24
  register "actions.configuration_loader" do
@@ -141,6 +141,10 @@ class KuberKit::Container
141
141
  KuberKit::Preprocessing::DirPreprocessor.new
142
142
  end
143
143
 
144
+ register "image_compiler.action_handler" do
145
+ KuberKit::ImageCompiler::ActionHandler.new
146
+ end
147
+
144
148
  register "image_compiler.compiler" do
145
149
  KuberKit::ImageCompiler::Compiler.new
146
150
  end
@@ -173,12 +177,16 @@ class KuberKit::Container
173
177
  KuberKit::ArtifactsSync::NullArtifactResolver.new
174
178
  end
175
179
 
180
+ register "env_file_reader.action_handler" do
181
+ KuberKit::EnvFileReader::ActionHandler.new
182
+ end
183
+
176
184
  register "env_file_reader.reader" do
177
185
  KuberKit::EnvFileReader::Reader.new
178
186
  end
179
187
 
180
- register "env_file_reader.artifact_file_reader" do
181
- KuberKit::EnvFileReader::ArtifactFileReader.new
188
+ register "env_file_reader.strategies.artifact_file" do
189
+ KuberKit::EnvFileReader::Strategies::ArtifactFile.new
182
190
  end
183
191
 
184
192
  register "template_reader.reader" do
@@ -189,14 +197,34 @@ class KuberKit::Container
189
197
  KuberKit::TemplateReader::ArtifactFileReader.new
190
198
  end
191
199
 
192
- register "service_deployer.service_reader" do
193
- KuberKit::ServiceDeployer::ServiceReader.new
200
+ register "service_deployer.action_handler" do
201
+ KuberKit::ServiceDeployer::ActionHandler.new
202
+ end
203
+
204
+ register "service_deployer.strategy_detector" do
205
+ KuberKit::ServiceDeployer::StrategyDetector.new
206
+ end
207
+
208
+ register "service_deployer.deployer" do
209
+ KuberKit::ServiceDeployer::Deployer.new
194
210
  end
195
211
 
196
212
  register "service_deployer.service_list_resolver" do
197
213
  KuberKit::ServiceDeployer::ServiceListResolver.new
198
214
  end
199
215
 
216
+ register "service_deployer.strategies.kubernetes" do
217
+ KuberKit::ServiceDeployer::Strategies::Kubernetes.new
218
+ end
219
+
220
+ register "service_reader.action_handler" do
221
+ KuberKit::ServiceReader::ActionHandler.new
222
+ end
223
+
224
+ register "service_reader.reader" do
225
+ KuberKit::ServiceReader::Reader.new
226
+ end
227
+
200
228
  register "ui" do
201
229
  if KuberKit.debug_mode?
202
230
  KuberKit::UI::Simple.new
@@ -1,5 +1,5 @@
1
1
  class KuberKit::Core::Configuration
2
- attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubecfg_path
2
+ attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path, :deploy_strategy, :services_attributes
3
3
 
4
4
  Contract KeywordArgs[
5
5
  name: Symbol,
@@ -7,14 +7,22 @@ class KuberKit::Core::Configuration
7
7
  registries: Hash,
8
8
  env_files: Hash,
9
9
  templates: Hash,
10
- kubecfg_path: Maybe[String]
10
+ kubeconfig_path: Maybe[String],
11
+ deploy_strategy: Symbol,
12
+ services_attributes: HashOf[Symbol => Hash]
11
13
  ] => Any
12
- def initialize(name:, artifacts:, registries:, env_files:, templates:, kubecfg_path:)
13
- @name = name
14
- @artifacts = artifacts
15
- @registries = registries
16
- @env_files = env_files
17
- @templates = templates
18
- @kubecfg_path = kubecfg_path
14
+ def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, deploy_strategy:, services_attributes:)
15
+ @name = name
16
+ @artifacts = artifacts
17
+ @registries = registries
18
+ @env_files = env_files
19
+ @templates = templates
20
+ @kubeconfig_path = kubeconfig_path
21
+ @deploy_strategy = deploy_strategy
22
+ @services_attributes = services_attributes
23
+ end
24
+
25
+ def service_attributes(service_name)
26
+ services_attributes[service_name.to_sym] || {}
19
27
  end
20
28
  end
@@ -10,16 +10,21 @@ class KuberKit::Core::ConfigurationDefinition
10
10
  @registries = {}
11
11
  @env_files = {}
12
12
  @templates = {}
13
+ @enabled_services = []
14
+ @services_attributes = {}
13
15
  end
14
16
 
15
17
  def to_attrs
16
18
  OpenStruct.new(
17
- name: @configuration_name,
18
- artifacts: @artifacts,
19
- registries: @registries,
20
- env_files: @env_files,
21
- templates: @templates,
22
- kubecfg_path: @kubecfg_path
19
+ name: @configuration_name,
20
+ artifacts: @artifacts,
21
+ registries: @registries,
22
+ env_files: @env_files,
23
+ templates: @templates,
24
+ kubeconfig_path: @kubeconfig_path,
25
+ deploy_strategy: @deploy_strategy,
26
+ enabled_services: @enabled_services,
27
+ services_attributes: @services_attributes
23
28
  )
24
29
  end
25
30
 
@@ -59,8 +64,21 @@ class KuberKit::Core::ConfigurationDefinition
59
64
  self
60
65
  end
61
66
 
62
- def kubecfg_path(path)
63
- @kubecfg_path = path
67
+ def kubeconfig_path(path)
68
+ @kubeconfig_path = path
69
+
70
+ self
71
+ end
72
+
73
+ def deploy_strategy(path)
74
+ @deploy_strategy = path
75
+
76
+ self
77
+ end
78
+
79
+ def enabled_services(services_hash)
80
+ @enabled_services += services_hash.keys.map(&:to_sym)
81
+ @services_attributes = @services_attributes.merge(services_hash)
64
82
 
65
83
  self
66
84
  end
@@ -5,7 +5,8 @@ class KuberKit::Core::ConfigurationFactory
5
5
  "core.registry_store",
6
6
  "core.artifact_store",
7
7
  "core.env_file_store",
8
- "core.template_store"
8
+ "core.template_store",
9
+ "configs"
9
10
  ]
10
11
 
11
12
  def create(definition)
@@ -17,12 +18,14 @@ class KuberKit::Core::ConfigurationFactory
17
18
  templates = fetch_templates(configuration_attrs.templates)
18
19
 
19
20
  KuberKit::Core::Configuration.new(
20
- name: configuration_attrs.name,
21
- artifacts: artifacts,
22
- registries: registries,
23
- env_files: env_files,
24
- templates: templates,
25
- kubecfg_path: configuration_attrs.kubecfg_path
21
+ name: configuration_attrs.name,
22
+ artifacts: artifacts,
23
+ registries: registries,
24
+ env_files: env_files,
25
+ templates: templates,
26
+ kubeconfig_path: configuration_attrs.kubeconfig_path,
27
+ deploy_strategy: configuration_attrs.deploy_strategy || configs.deploy_strategy,
28
+ services_attributes: configuration_attrs.services_attributes
26
29
  )
27
30
  end
28
31
 
@@ -25,6 +25,7 @@ class KuberKit::Core::ConfigurationStore
25
25
  @@configuration_definitions[configuration_definition.configuration_name] = configuration_definition
26
26
  end
27
27
 
28
+ Contract Symbol => Any
28
29
  def get_definition(configuration_name)
29
30
  @@configuration_definitions ||= {}
30
31
 
@@ -35,6 +36,7 @@ class KuberKit::Core::ConfigurationStore
35
36
  @@configuration_definitions[configuration_name]
36
37
  end
37
38
 
39
+ Contract Symbol => Any
38
40
  def get_configuration(configuration_name)
39
41
  definition = get_definition(configuration_name)
40
42
 
@@ -1,23 +1,30 @@
1
1
  class KuberKit::Core::ContextHelper::BaseHelper
2
- attr_reader :shell, :artifact_store, :image_store
2
+ CONTRACT = RespondTo[:get_binding]
3
3
 
4
- def initialize(image_store:, artifact_store:, shell:)
5
- @image_store = image_store
6
- @artifact_store = artifact_store
7
- @shell = shell
4
+ attr_reader :shell, :artifact_store, :image_store, :env_file_reader
5
+
6
+ def initialize(image_store:, artifact_store:, shell:, env_file_reader:)
7
+ @image_store = image_store
8
+ @artifact_store = artifact_store
9
+ @shell = shell
10
+ @env_file_reader = env_file_reader
8
11
  end
9
12
 
10
13
  def image_url(image_name)
11
- image = @image_store.get_image(image_name)
14
+ image = @image_store.get_image(image_name.to_sym)
12
15
 
13
16
  image.remote_registry_url
14
17
  end
15
18
 
16
19
  def artifact_path(name, file_name = nil)
17
- artifact = @artifact_store.get(name)
20
+ artifact = @artifact_store.get(name.to_sym)
18
21
  [artifact.cloned_path, file_name].compact.join("/")
19
22
  end
20
23
 
24
+ def env_file(env_file_name)
25
+ @env_file_reader.call(@shell, env_file_name)
26
+ end
27
+
21
28
  def configuration_name
22
29
  KuberKit.current_configuration.name
23
30
  end
@@ -1,23 +1,26 @@
1
1
  class KuberKit::Core::ContextHelper::ContextHelperFactory
2
2
  include KuberKit::Import[
3
3
  "core.image_store",
4
- "core.artifact_store"
4
+ "core.artifact_store",
5
+ env_file_reader: "env_file_reader.action_handler"
5
6
  ]
6
7
 
7
8
  def build_image_context(shell)
8
9
  KuberKit::Core::ContextHelper::ImageHelper.new(
9
- image_store: image_store,
10
- artifact_store: artifact_store,
11
- shell: shell
10
+ image_store: image_store,
11
+ artifact_store: artifact_store,
12
+ shell: shell,
13
+ env_file_reader: env_file_reader
12
14
  )
13
15
  end
14
16
 
15
17
  def build_service_context(shell, service)
16
18
  KuberKit::Core::ContextHelper::ServiceHelper.new(
17
- image_store: image_store,
18
- artifact_store: artifact_store,
19
- shell: shell,
20
- service: service
19
+ image_store: image_store,
20
+ artifact_store: artifact_store,
21
+ shell: shell,
22
+ env_file_reader: env_file_reader,
23
+ service: service,
21
24
  )
22
25
  end
23
26
  end
@@ -1,9 +1,10 @@
1
1
  class KuberKit::Core::ContextHelper::ServiceHelper < KuberKit::Core::ContextHelper::BaseHelper
2
- def initialize(image_store:, artifact_store:, shell:, service:)
2
+ def initialize(image_store:, artifact_store:, shell:, env_file_reader:, service:)
3
3
  super(
4
- image_store: image_store,
5
- artifact_store: artifact_store,
6
- shell: shell
4
+ image_store: image_store,
5
+ artifact_store: artifact_store,
6
+ shell: shell,
7
+ env_file_reader: env_file_reader
7
8
  )
8
9
  @service = service
9
10
  end
@@ -13,7 +14,10 @@ class KuberKit::Core::ContextHelper::ServiceHelper < KuberKit::Core::ContextHelp
13
14
  end
14
15
 
15
16
  def service_uri
16
- service_name
17
- .sub("_", "-")
17
+ @service.uri
18
+ end
19
+
20
+ def attribute(attribute_name)
21
+ @service.attribute(attribute_name)
18
22
  end
19
23
  end
@@ -25,6 +25,7 @@ class KuberKit::Core::ImageStore
25
25
  @@image_definitions[image_definition.image_name] = image_definition
26
26
  end
27
27
 
28
+ Contract Symbol => Any
28
29
  def get_definition(image_name)
29
30
  @@image_definitions ||= {}
30
31
 
@@ -35,6 +36,7 @@ class KuberKit::Core::ImageStore
35
36
  @@image_definitions[image_name]
36
37
  end
37
38
 
39
+ Contract Symbol => Any
38
40
  def get_image(image_name)
39
41
  definition = get_definition(image_name)
40
42
 
@@ -1,14 +1,32 @@
1
1
  class KuberKit::Core::Service
2
- attr_reader :name, :template_name, :tags
2
+ AttributeNotSet = Class.new(Indocker::Error)
3
+
4
+ attr_reader :name, :template_name, :tags, :images, :attributes
3
5
 
4
6
  Contract KeywordArgs[
5
7
  name: Symbol,
6
8
  template_name: Symbol,
7
9
  tags: ArrayOf[Symbol],
10
+ images: ArrayOf[Symbol],
11
+ attributes: HashOf[Symbol => Any],
8
12
  ] => Any
9
- def initialize(name:, template_name:, tags:)
13
+ def initialize(name:, template_name:, tags:, images:, attributes:)
10
14
  @name = name
11
15
  @template_name = template_name
12
16
  @tags = tags
17
+ @images = images
18
+ @attributes = attributes
19
+ end
20
+
21
+ def uri
22
+ name.to_s.gsub("_", "-")
23
+ end
24
+
25
+ def attribute(attribute_name)
26
+ unless attributes.has_key?(attribute_name.to_sym)
27
+ raise AttributeNotSet, "attribute #{attribute_name} was not set"
28
+ end
29
+
30
+ attributes[attribute_name.to_sym]
13
31
  end
14
32
  end
@@ -10,7 +10,9 @@ class KuberKit::Core::ServiceDefinition
10
10
  OpenStruct.new(
11
11
  name: @service_name,
12
12
  template_name: get_value(@template_name),
13
- tags: Array(get_value(@tags)).map(&:to_sym)
13
+ tags: Array(get_value(@tags)).map(&:to_sym),
14
+ images: Array(get_value(@images)).map(&:to_sym),
15
+ attributes: get_value(@attributes),
14
16
  )
15
17
  end
16
18
 
@@ -26,6 +28,18 @@ class KuberKit::Core::ServiceDefinition
26
28
  self
27
29
  end
28
30
 
31
+ def images(*value, &block)
32
+ @images = block_given? ? block : Array(value).flatten
33
+
34
+ self
35
+ end
36
+
37
+ def attributes(value = nil, &block)
38
+ @attributes = block_given? ? block : value
39
+
40
+ self
41
+ end
42
+
29
43
  private
30
44
  def get_value(variable)
31
45
  variable.is_a?(Proc) ? variable.call : variable
@@ -8,10 +8,15 @@ class KuberKit::Core::ServiceFactory
8
8
  raise AttributeNotSetError, "Please set template for service using #template method"
9
9
  end
10
10
 
11
+ configuration_attributes = KuberKit.current_configuration.service_attributes(service_attrs.name)
12
+ attributes = (service_attrs.attributes || {}).merge(configuration_attributes)
13
+
11
14
  KuberKit::Core::Service.new(
12
15
  name: service_attrs.name,
13
16
  template_name: service_attrs.template_name,
14
- tags: service_attrs.tags
17
+ tags: service_attrs.tags,
18
+ images: service_attrs.images,
19
+ attributes: attributes
15
20
  )
16
21
  end
17
22
  end
@@ -25,6 +25,7 @@ class KuberKit::Core::ServiceStore
25
25
  @@service_definitions[service_definition.service_name] = service_definition
26
26
  end
27
27
 
28
+ Contract Symbol => Any
28
29
  def get_definition(service_name)
29
30
  @@service_definitions ||= {}
30
31
 
@@ -35,6 +36,7 @@ class KuberKit::Core::ServiceStore
35
36
  @@service_definitions[service_name]
36
37
  end
37
38
 
39
+ Contract Symbol => Any
38
40
  def get_service(service_name)
39
41
  definition = get_definition(service_name)
40
42
 
@@ -0,0 +1,12 @@
1
+ class KuberKit::EnvFileReader::ActionHandler
2
+ include KuberKit::Import[
3
+ "env_file_reader.reader",
4
+ "core.env_file_store",
5
+ ]
6
+
7
+ Contract KuberKit::Shell::AbstractShell, Symbol => Any
8
+ def call(shell, env_file_name)
9
+ env_file = env_file_store.get(env_file_name)
10
+ reader.read(shell, env_file)
11
+ end
12
+ end
@@ -2,14 +2,14 @@ class KuberKit::EnvFileReader::Reader
2
2
  ReaderNotFoundError = Class.new(KuberKit::NotFoundError)
3
3
 
4
4
  include KuberKit::Import[
5
- "env_file_reader.artifact_file_reader",
5
+ "env_file_reader.strategies.artifact_file",
6
6
  ]
7
7
 
8
8
  def use_reader(env_file_reader, env_file_class:)
9
9
  @@readers ||= {}
10
10
 
11
- if !env_file_reader.is_a?(KuberKit::EnvFileReader::AbstractEnvFileReader)
12
- raise ArgumentError.new("should be an instance of KuberKit::EnvFileReader::AbstractEnvFileReader, got: #{env_file_reader.inspect}")
11
+ if !env_file_reader.is_a?(KuberKit::EnvFileReader::Strategies::Abstract)
12
+ raise ArgumentError.new("should be an instance of KuberKit::EnvFileReader::Strategies::Abstract, got: #{env_file_reader.inspect}")
13
13
  end
14
14
 
15
15
  @@readers[env_file_class] = env_file_reader
@@ -26,7 +26,7 @@ class KuberKit::EnvFileReader::Reader
26
26
  end
27
27
 
28
28
  def add_default_readers
29
- use_reader(artifact_file_reader, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
29
+ use_reader(artifact_file, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
30
30
  end
31
31
 
32
32
  def reset!
@@ -1,4 +1,4 @@
1
- class KuberKit::EnvFileReader::AbstractEnvFileReader
1
+ class KuberKit::EnvFileReader::Strategies::Abstract
2
2
  def read(shell, env_file)
3
3
  raise KuberKit::NotImplementedError, "must be implemented"
4
4
  end
@@ -1,4 +1,4 @@
1
- class KuberKit::EnvFileReader::ArtifactFileReader < KuberKit::EnvFileReader::AbstractEnvFileReader
1
+ class KuberKit::EnvFileReader::Strategies::ArtifactFile < KuberKit::EnvFileReader::Strategies::Abstract
2
2
  include KuberKit::Import[
3
3
  "core.artifact_store"
4
4
  ]
@@ -0,0 +1,20 @@
1
+ class KuberKit::ImageCompiler::ActionHandler
2
+ include KuberKit::Import[
3
+ "image_compiler.compiler",
4
+ "core.image_store",
5
+ "configs",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Symbol, String => Any
9
+ def call(shell, image_name, build_id)
10
+ image = image_store.get_image(image_name)
11
+
12
+ compile_dir = generate_compile_dir(build_id: build_id)
13
+
14
+ compiler.compile(shell, image, compile_dir)
15
+ end
16
+
17
+ def generate_compile_dir(build_id:)
18
+ File.join(configs.image_compile_dir, build_id)
19
+ end
20
+ end
@@ -3,19 +3,16 @@ class KuberKit::ImageCompiler::Compiler
3
3
  "image_compiler.image_build_dir_creator",
4
4
  "image_compiler.image_builder",
5
5
  "core.context_helper_factory",
6
- "core.image_store"
7
6
  ]
8
7
 
9
- Contract KuberKit::Shell::AbstractShell, Symbol, String => Any
10
- def compile(shell, image_name, builds_dir)
11
- image = image_store.get_image(image_name)
12
-
8
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Image, String => Any
9
+ def compile(shell, image, builds_dir)
13
10
  image_build_dir = File.join(builds_dir, image.name.to_s)
14
11
 
15
12
  context_helper = context_helper_factory.build_image_context(shell)
16
13
  image_build_dir_creator.create(shell, image, image_build_dir, context_helper: context_helper)
17
14
 
18
- image_builder.build(shell, image, image_build_dir, context_helper: context_helper, args: [])
15
+ image_builder.build(shell, image, image_build_dir, context_helper: context_helper)
19
16
  image_build_dir_creator.cleanup(shell, image_build_dir)
20
17
  end
21
18
  end
@@ -5,10 +5,9 @@ class KuberKit::ImageCompiler::ImageBuilder
5
5
  ]
6
6
 
7
7
  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Image, String, KeywordArgs[
8
- args: Maybe[Any],
9
- context_helper: Maybe[KuberKit::Core::ContextHelper]
8
+ context_helper: Maybe[KuberKit::Core::ContextHelper::BaseHelper::CONTRACT]
10
9
  ] => Any
11
- def build(shell, image, build_dir, context_helper: nil, args: [])
10
+ def build(shell, image, build_dir, context_helper: nil)
12
11
  image.before_build_callback.call(context_helper, build_dir) if image.before_build_callback
13
12
 
14
13
  docker_commands.build(shell, build_dir, ["-t=#{image.registry_url}"])
@@ -2,6 +2,6 @@ require 'erb'
2
2
 
3
3
  class KuberKit::Preprocessing::TextPreprocessor
4
4
  def compile(template, context_helper: nil)
5
- ERB.new(template).result(context_helper&.get_binding)
5
+ ERB.new(template, nil, '-').result(context_helper&.get_binding)
6
6
  end
7
7
  end
@@ -0,0 +1,16 @@
1
+ class KuberKit::ServiceDeployer::ActionHandler
2
+ include KuberKit::Import[
3
+ "service_deployer.deployer",
4
+ "service_deployer.strategy_detector",
5
+ "core.service_store",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Symbol => Any
9
+ def call(shell, service_name)
10
+ service = service_store.get_service(service_name)
11
+
12
+ strategy_name = strategy_detector.call(service)
13
+
14
+ deployer.restart(shell, service, strategy_name)
15
+ end
16
+ end
@@ -0,0 +1,37 @@
1
+ class KuberKit::ServiceDeployer::Deployer
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 deploy(shell, service, strategy_name)
21
+ add_default_strategies
22
+
23
+ deployer = @@strategies[strategy_name]
24
+
25
+ raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if deployer.nil?
26
+
27
+ deployer.deploy(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
@@ -0,0 +1,5 @@
1
+ class KuberKit::ServiceDeployer::Strategies::Abstract
2
+ def deploy(shell, service)
3
+ raise KuberKit::NotImplementedError, "must be implemented"
4
+ end
5
+ end
@@ -0,0 +1,18 @@
1
+ class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeployer::Strategies::Abstract
2
+ include KuberKit::Import[
3
+ "service_reader.reader",
4
+ "shell.kubectl_commands",
5
+ "configs",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
9
+ def deploy(shell, service)
10
+ service_config = reader.read(shell, service)
11
+ config_path = "#{configs.service_config_dir}/#{service.name}.yml"
12
+ shell.write(config_path, service_config)
13
+
14
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
15
+ kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path)
16
+ kubectl_commands.rolling_restart(shell, service.uri, kubeconfig_path: kubeconfig_path)
17
+ end
18
+ end
@@ -0,0 +1,6 @@
1
+ class KuberKit::ServiceDeployer::StrategyDetector
2
+ Contract KuberKit::Core::Service => Symbol
3
+ def call(service)
4
+ KuberKit.current_configuration.deploy_strategy
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ class KuberKit::ServiceReader::ActionHandler
2
+ include KuberKit::Import[
3
+ "service_reader.reader",
4
+ "core.service_store",
5
+ ]
6
+
7
+ Contract KuberKit::Shell::AbstractShell, Symbol => Any
8
+ def call(shell, service_name)
9
+ service = service_store.get_service(service_name)
10
+
11
+ reader.read(shell, service)
12
+ end
13
+ end
@@ -1,4 +1,4 @@
1
- class KuberKit::ServiceDeployer::ServiceReader
1
+ class KuberKit::ServiceReader::Reader
2
2
  include KuberKit::Import[
3
3
  "core.template_store",
4
4
  "core.context_helper_factory",
@@ -6,6 +6,7 @@ class KuberKit::ServiceDeployer::ServiceReader
6
6
  "preprocessing.text_preprocessor"
7
7
  ]
8
8
 
9
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
9
10
  def read(shell, service)
10
11
  template = template_store.get(service.template_name)
11
12
 
@@ -1,12 +1,42 @@
1
+ require 'json'
2
+ require 'shellwords'
3
+
1
4
  class KuberKit::Shell::KubectlCommands
2
- def apply_file(shell, file_path, kubecfg_path: nil)
5
+ def apply_file(shell, file_path, kubeconfig_path: nil)
3
6
  command_parts = []
4
- if kubecfg_path
5
- command_parts << "KUBECFG=#{kubecfg_path}"
7
+ if kubeconfig_path
8
+ command_parts << "KUBECONFIG=#{kubeconfig_path}"
6
9
  end
7
10
 
8
11
  command_parts << "kubectl apply -f #{file_path}"
9
12
 
10
13
  shell.exec!(command_parts.join(" "))
11
14
  end
15
+
16
+ def rolling_restart(shell, deployment_name, kubeconfig_path: nil)
17
+ patch_deployment(shell, deployment_name, {
18
+ spec: {
19
+ template: {
20
+ metadata: {
21
+ labels: {
22
+ redeploy: "$(date +%s)"
23
+ }
24
+ }
25
+ }
26
+ }
27
+ }, kubeconfig_path: kubeconfig_path)
28
+ end
29
+
30
+ def patch_deployment(shell, deployment_name, specs, kubeconfig_path: nil)
31
+ command_parts = []
32
+ if kubeconfig_path
33
+ command_parts << "KUBECONFIG=#{kubeconfig_path}"
34
+ end
35
+
36
+ specs_json = JSON.dump(specs).gsub('"', '\"')
37
+
38
+ command_parts << %Q{kubectl patch deployment #{deployment_name} -p "#{specs_json}"}
39
+
40
+ shell.exec!(command_parts.join(" "))
41
+ end
12
42
  end
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.6"
3
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.1
4
+ version: 0.1.6
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-10-30 00:00:00.000000000 Z
11
+ date: 2020-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts-lite
@@ -144,6 +144,7 @@ files:
144
144
  - TODO.md
145
145
  - bin/console
146
146
  - bin/kit
147
+ - example/app_data/env_file.yml
147
148
  - example/app_data/service.yml
148
149
  - example/app_data/test.env
149
150
  - example/app_data/test.txt
@@ -163,14 +164,15 @@ files:
163
164
  - example/infrastructure/env_files.rb
164
165
  - example/infrastructure/registries.rb
165
166
  - example/infrastructure/templates.rb
166
- - example/services/auth_app.rb
167
+ - example/services/env_file.rb
168
+ - example/services/ruby_app.rb
167
169
  - kuber_kit.gemspec
168
170
  - lib/kuber_kit.rb
169
171
  - lib/kuber_kit/actions/configuration_loader.rb
170
172
  - lib/kuber_kit/actions/env_file_reader.rb
171
173
  - lib/kuber_kit/actions/image_compiler.rb
172
174
  - lib/kuber_kit/actions/kubectl_applier.rb
173
- - lib/kuber_kit/actions/service_applier.rb
175
+ - lib/kuber_kit/actions/service_deployer.rb
174
176
  - lib/kuber_kit/actions/service_reader.rb
175
177
  - lib/kuber_kit/actions/template_reader.rb
176
178
  - lib/kuber_kit/artifacts_sync/abstract_artifact_resolver.rb
@@ -212,13 +214,15 @@ files:
212
214
  - lib/kuber_kit/core/templates/abstract_template.rb
213
215
  - lib/kuber_kit/core/templates/artifact_file.rb
214
216
  - 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
217
+ - lib/kuber_kit/env_file_reader/action_handler.rb
217
218
  - lib/kuber_kit/env_file_reader/reader.rb
219
+ - lib/kuber_kit/env_file_reader/strategies/abstract.rb
220
+ - lib/kuber_kit/env_file_reader/strategies/artifact_file.rb
218
221
  - lib/kuber_kit/extensions/colored_string.rb
219
222
  - lib/kuber_kit/extensions/contracts.rb
220
223
  - lib/kuber_kit/extensions/indocker_compat.rb
221
224
  - lib/kuber_kit/extensions/inspectable.rb
225
+ - lib/kuber_kit/image_compiler/action_handler.rb
222
226
  - lib/kuber_kit/image_compiler/compiler.rb
223
227
  - lib/kuber_kit/image_compiler/image_build_dir_creator.rb
224
228
  - lib/kuber_kit/image_compiler/image_builder.rb
@@ -227,8 +231,14 @@ files:
227
231
  - lib/kuber_kit/preprocessing/dir_preprocessor.rb
228
232
  - lib/kuber_kit/preprocessing/file_preprocessor.rb
229
233
  - lib/kuber_kit/preprocessing/text_preprocessor.rb
234
+ - lib/kuber_kit/service_deployer/action_handler.rb
235
+ - lib/kuber_kit/service_deployer/deployer.rb
230
236
  - lib/kuber_kit/service_deployer/service_list_resolver.rb
231
- - lib/kuber_kit/service_deployer/service_reader.rb
237
+ - lib/kuber_kit/service_deployer/strategies/abstract.rb
238
+ - lib/kuber_kit/service_deployer/strategies/kubernetes.rb
239
+ - lib/kuber_kit/service_deployer/strategy_detector.rb
240
+ - lib/kuber_kit/service_reader/action_handler.rb
241
+ - lib/kuber_kit/service_reader/reader.rb
232
242
  - lib/kuber_kit/shell/abstract_shell.rb
233
243
  - lib/kuber_kit/shell/bash_commands.rb
234
244
  - lib/kuber_kit/shell/command_counter.rb
@@ -1,3 +0,0 @@
1
- KuberKit
2
- .define_service(:auth_app)
3
- .template(:service)
@@ -1,39 +0,0 @@
1
- class KuberKit::Actions::ServiceApplier
2
- include KuberKit::Import[
3
- "core.service_store",
4
- "service_deployer.service_reader",
5
- "service_deployer.service_list_resolver",
6
- "shell.local_shell",
7
- "shell.kubectl_commands",
8
- "configs",
9
- "ui"
10
- ]
11
-
12
- Contract KeywordArgs[
13
- services: Maybe[ArrayOf[String]],
14
- tags: Maybe[ArrayOf[String]],
15
- ] => Any
16
- def call(services:, tags:)
17
- service_names = service_list_resolver.resolve(
18
- services: services || [],
19
- tags: tags || []
20
- )
21
- service_names.each do |service_name|
22
- apply_service(service_name.to_sym)
23
- end
24
- end
25
-
26
- def apply_service(service_name)
27
- service = service_store.get_service(service_name)
28
- kubecfg_path = KuberKit.current_configuration.kubecfg_path
29
-
30
- result = service_reader.read(local_shell, service)
31
- file_path = "#{configs.service_config_dir}/#{service.name}.yml"
32
- local_shell.write(file_path, result)
33
-
34
- ui.create_task("Applying file: #{file_path}") do |task|
35
- kubectl_commands.apply_file(local_shell, file_path, kubecfg_path: kubecfg_path)
36
- task.update_title("Applied file: #{file_path}")
37
- end
38
- end
39
- end