kuber_kit 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c4c480432ebb2d98461e9549271f26e607e3790464fde89b30631a675e9bc85
4
- data.tar.gz: 04b4f46724bd31dd72467ffa0f073dd495dcaafecc7213ca57a6c70bbce1e4f7
3
+ metadata.gz: d85e9b30ebb43f4fe0a056823e3eeda6f878784555fa909df004e46522d750ec
4
+ data.tar.gz: 441270e1f147862ff75f999606bfafa7e467efde71765d27490e8f6afdd74740
5
5
  SHA512:
6
- metadata.gz: ef5601a6e9bd63a49154f6ae14ce77eebcbc0702bd89578fd413ec23226f7db0c37b60cffcd20d314bf1cfbd6fb98a8e050f9912be668aa3dce31dd6a5056cae
7
- data.tar.gz: 7b17416b8b1d98b706409b1b88c44679b61f1689bf6c38d449320789d843f8f9b74dd519e61af364639e9cf78e95e28fd6499817980e2d211a85f0bd98d0b210
6
+ metadata.gz: 0d112105c8b7e268a528b59097028f9c483ac921d3b584bb372ba33f23595d3d8614f4a7251b75498934c1f0d365e5eed3d9c2b237a9f30d5a235cbd290150c8
7
+ data.tar.gz: '068e6d864886eb38d6ebd9f8ac10358bb3f220cabe0c38a67df9b6a886b07b224083586be4ddd7320691b05b0420af8f053f9f2d1ed6c2a7c81accd4dce6f4a0'
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.1.3)
4
+ kuber_kit (0.1.4)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
@@ -1,3 +1,4 @@
1
1
  KuberKit
2
2
  .define_service(:ruby_app)
3
- .template(:service)
3
+ .template(:service)
4
+ .images(:ruby_app)
@@ -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
@@ -1,7 +1,9 @@
1
1
  class KuberKit::Actions::ServiceDeployer
2
2
  include KuberKit::Import[
3
+ "actions.image_compiler",
3
4
  "service_deployer.service_list_resolver",
4
5
  "service_deployer.deployer",
6
+ "core.service_store",
5
7
  "shell.local_shell",
6
8
  "tools.logger",
7
9
  "ui"
@@ -17,6 +19,17 @@ class KuberKit::Actions::ServiceDeployer
17
19
  tags: tags || []
18
20
  )
19
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)
20
33
  task_group = ui.create_task_group
21
34
 
22
35
  service_names.each do |service_name|
@@ -32,4 +45,8 @@ class KuberKit::Actions::ServiceDeployer
32
45
 
33
46
  task_group.wait
34
47
  end
48
+
49
+ def compile_images(images_names)
50
+ image_compiler.call(images_names, {}) if images_names.any?
51
+ end
35
52
  end
@@ -1,5 +1,5 @@
1
1
  class KuberKit::Core::Configuration
2
- attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubecfg_path, :deploy_strategy
2
+ attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path, :deploy_strategy
3
3
 
4
4
  Contract KeywordArgs[
5
5
  name: Symbol,
@@ -7,16 +7,16 @@ 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
11
  deploy_strategy: Symbol
12
12
  ] => Any
13
- def initialize(name:, artifacts:, registries:, env_files:, templates:, kubecfg_path:, deploy_strategy:)
14
- @name = name
15
- @artifacts = artifacts
16
- @registries = registries
17
- @env_files = env_files
18
- @templates = templates
19
- @kubecfg_path = kubecfg_path
20
- @deploy_strategy = deploy_strategy
13
+ def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, deploy_strategy:)
14
+ @name = name
15
+ @artifacts = artifacts
16
+ @registries = registries
17
+ @env_files = env_files
18
+ @templates = templates
19
+ @kubeconfig_path = kubeconfig_path
20
+ @deploy_strategy = deploy_strategy
21
21
  end
22
22
  end
@@ -19,7 +19,7 @@ class KuberKit::Core::ConfigurationDefinition
19
19
  registries: @registries,
20
20
  env_files: @env_files,
21
21
  templates: @templates,
22
- kubecfg_path: @kubecfg_path,
22
+ kubeconfig_path: @kubeconfig_path,
23
23
  deploy_strategy: @deploy_strategy
24
24
  )
25
25
  end
@@ -60,8 +60,8 @@ class KuberKit::Core::ConfigurationDefinition
60
60
  self
61
61
  end
62
62
 
63
- def kubecfg_path(path)
64
- @kubecfg_path = path
63
+ def kubeconfig_path(path)
64
+ @kubeconfig_path = path
65
65
 
66
66
  self
67
67
  end
