kuber_kit 0.3.2 → 0.3.7
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 +4 -4
- data/Gemfile.lock +4 -6
- data/TODO.md +2 -2
- data/bin/{console → kit_console} +0 -0
- data/lib/kuber_kit.rb +3 -1
- data/lib/kuber_kit/actions/kubectl_attacher.rb +7 -1
- data/lib/kuber_kit/actions/kubectl_console.rb +32 -0
- data/lib/kuber_kit/actions/kubectl_logs.rb +37 -0
- data/lib/kuber_kit/actions/service_deployer.rb +5 -4
- data/lib/kuber_kit/cli.rb +32 -6
- data/lib/kuber_kit/container.rb +10 -2
- data/lib/kuber_kit/core/context_helper/base_helper.rb +7 -0
- data/lib/kuber_kit/service_deployer/deployer.rb +2 -2
- data/lib/kuber_kit/service_deployer/strategies/docker.rb +46 -0
- data/lib/kuber_kit/service_deployer/strategies/docker_compose.rb +16 -6
- data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +34 -7
- data/lib/kuber_kit/shell/commands/docker_commands.rb +20 -0
- data/lib/kuber_kit/shell/commands/docker_compose_commands.rb +9 -4
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +38 -15
- data/lib/kuber_kit/ui/interactive.rb +7 -1
- data/lib/kuber_kit/ui/simple.rb +2 -1
- data/lib/kuber_kit/version.rb +1 -1
- metadata +7 -5
- data/lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb +0 -35
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e15ac135b8fd4fab45aee2797f1aa6c836e299e40175e6c518761af7d7557587
|
4
|
+
data.tar.gz: a998aa67c2389dad43604b610471f9b196456dffb100926d25e3acbf6782494f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ac0c29ae11579f2431f8fc7972027b8551866d96cc212d4117eddfb91694d7680a73f0d6d867f955746475e404cd6136b8d4ad228e5489366df7f881cbba92be
|
7
|
+
data.tar.gz: d29aaa6aa028eef516f91a8f9081fd4a9d32c5c9f850755c7bea8583240c9b3bf2636dc2bab745fa778062c2a45334fc043d49d69d10963c574be4f26fc66044
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kuber_kit (0.3.
|
4
|
+
kuber_kit (0.3.7)
|
5
5
|
cli-ui
|
6
6
|
contracts-lite
|
7
7
|
dry-auto_inject
|
@@ -19,16 +19,14 @@ GEM
|
|
19
19
|
docile (1.3.2)
|
20
20
|
dry-auto_inject (0.7.0)
|
21
21
|
dry-container (>= 0.3.4)
|
22
|
-
dry-configurable (0.
|
22
|
+
dry-configurable (0.12.0)
|
23
23
|
concurrent-ruby (~> 1.0)
|
24
|
-
dry-core (~> 0.
|
25
|
-
dry-equalizer (~> 0.2)
|
24
|
+
dry-core (~> 0.5, >= 0.5.0)
|
26
25
|
dry-container (0.7.2)
|
27
26
|
concurrent-ruby (~> 1.0)
|
28
27
|
dry-configurable (~> 0.1, >= 0.1.3)
|
29
|
-
dry-core (0.
|
28
|
+
dry-core (0.5.0)
|
30
29
|
concurrent-ruby (~> 1.0)
|
31
|
-
dry-equalizer (0.3.0)
|
32
30
|
method_source (1.0.0)
|
33
31
|
net-ssh (6.1.0)
|
34
32
|
pry (0.13.1)
|
data/TODO.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
+
- https://ttytoolkit.org/
|
2
|
+
- kit status should show the list of services and their status, with ability to select & view logs
|
1
3
|
- list services and require confirmation before deployment
|
2
|
-
- kit attach should list available deployments/pods, and ask for specific container if it has multiple containers
|
3
4
|
- add kit logs support, should work similar to kit attach
|
4
5
|
- allow deploying only services enabled for specific configuration
|
5
6
|
- find a way to always deploy some service, e.g. for migrations and env_files
|
6
|
-
- add ability to set container health checks
|
7
7
|
- template should be able to set default attributes
|
8
8
|
- template should be able to depend on image?
|
data/bin/{console → kit_console}
RENAMED
File without changes
|
data/lib/kuber_kit.rb
CHANGED
@@ -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
|
|
@@ -166,6 +166,8 @@ module KuberKit
|
|
166
166
|
autoload :ConfigurationLoader, 'actions/configuration_loader'
|
167
167
|
autoload :KubectlApplier, 'actions/kubectl_applier'
|
168
168
|
autoload :KubectlAttacher, 'actions/kubectl_attacher'
|
169
|
+
autoload :KubectlConsole, 'actions/kubectl_console'
|
170
|
+
autoload :KubectlLogs, 'actions/kubectl_logs'
|
169
171
|
end
|
170
172
|
|
171
173
|
module Extensions
|
@@ -5,11 +5,17 @@ class KuberKit::Actions::KubectlAttacher
|
|
5
5
|
"ui"
|
6
6
|
]
|
7
7
|
|
8
|
-
Contract String, Hash => Any
|
8
|
+
Contract Maybe[String], Hash => Any
|
9
9
|
def call(pod_name, options)
|
10
10
|
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
11
11
|
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
12
12
|
|
13
|
+
if !pod_name
|
14
|
+
resources = kubectl_commands.get_resources(local_shell, "deployments", jsonpath: ".items[*].metadata.name")
|
15
|
+
options = resources.split(" ").map{|d| "deploy/#{d}" }
|
16
|
+
pod_name = ui.prompt("Please select deployment to attach", options)
|
17
|
+
end
|
18
|
+
|
13
19
|
kubectl_commands.exec(
|
14
20
|
local_shell, pod_name, "bash", args: "-it",
|
15
21
|
kubeconfig_path: kubeconfig_path,
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class KuberKit::Actions::KubectlConsole
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.kubectl_commands",
|
4
|
+
"shell.local_shell",
|
5
|
+
"ui"
|
6
|
+
]
|
7
|
+
|
8
|
+
Contract Maybe[String], Hash => Any
|
9
|
+
def call(pod_name, options)
|
10
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
11
|
+
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
12
|
+
|
13
|
+
if !pod_name
|
14
|
+
resources = kubectl_commands.get_resources(local_shell, "deployments", jsonpath: ".items[*].metadata.name")
|
15
|
+
options = resources.split(" ").map{|d| "deploy/#{d}" }
|
16
|
+
pod_name = ui.prompt("Please select deployment to attach", options)
|
17
|
+
end
|
18
|
+
|
19
|
+
kubectl_commands.exec(
|
20
|
+
local_shell, pod_name, "bin/console", args: "-it",
|
21
|
+
kubeconfig_path: kubeconfig_path,
|
22
|
+
interactive: true,
|
23
|
+
namespace: deployer_namespace
|
24
|
+
)
|
25
|
+
|
26
|
+
true
|
27
|
+
rescue KuberKit::Error => e
|
28
|
+
ui.print_error("Error", e.message)
|
29
|
+
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class KuberKit::Actions::KubectlLogs
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.kubectl_commands",
|
4
|
+
"shell.local_shell",
|
5
|
+
"ui"
|
6
|
+
]
|
7
|
+
|
8
|
+
Contract Maybe[String], Hash => Any
|
9
|
+
def call(pod_name, options)
|
10
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
11
|
+
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
12
|
+
|
13
|
+
if !pod_name
|
14
|
+
deployments = kubectl_commands.get_resources(local_shell, "deployments", jsonpath: ".items[*].metadata.name")
|
15
|
+
deploy_options = deployments.split(" ").map{|d| "deploy/#{d}" }
|
16
|
+
pod_name = ui.prompt("Please select deployment to attach", deploy_options)
|
17
|
+
end
|
18
|
+
|
19
|
+
args = nil
|
20
|
+
if options[:follow]
|
21
|
+
args = "-f"
|
22
|
+
end
|
23
|
+
|
24
|
+
kubectl_commands.logs(
|
25
|
+
local_shell, pod_name,
|
26
|
+
args: args,
|
27
|
+
kubeconfig_path: kubeconfig_path,
|
28
|
+
namespace: deployer_namespace
|
29
|
+
)
|
30
|
+
|
31
|
+
true
|
32
|
+
rescue KuberKit::Error => e
|
33
|
+
ui.print_error("Error", e.message)
|
34
|
+
|
35
|
+
false
|
36
|
+
end
|
37
|
+
end
|
@@ -10,10 +10,11 @@ class KuberKit::Actions::ServiceDeployer
|
|
10
10
|
]
|
11
11
|
|
12
12
|
Contract KeywordArgs[
|
13
|
-
services:
|
14
|
-
tags:
|
13
|
+
services: Maybe[ArrayOf[String]],
|
14
|
+
tags: Maybe[ArrayOf[String]],
|
15
|
+
skip_compile: Maybe[Bool],
|
15
16
|
] => Any
|
16
|
-
def call(services:, tags:)
|
17
|
+
def call(services:, tags:, skip_compile: false)
|
17
18
|
if services.empty? && tags.empty?
|
18
19
|
services, tags = show_tags_selection
|
19
20
|
end
|
@@ -33,7 +34,7 @@ class KuberKit::Actions::ServiceDeployer
|
|
33
34
|
|
34
35
|
images_names = services.map(&:images).flatten.uniq
|
35
36
|
|
36
|
-
compile_images(images_names)
|
37
|
+
compile_images(images_names) unless skip_compile
|
37
38
|
deploy_services(service_names)
|
38
39
|
|
39
40
|
true
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -31,15 +31,17 @@ class KuberKit::CLI < Thor
|
|
31
31
|
end
|
32
32
|
|
33
33
|
desc "deploy CONTEXT_NAME", "Deploy CONTEXT_NAME with kubectl"
|
34
|
-
method_option :services,
|
35
|
-
method_option :tags,
|
34
|
+
method_option :services, :type => :array, aliases: ["-s"]
|
35
|
+
method_option :tags, :type => :array, aliases: ["-t"]
|
36
|
+
method_option :skip_compile, :type => :boolean, aliases: ["-B"]
|
36
37
|
def deploy
|
37
38
|
KuberKit.set_debug_mode(options[:debug])
|
38
39
|
|
39
40
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
40
41
|
result = KuberKit::Container['actions.service_deployer'].call(
|
41
|
-
services:
|
42
|
-
tags:
|
42
|
+
services: options[:services] || [],
|
43
|
+
tags: options[:tags] || [],
|
44
|
+
skip_compile: options[:skip_compile] || false
|
43
45
|
)
|
44
46
|
end
|
45
47
|
|
@@ -91,8 +93,8 @@ class KuberKit::CLI < Thor
|
|
91
93
|
end
|
92
94
|
end
|
93
95
|
|
94
|
-
desc "attach POD_NAME", "Attach to POD_NAME
|
95
|
-
def attach(pod_name)
|
96
|
+
desc "attach POD_NAME", "Attach to POD_NAME using kubectl"
|
97
|
+
def attach(pod_name = nil)
|
96
98
|
KuberKit.set_debug_mode(options[:debug])
|
97
99
|
|
98
100
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
@@ -100,6 +102,30 @@ class KuberKit::CLI < Thor
|
|
100
102
|
end
|
101
103
|
end
|
102
104
|
|
105
|
+
desc "launch console in POD_NAME", "Attach to POD_NAME using kubectl & launch bin/console"
|
106
|
+
def console(pod_name = nil)
|
107
|
+
KuberKit.set_debug_mode(options[:debug])
|
108
|
+
|
109
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
110
|
+
KuberKit::Container['actions.kubectl_console'].call(pod_name, options)
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
desc "show logs for POD_NAME", "Show logs for POD_NAME using kubectl"
|
115
|
+
method_option :follow, :type => :boolean, aliases: ["-f"]
|
116
|
+
def logs(pod_name = nil)
|
117
|
+
KuberKit.set_debug_mode(options[:debug])
|
118
|
+
|
119
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
120
|
+
KuberKit::Container['actions.kubectl_logs'].call(pod_name, options)
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
desc "version", "Print current version"
|
125
|
+
def version
|
126
|
+
puts KuberKit::VERSION
|
127
|
+
end
|
128
|
+
|
103
129
|
def self.exit_on_failure?
|
104
130
|
true
|
105
131
|
end
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -33,6 +33,14 @@ class KuberKit::Container
|
|
33
33
|
KuberKit::Actions::KubectlAttacher.new
|
34
34
|
end
|
35
35
|
|
36
|
+
register "actions.kubectl_console" do
|
37
|
+
KuberKit::Actions::KubectlConsole.new
|
38
|
+
end
|
39
|
+
|
40
|
+
register "actions.kubectl_logs" do
|
41
|
+
KuberKit::Actions::KubectlLogs.new
|
42
|
+
end
|
43
|
+
|
36
44
|
register "configs" do
|
37
45
|
KuberKit::Configs.new
|
38
46
|
end
|
@@ -233,8 +241,8 @@ class KuberKit::Container
|
|
233
241
|
KuberKit::ServiceDeployer::Strategies::Kubernetes.new
|
234
242
|
end
|
235
243
|
|
236
|
-
register "service_deployer.strategies.
|
237
|
-
KuberKit::ServiceDeployer::Strategies::
|
244
|
+
register "service_deployer.strategies.docker" do
|
245
|
+
KuberKit::ServiceDeployer::Strategies::Docker.new
|
238
246
|
end
|
239
247
|
|
240
248
|
register "service_deployer.strategies.docker_compose" do
|
@@ -33,6 +33,13 @@ class KuberKit::Core::ContextHelper::BaseHelper
|
|
33
33
|
KuberKit.global_build_vars
|
34
34
|
end
|
35
35
|
|
36
|
+
def global_build_args
|
37
|
+
unless KuberKit.deprecation_warnings_disabled?
|
38
|
+
puts "DEPRECATION: global_build_args is deprecated, please use global_build_vars instead"
|
39
|
+
end
|
40
|
+
global_build_vars
|
41
|
+
end
|
42
|
+
|
36
43
|
def get_binding
|
37
44
|
binding
|
38
45
|
end
|
@@ -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.
|
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(:
|
42
|
+
register_strategy(:docker, docker)
|
43
43
|
register_strategy(:docker_compose, docker_compose)
|
44
44
|
end
|
45
45
|
end
|
@@ -0,0 +1,46 @@
|
|
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(
|
40
|
+
shell, image.remote_registry_url,
|
41
|
+
run_args: docker_run_args,
|
42
|
+
run_command: docker_run_command,
|
43
|
+
detached: !!strategy_options[:detached]
|
44
|
+
)
|
45
|
+
end
|
46
|
+
end
|
@@ -5,20 +5,30 @@ 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
|
-
|
15
|
-
|
16
|
-
|
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:
|
20
|
-
command:
|
21
|
-
|
29
|
+
service: service_name,
|
30
|
+
command: command_name,
|
31
|
+
detached: !!strategy_options[:detached]
|
22
32
|
)
|
23
33
|
end
|
24
34
|
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
|
15
|
-
|
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:
|
42
|
+
kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
18
43
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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,26 @@ 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, detached: false)
|
18
|
+
command_parts = []
|
19
|
+
command_parts << "docker run"
|
20
|
+
command_parts << "-d" if detached
|
21
|
+
command_parts << run_args if run_args
|
22
|
+
command_parts << image_name
|
23
|
+
command_parts << run_command if run_command
|
24
|
+
|
25
|
+
shell.exec!(command_parts.join(" "))
|
26
|
+
end
|
27
|
+
|
28
|
+
def container_exists?(shell, container_name)
|
29
|
+
result = get_container_id(shell, container_name)
|
30
|
+
result && result != ""
|
31
|
+
end
|
32
|
+
|
33
|
+
def delete_container(shell, container_name)
|
34
|
+
shell.exec!(%Q{docker rm -f #{container_name}})
|
35
|
+
end
|
36
|
+
|
17
37
|
def get_container_id(shell, container_name, only_healthy: false, status: "running")
|
18
38
|
command_parts = []
|
19
39
|
command_parts << "docker ps -a -q"
|
@@ -1,13 +1,18 @@
|
|
1
1
|
class KuberKit::Shell::Commands::DockerComposeCommands
|
2
|
-
def run(shell, path, service:, command:, interactive: false)
|
2
|
+
def run(shell, path, service:, command:, interactive: false, detached: false)
|
3
3
|
command_parts = [
|
4
4
|
"docker-compose",
|
5
|
-
"-f #{path}",
|
6
5
|
"run",
|
7
|
-
|
8
|
-
command
|
6
|
+
"-f #{path}",
|
9
7
|
]
|
10
8
|
|
9
|
+
if detached
|
10
|
+
command_parts << "-d"
|
11
|
+
end
|
12
|
+
|
13
|
+
command_parts << service
|
14
|
+
command_parts << command
|
15
|
+
|
11
16
|
if interactive
|
12
17
|
shell.interactive!(command_parts.join(" "))
|
13
18
|
else
|
@@ -40,25 +40,56 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
40
40
|
kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, interactive: interactive, namespace: namespace)
|
41
41
|
end
|
42
42
|
|
43
|
+
def logs(shell, pod_name, args: nil, kubeconfig_path: nil, namespace: nil)
|
44
|
+
command_parts = []
|
45
|
+
command_parts << "logs"
|
46
|
+
|
47
|
+
if args
|
48
|
+
command_parts << args
|
49
|
+
end
|
50
|
+
|
51
|
+
command_parts << pod_name
|
52
|
+
kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, interactive: true, namespace: namespace)
|
53
|
+
end
|
54
|
+
|
55
|
+
def get_resources(shell, resource_type, field_selector: nil, jsonpath: ".items[*].metadata.name", kubeconfig_path: nil, namespace: nil)
|
56
|
+
command_parts = []
|
57
|
+
command_parts << "get #{resource_type}"
|
58
|
+
|
59
|
+
if field_selector
|
60
|
+
command_parts << "--field-selector=#{field_selector}"
|
61
|
+
end
|
62
|
+
|
63
|
+
if jsonpath
|
64
|
+
command_parts << "-o jsonpath='{#{jsonpath}}'"
|
65
|
+
end
|
66
|
+
|
67
|
+
kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
68
|
+
end
|
69
|
+
|
43
70
|
def resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
44
|
-
result =
|
71
|
+
result = get_resources(shell, resource_type,
|
72
|
+
field_selector: "metadata.name=#{resource_name}", kubeconfig_path: kubeconfig_path, namespace: namespace
|
73
|
+
)
|
45
74
|
result && result != ""
|
46
75
|
end
|
47
76
|
|
48
|
-
def
|
49
|
-
command = %Q{
|
77
|
+
def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
78
|
+
command = %Q{delete #{resource_type} #{resource_name}}
|
50
79
|
|
51
80
|
kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
52
81
|
end
|
53
82
|
|
54
|
-
def
|
55
|
-
|
83
|
+
def patch_resource(shell, resource_type, resource_name, specs, kubeconfig_path: nil, namespace: nil)
|
84
|
+
specs_json = JSON.dump(specs).gsub('"', '\"')
|
85
|
+
|
86
|
+
command = %Q{patch #{resource_type} #{resource_name} -p "#{specs_json}"}
|
56
87
|
|
57
88
|
kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
58
89
|
end
|
59
90
|
|
60
|
-
def rolling_restart(shell,
|
61
|
-
|
91
|
+
def rolling_restart(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
92
|
+
patch_resource(shell, resource_type, resource_name, {
|
62
93
|
spec: {
|
63
94
|
template: {
|
64
95
|
metadata: {
|
@@ -70,12 +101,4 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
70
101
|
}
|
71
102
|
}, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
72
103
|
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
104
|
end
|
@@ -29,7 +29,13 @@ class KuberKit::UI::Interactive
|
|
29
29
|
def prompt(text, options, &callback)
|
30
30
|
CLI::UI::Prompt.ask(text) do |handler|
|
31
31
|
options.each do |option|
|
32
|
-
|
32
|
+
if callback
|
33
|
+
handler.option(option, &callback)
|
34
|
+
else
|
35
|
+
handler.option(option) do |selection|
|
36
|
+
selection
|
37
|
+
end
|
38
|
+
end
|
33
39
|
end
|
34
40
|
end
|
35
41
|
end
|
data/lib/kuber_kit/ui/simple.rb
CHANGED
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.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -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
|
@@ -191,6 +191,8 @@ files:
|
|
191
191
|
- lib/kuber_kit/actions/image_compiler.rb
|
192
192
|
- lib/kuber_kit/actions/kubectl_applier.rb
|
193
193
|
- lib/kuber_kit/actions/kubectl_attacher.rb
|
194
|
+
- lib/kuber_kit/actions/kubectl_console.rb
|
195
|
+
- lib/kuber_kit/actions/kubectl_logs.rb
|
194
196
|
- lib/kuber_kit/actions/service_deployer.rb
|
195
197
|
- lib/kuber_kit/actions/service_reader.rb
|
196
198
|
- lib/kuber_kit/actions/template_reader.rb
|
@@ -260,9 +262,9 @@ files:
|
|
260
262
|
- lib/kuber_kit/service_deployer/deployer.rb
|
261
263
|
- lib/kuber_kit/service_deployer/service_list_resolver.rb
|
262
264
|
- lib/kuber_kit/service_deployer/strategies/abstract.rb
|
265
|
+
- lib/kuber_kit/service_deployer/strategies/docker.rb
|
263
266
|
- lib/kuber_kit/service_deployer/strategies/docker_compose.rb
|
264
267
|
- lib/kuber_kit/service_deployer/strategies/kubernetes.rb
|
265
|
-
- lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb
|
266
268
|
- lib/kuber_kit/service_deployer/strategy_detector.rb
|
267
269
|
- lib/kuber_kit/service_reader/action_handler.rb
|
268
270
|
- 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
|