kuber_kit 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 339883bd875277f494fdef1fe01035920e6a867ea98394e10c4d08e5a8b5a108
4
- data.tar.gz: 96448b7bb059d60e55ec0b8bceb70e1a02b8740773dcdbc4944afa3fafda3192
3
+ metadata.gz: ae284766e125c54579032cd54c29d602848f95a9a91e07c357ab1b985632a9d1
4
+ data.tar.gz: 9a9c7a194893cdc39c7629fbda8e03bb7da6b77583899995c14a511f3b152943
5
5
  SHA512:
6
- metadata.gz: 49b5bf9c115c06ab88f67b60bc54f55b254a3a1a4de58ebe0fa834c04b352d8e759ed66747bd98e1d62a8adbb794cbda948dbd324c06165113af29d28ce02aad
7
- data.tar.gz: 77354cf127ad50ff4f5f092aeaebfdb7568030ea8120e990dc01eb109a9ca679da83f1124cd5df225d37053ce2abe84d4e9016c0d284b47a323a4d175ba28b40
6
+ metadata.gz: 3cbef254939ce54ff789fcde11ca3db500bfc552f75768bb9424dbdef682830eceed216b046f5930b95e45c8985c2b77e6ce2947e277951e718b1f38df62af29
7
+ data.tar.gz: bb571f10d8f4e41612c31e1616138e45a54134b92b4b8f9a9577083fc175982e3e5f1a77f1ec564a160ce88f46f76d57d143a8968b8282c92d66f4cb2e2f4220
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.3.2)
4
+ kuber_kit (0.3.3)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
File without changes
@@ -146,9 +146,9 @@ module KuberKit
146
146
 
147
147
  module Strategies
148
148
  autoload :Abstract, 'service_deployer/strategies/abstract'
149
+ autoload :Docker, 'service_deployer/strategies/docker'
149
150
  autoload :DockerCompose, 'service_deployer/strategies/docker_compose'
150
151
  autoload :Kubernetes, 'service_deployer/strategies/kubernetes'
151
- autoload :KubernetesRunner, 'service_deployer/strategies/kubernetes_runner'
152
152
  end
153
153
  end
154
154
 
@@ -233,8 +233,8 @@ class KuberKit::Container
233
233
  KuberKit::ServiceDeployer::Strategies::Kubernetes.new
234
234
  end
235
235
 
236
- register "service_deployer.strategies.kubernetes_runner" do
237
- KuberKit::ServiceDeployer::Strategies::KubernetesRunner.new
236
+ register "service_deployer.strategies.docker" do
237
+ KuberKit::ServiceDeployer::Strategies::Docker.new
238
238
  end
239
239
 
240
240
  register "service_deployer.strategies.docker_compose" do
@@ -4,7 +4,7 @@ class KuberKit::ServiceDeployer::Deployer
4
4
  include KuberKit::Import[
5
5
  "core.service_store",
6
6
  "service_deployer.strategies.kubernetes",
7
- "service_deployer.strategies.kubernetes_runner",
7
+ "service_deployer.strategies.docker",
8
8
  "service_deployer.strategies.docker_compose"
9
9
  ]
10
10
 
@@ -39,7 +39,7 @@ class KuberKit::ServiceDeployer::Deployer
39
39
  private
40
40
  def add_default_strategies
41
41
  register_strategy(:kubernetes, kubernetes)
42
- register_strategy(:kubernetes_runner, kubernetes_runner)
42
+ register_strategy(:docker, docker)
43
43
  register_strategy(:docker_compose, docker_compose)
44
44
  end
45
45
  end
@@ -0,0 +1,41 @@
1
+ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer::Strategies::Abstract
2
+ include KuberKit::Import[
3
+ "shell.docker_commands",
4
+ "core.image_store",
5
+ "configs",
6
+ ]
7
+
8
+ STRATEGY_OPTIONS = [
9
+ :container_name,
10
+ :image_name,
11
+ :docker_run_args,
12
+ :docker_run_command,
13
+ :delete_if_exists
14
+ ]
15
+
16
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
17
+ def deploy(shell, service)
18
+ strategy_options = service.attribute(:deployer, default: {})
19
+ unknown_options = strategy_options.keys.map(&:to_sym) - STRATEGY_OPTIONS
20
+ if unknown_options.any?
21
+ raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
22
+ end
23
+
24
+ container_name = strategy_options.fetch(:container_name, service.uri)
25
+ docker_run_args = strategy_options.fetch(:docker_run_args, nil)
26
+ docker_run_command = strategy_options.fetch(:docker_run_command, nil)
27
+
28
+ image_name = strategy_options.fetch(:image_name, nil)
29
+ if image_name.nil?
30
+ raise KuberKit::Error, "image_name is mandatory attribute for this deploy strategy"
31
+ end
32
+ image = image_store.get_image(image_name.to_sym)
33
+
34
+ delete_enabled = strategy_options.fetch(:delete_if_exists, false)
35
+ if delete_enabled && docker_commands.container_exists?(shell, container_name)
36
+ docker_commands.delete_container(shell, container_name)
37
+ end
38
+
39
+ docker_commands.run(shell, image.remote_registry_url, run_args: docker_run_args, run_command: docker_run_command)
40
+ end
41
+ end
@@ -5,20 +5,29 @@ class KuberKit::ServiceDeployer::Strategies::DockerCompose < KuberKit::ServiceDe
5
5
  "configs",