@@ -23,7 +23,7 @@ class KuberKit::Core::ConfigurationFactory
23
23
  registries: registries,
24
24
  env_files: env_files,
25
25
  templates: templates,
26
- kubecfg_path: configuration_attrs.kubecfg_path,
26
+ kubeconfig_path: configuration_attrs.kubeconfig_path,
27
27
  deploy_strategy: configuration_attrs.deploy_strategy || configs.deploy_strategy
28
28
  )
29
29
  end
@@ -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
 
@@ -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,15 +1,17 @@
1
1
  class KuberKit::Core::Service
2
- attr_reader :name, :template_name, :tags
2
+ attr_reader :name, :template_name, :tags, :images
3
3
 
4
4
  Contract KeywordArgs[
5
5
  name: Symbol,
6
6
  template_name: Symbol,
7
7
  tags: ArrayOf[Symbol],
8
+ images: ArrayOf[Symbol],
8
9
  ] => Any
9
- def initialize(name:, template_name:, tags:)
10
+ def initialize(name:, template_name:, tags:, images:)
10
11
  @name = name
11
12
  @template_name = template_name
12
13
  @tags = tags
14
+ @images = images
13
15
  end
14
16
 
15
17
  def uri
@@ -10,7 +10,8 @@ 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),
14
15
  )
15
16
  end
16
17
 
@@ -26,6 +27,12 @@ class KuberKit::Core::ServiceDefinition
26
27
  self
27
28
  end
28
29
 
30
+ def images(*value, &block)
31
+ @images = block_given? ? block : Array(value).flatten
32
+
33
+ self
34
+ end
35
+
29
36
  private
30
37
  def get_value(variable)
31
38
  variable.is_a?(Proc) ? variable.call : variable
@@ -11,7 +11,8 @@ class KuberKit::Core::ServiceFactory
11
11
  KuberKit::Core::Service.new(
12
12
  name: service_attrs.name,
13
13
  template_name: service_attrs.template_name,
14
- tags: service_attrs.tags
14
+ tags: service_attrs.tags,
15
+ images: service_attrs.images
15
16
  )
16
17
  end
17
18
  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
 
@@ -11,8 +11,8 @@ class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeplo
11
11
  config_path = "#{configs.service_config_dir}/#{service.name}.yml"
12
12
  shell.write(config_path, service_config)
13
13
 
14
- kubecfg_path = KuberKit.current_configuration.kubecfg_path
15
- kubectl_commands.apply_file(shell, config_path, kubecfg_path: kubecfg_path)
16
- kubectl_commands.rolling_restart(shell, service.uri, kubecfg_path: kubecfg_path)
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
17
  end
18
18
  end
@@ -2,10 +2,10 @@ require 'json'
2
2
  require 'shellwords'
3
3
 
4
4
  class KuberKit::Shell::KubectlCommands
5
- def apply_file(shell, file_path, kubecfg_path: nil)
5
+ def apply_file(shell, file_path, kubeconfig_path: nil)
6
6
  command_parts = []
7
- if kubecfg_path
8
- command_parts << "KUBECFG=#{kubecfg_path}"
7
+ if kubeconfig_path
8
+ command_parts << "KUBECONFIG=#{kubeconfig_path}"
9
9
  end
10
10
 
11
11
  command_parts << "kubectl apply -f #{file_path}"
@@ -13,7 +13,7 @@ class KuberKit::Shell::KubectlCommands
13
13
  shell.exec!(command_parts.join(" "))
14
14
  end
15
15
 
16
- def rolling_restart(shell, deployment_name, kubecfg_path: nil)
16
+ def rolling_restart(shell, deployment_name, kubeconfig_path: nil)
17
17
  patch_deployment(shell, deployment_name, {
18
18
  spec: {
19
19
  template: {
@@ -24,13 +24,13 @@ class KuberKit::Shell::KubectlCommands
24
24
  }
25
25
  }
26
26
  }
27
- }, kubecfg_path: kubecfg_path)
27
+ }, kubeconfig_path: kubeconfig_path)
28
28
  end
29
29
 
30
- def patch_deployment(shell, deployment_name, specs, kubecfg_path: nil)
30
+ def patch_deployment(shell, deployment_name, specs, kubeconfig_path: nil)
31
31
  command_parts = []
32
- if kubecfg_path
33
- command_parts << "KUBECFG=#{kubecfg_path}"
32
+ if kubeconfig_path
33
+ command_parts << "KUBECONFIG=#{kubeconfig_path}"
34
34
  end
35
35
 
36
36
  specs_json = JSON.dump(specs).gsub('"', '\"')
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kuber_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Khaziev