6
6
  ]
7
7
 
8
+ STRATEGY_OPTIONS = [
9
+ :service_name,
10
+ :command_name
11
+ ]
12
+
8
13
  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
9
14
  def deploy(shell, service)
10
15
  service_config = reader.read(shell, service)
11
16
  config_path = "#{configs.service_config_dir}/#{service.name}.yml"
12
17
  shell.write(config_path, service_config)
13
18
 
14
- deployer_service_name = service.attribute(:deployer_service_name, default: service.name.to_s)
15
- deployer_command_name = service.attribute(:deployer_command_name, default: "bash")
16
- deployer_interactive = service.attribute(:deployer_interactive, default: false)
19
+ strategy_options = service.attribute(:deployer, default: {})
20
+ unknown_options = strategy_options.keys.map(&:to_sym) - STRATEGY_OPTIONS
21
+ if unknown_options.any?
22
+ raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
23
+ end
24
+
25
+ service_name = strategy_options.fetch(:service_name, service.name.to_s)
26
+ command_name = strategy_options.fetch(:command_name, "bash")
17
27
 
18
28
  docker_compose_commands.run(shell, config_path,
19
- service: deployer_service_name,
20
- command: deployer_command_name,
21
- interactive: deployer_interactive
29
+ service: service_name,
30
+ command: command_name,
22
31
  )
23
32
  end
24
33
  end
@@ -5,21 +5,48 @@ class KuberKit::ServiceDeployer::Strategies::Kubernetes < KuberKit::ServiceDeplo
5
5
  "configs",
6
6
  ]
7
7
 
8
+ STRATEGY_OPTIONS = [
9
+ :resource_type,
10
+ :resource_name,
11
+ :delete_if_exists,
12
+ :restart_if_exists
13
+ ]
14
+
8
15
  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
9
16
  def deploy(shell, service)
10
17
  service_config = reader.read(shell, service)
11
18
  config_path = "#{configs.service_config_dir}/#{service.name}.yml"
12
19
  shell.write(config_path, service_config)
13
20
 
14
- kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
15
- deployer_namespace = KuberKit.current_configuration.deployer_namespace
21
+ kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
22
+ namespace = KuberKit.current_configuration.deployer_namespace
23
+
24
+ strategy_options = service.attribute(:deployer, default: {})
25
+ unknown_options = strategy_options.keys.map(&:to_sym) - STRATEGY_OPTIONS
26
+ if unknown_options.any?
27
+ raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
28
+ end
29
+
30
+ resource_type = strategy_options.fetch(:resource_type, "deployment")
31
+ resource_name = strategy_options.fetch(:resource_name, service.uri)
32
+
33
+ resource_exists = kubectl_commands.resource_exists?(
34
+ shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace
35
+ )
36
+
37
+ delete_enabled = strategy_options.fetch(:delete_if_exists, false)
38
+ if delete_enabled && resource_exists
39
+ kubectl_commands.delete_resource(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
40
+ end
16
41
 
17
- kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: deployer_namespace)
42
+ kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: namespace)
18
43
 
19
- deployer_restart_enabled = service.attribute(:deployer_restart_enabled, default: true)
20
- deployer_restart_name = service.attribute(:deployer_restart_name, default: service.uri)
21
- if deployer_restart_enabled
22
- kubectl_commands.rolling_restart(shell, deployer_restart_name, kubeconfig_path: kubeconfig_path, namespace: deployer_namespace)
44
+ restart_enabled = strategy_options.fetch(:restart_if_exists, true)
45
+ if restart_enabled && resource_exists
46
+ kubectl_commands.rolling_restart(
47
+ shell, resource_type, resource_name,
48
+ kubeconfig_path: kubeconfig_path, namespace: namespace
49
+ )
23
50
  end
24
51
  end
25
52
  end
@@ -14,6 +14,25 @@ class KuberKit::Shell::Commands::DockerCommands
14
14
  shell.exec!(%Q{docker push #{tag_name}})
15
15
  end
16
16
 
17
+ def run(shell, image_name, run_args: nil, run_command: nil)
18
+ command_parts = []
19
+ command_parts << "docker run"
20
+ command_parts << run_args if run_args
21
+ command_parts << image_name
22
+ command_parts << run_command if run_command
23
+
24
+ shell.exec!(command_parts.join(" "))
25
+ end
26
+
27
+ def container_exists?(shell, container_name)
28
+ result = get_container_id(shell, container_name)
29
+ result && result != ""
30
+ end
31
+
32
+ def delete_container(shell, container_name)
33
+ shell.exec!(%Q{docker rm -f #{container_name}})
34
+ end
35
+
17
36
  def get_container_id(shell, container_name, only_healthy: false, status: "running")
18
37
  command_parts = []
19
38
  command_parts << "docker ps -a -q"
@@ -57,8 +57,16 @@ class KuberKit::Shell::Commands::KubectlCommands
57
57
  kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
58
58
  end
59
59
 
60
- def rolling_restart(shell, deployer_name, kubeconfig_path: nil, namespace: nil)
61
- patch_deployment(shell, deployer_name, {
60
+ def patch_resource(shell, resource_type, resource_name, specs, kubeconfig_path: nil, namespace: nil)
61
+ specs_json = JSON.dump(specs).gsub('"', '\"')
62
+
63
+ command = %Q{patch #{resource_type} #{resource_name} -p "#{specs_json}"}
64
+
65
+ kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
66
+ end
67
+
68
+ def rolling_restart(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
69
+ patch_resource(shell, resource_type, resource_name, {
62
70
  spec: {
63
71
  template: {
64
72
  metadata: {
@@ -70,12 +78,4 @@ class KuberKit::Shell::Commands::KubectlCommands
70
78
  }
71
79
  }, kubeconfig_path: kubeconfig_path, namespace: namespace)
72
80
  end
73
-
74
- def patch_deployment(shell, deployer_name, specs, kubeconfig_path: nil, namespace: nil)
75
- specs_json = JSON.dump(specs).gsub('"', '\"')
76
-
77
- command = %Q{patch deployment #{deployer_name} -p "#{specs_json}"}
78
-
79
- kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
80
- end
81
81
  end
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
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.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Khaziev
@@ -140,8 +140,8 @@ description: Docker Containers Build & Deployment
140
140
  email:
141
141
  - gvalmon@gmail.com
142
142
  executables:
143
- - console
144
143
  - kit
144
+ - kit_console
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
@@ -156,8 +156,8 @@ files:
156
156
  - README.md
157
157
  - Rakefile
158
158
  - TODO.md
159
- - bin/console
160
159
  - bin/kit
160
+ - bin/kit_console
161
161
  - example/app_data/docker_compose.yml
162
162
  - example/app_data/env_file.yml
163
163
  - example/app_data/service.yml
@@ -260,9 +260,9 @@ files:
260
260
  - lib/kuber_kit/service_deployer/deployer.rb
261
261
  - lib/kuber_kit/service_deployer/service_list_resolver.rb
262
262
  - lib/kuber_kit/service_deployer/strategies/abstract.rb
263
+ - lib/kuber_kit/service_deployer/strategies/docker.rb
263
264
  - lib/kuber_kit/service_deployer/strategies/docker_compose.rb
264
265
  - lib/kuber_kit/service_deployer/strategies/kubernetes.rb
265
- - lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb
266
266
  - lib/kuber_kit/service_deployer/strategy_detector.rb
267
267
  - lib/kuber_kit/service_reader/action_handler.rb
268
268
  - lib/kuber_kit/service_reader/reader.rb
@@ -1,35 +0,0 @@
1
- class KuberKit::ServiceDeployer::Strategies::KubernetesRunner < 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
- deployer_namespace = KuberKit.current_configuration.deployer_namespace
16
-
17
- deployer_resource_name = service.attribute(:deployer_resource_name, default: service.uri)
18
- deployer_resource_type = service.attribute(:deployer_resource_type, default: "job")
19
-
20
- deployer_delete_enabled = service.attribute(:deployer_delete_enabled, default: true)
21
- if deployer_delete_enabled
22
- delete_resource_if_exists(shell, deployer_resource_type, deployer_resource_name, kubeconfig_path: kubeconfig_path, namespace: deployer_namespace)
23
- end
24
-
25
- kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: deployer_namespace)
26
- end
27
-
28
- private
29
- def delete_resource_if_exists(shell, resource_type, resource_name, kubeconfig_path:, namespace: )
30
- unless kubectl_commands.resource_exists?(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
31
- return false
32
- end
33
- kubectl_commands.delete_resource(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
34
- end
35
- end