kuber_kit 0.2.0 → 0.2.1
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 +2 -2
- data/TODO.md +2 -0
- data/example/services/env_file.rb +1 -0
- data/example/services/ruby_app.rb +2 -1
- data/lib/kuber_kit/actions/kubectl_applier.rb +3 -2
- data/lib/kuber_kit/actions/kubectl_attacher.rb +8 -1
- data/lib/kuber_kit/actions/service_deployer.rb +28 -0
- data/lib/kuber_kit/cli.rb +4 -1
- data/lib/kuber_kit/core/configuration.rb +5 -3
- data/lib/kuber_kit/core/configuration_definition.rb +8 -1
- data/lib/kuber_kit/core/configuration_factory.rb +1 -0
- data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +5 -3
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +25 -26
- data/lib/kuber_kit/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d669438926fb5a86f3ca7fff7f37226330cdcc4f581e590ff8ef9720eae9134c
|
4
|
+
data.tar.gz: 5ce659015d98f83c07ad3e643b70ffadb729722712c88c32364a9f9668b4717e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a3966b99289899afb257091b11424ba5a0c56d9c5f4385bcb519de32a37355445554922468070cc7520fbfc727435d8b0b41dd8f5cb73f097c6ffe3baf0a9f3f
|
7
|
+
data.tar.gz: 1343042958b0e71cd5091db62b9646ad43e027833b2bd8df7cf742b1f73065992071e208110bb95a0020e2a66b00d8c12a8a91dd090cbd2bb195114dde3a68cc
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kuber_kit (0.2.
|
4
|
+
kuber_kit (0.2.1)
|
5
5
|
cli-ui
|
6
6
|
contracts-lite
|
7
7
|
dry-auto_inject
|
@@ -26,7 +26,7 @@ GEM
|
|
26
26
|
dry-container (0.7.2)
|
27
27
|
concurrent-ruby (~> 1.0)
|
28
28
|
dry-configurable (~> 0.1, >= 0.1.3)
|
29
|
-
dry-core (0.4.
|
29
|
+
dry-core (0.4.10)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
dry-equalizer (0.3.0)
|
32
32
|
method_source (1.0.0)
|
data/TODO.md
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
+
- allow setting default configuration for kuberkit using env variable
|
1
2
|
- implement interactive shell.exec!
|
3
|
+
- allow deploying only services enabled for specific configuration
|
2
4
|
- list services and require confirmation before deployment
|
3
5
|
- add build vars support (use images instead of containers)
|
4
6
|
- template should be able to set default attributes
|
@@ -7,9 +7,10 @@ class KuberKit::Actions::KubectlApplier
|
|
7
7
|
|
8
8
|
Contract String, Hash => Any
|
9
9
|
def call(file_path, options)
|
10
|
-
kubeconfig_path
|
10
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
11
|
+
deploy_namespace = KuberKit.current_configuration.deploy_namespace
|
11
12
|
ui.create_task("Applying file: #{file_path}") do |task|
|
12
|
-
kubectl_commands.apply_file(local_shell, file_path, kubeconfig_path: kubeconfig_path)
|
13
|
+
kubectl_commands.apply_file(local_shell, file_path, kubeconfig_path: kubeconfig_path, namespace: deploy_namespace)
|
13
14
|
task.update_title("Applied file: #{file_path}")
|
14
15
|
end
|
15
16
|
|
@@ -8,7 +8,14 @@ class KuberKit::Actions::KubectlAttacher
|
|
8
8
|
Contract String, Hash => Any
|
9
9
|
def call(pod_name, options)
|
10
10
|
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
11
|
-
|
11
|
+
deploy_namespace = KuberKit.current_configuration.deploy_namespace
|
12
|
+
|
13
|
+
kubectl_commands.exec(
|
14
|
+
local_shell, pod_name, "bash", args: "-it",
|
15
|
+
kubeconfig_path: kubeconfig_path,
|
16
|
+
interactive: true,
|
17
|
+
namespace: deploy_namespace
|
18
|
+
)
|
12
19
|
|
13
20
|
true
|
14
21
|
rescue KuberKit::Error => e
|
@@ -14,6 +14,10 @@ class KuberKit::Actions::ServiceDeployer
|
|
14
14
|
tags: Maybe[ArrayOf[String]],
|
15
15
|
] => Any
|
16
16
|
def call(services:, tags:)
|
17
|
+
if services.empty? && tags.empty?
|
18
|
+
services, tags = show_tags_selection
|
19
|
+
end
|
20
|
+
|
17
21
|
service_names = service_list_resolver.resolve(
|
18
22
|
services: services || [],
|
19
23
|
tags: tags || []
|
@@ -59,4 +63,28 @@ class KuberKit::Actions::ServiceDeployer
|
|
59
63
|
def compile_images(images_names)
|
60
64
|
image_compiler.call(images_names, {}) if images_names.any?
|
61
65
|
end
|
66
|
+
|
67
|
+
def show_tags_selection()
|
68
|
+
specific_service_option = "deploy specific service"
|
69
|
+
|
70
|
+
tags = service_store.all_definitions.values.map(&:to_service_attrs).map(&:tags).flatten.uniq.map(&:to_s)
|
71
|
+
|
72
|
+
tags.push(specific_service_option)
|
73
|
+
|
74
|
+
ui.prompt("Please select which tag to deploy", tags) do |selected_tag|
|
75
|
+
if selected_tag == specific_service_option
|
76
|
+
show_service_selection
|
77
|
+
else
|
78
|
+
return [[], [selected_tag]]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def show_service_selection()
|
84
|
+
services = service_store.all_definitions.values.map(&:service_name).uniq.map(&:to_s)
|
85
|
+
|
86
|
+
ui.prompt("Please select which service to deploy", services) do |selected_service|
|
87
|
+
return [[selected_service], []]
|
88
|
+
end
|
89
|
+
end
|
62
90
|
end
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -37,7 +37,10 @@ class KuberKit::CLI < Thor
|
|
37
37
|
KuberKit.set_debug_mode(options[:debug])
|
38
38
|
|
39
39
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
40
|
-
result = KuberKit::Container['actions.service_deployer'].call(
|
40
|
+
result = KuberKit::Container['actions.service_deployer'].call(
|
41
|
+
services: options[:services] || [],
|
42
|
+
tags: options[:tags] || []
|
43
|
+
)
|
41
44
|
end
|
42
45
|
|
43
46
|
logger = KuberKit::Container['tools.logger']
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class KuberKit::Core::Configuration
|
2
2
|
attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path,
|
3
|
-
:deploy_strategy, :services_attributes, :build_servers
|
3
|
+
:deploy_strategy, :deploy_namespace, :services_attributes, :build_servers
|
4
4
|
|
5
5
|
Contract KeywordArgs[
|
6
6
|
name: Symbol,
|
@@ -9,12 +9,13 @@ class KuberKit::Core::Configuration
|
|
9
9
|
env_files: Hash,
|
10
10
|
templates: Hash,
|
11
11
|
kubeconfig_path: Maybe[String],
|
12
|
-
deploy_strategy:
|
12
|
+
deploy_strategy: Symbol,
|
13
|
+
deploy_namespace: Maybe[Symbol],
|
13
14
|
services_attributes: HashOf[Symbol => Hash],
|
14
15
|
build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer]
|
15
16
|
] => Any
|
16
17
|
def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:,
|
17
|
-
deploy_strategy:, services_attributes:, build_servers:)
|
18
|
+
deploy_strategy:, deploy_namespace:, services_attributes:, build_servers:)
|
18
19
|
@name = name
|
19
20
|
@artifacts = artifacts
|
20
21
|
@registries = registries
|
@@ -22,6 +23,7 @@ class KuberKit::Core::Configuration
|
|
22
23
|
@templates = templates
|
23
24
|
@kubeconfig_path = kubeconfig_path
|
24
25
|
@deploy_strategy = deploy_strategy
|
26
|
+
@deploy_namespace = deploy_namespace
|
25
27
|
@services_attributes = services_attributes
|
26
28
|
@build_servers = build_servers
|
27
29
|
end
|
@@ -24,9 +24,10 @@ class KuberKit::Core::ConfigurationDefinition
|
|
24
24
|
templates: @templates,
|
25
25
|
kubeconfig_path: @kubeconfig_path,
|
26
26
|
deploy_strategy: @deploy_strategy,
|
27
|
+
deploy_namespace: @deploy_namespace,
|
27
28
|
enabled_services: @enabled_services,
|
28
29
|
build_servers: @build_servers,
|
29
|
-
services_attributes: @services_attributes
|
30
|
+
services_attributes: @services_attributes,
|
30
31
|
)
|
31
32
|
end
|
32
33
|
|
@@ -80,6 +81,12 @@ class KuberKit::Core::ConfigurationDefinition
|
|
80
81
|
self
|
81
82
|
end
|
82
83
|
|
84
|
+
def deploy_namespace(namespace)
|
85
|
+
@deploy_namespace = namespace
|
86
|
+
|
87
|
+
self
|
88
|
+
end
|
89
|
+
|
83
90
|
def deploy_strategy(path)
|
84
91
|
@deploy_strategy = path
|
85
92
|
|
@@ -27,6 +27,7 @@ class KuberKit::Core::ConfigurationFactory
|
|
27
27
|
templates: templates,
|
28
28
|
kubeconfig_path: configuration_attrs.kubeconfig_path,
|
29
29
|
deploy_strategy: configuration_attrs.deploy_strategy || configs.deploy_strategy,
|
30
|
+
deploy_namespace: configuration_attrs.deploy_namespace,
|
30
31
|
services_attributes: configuration_attrs.services_attributes,
|
31
32
|
build_servers: build_servers
|
32
33
|
)
|
@@ -11,13 +11,15 @@ 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
|
-
kubeconfig_path
|
15
|
-
|
14
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
15
|
+
deploy_namespace = KuberKit.current_configuration.deploy_namespace
|
16
|
+
|
17
|
+
kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: deploy_namespace)
|
16
18
|
|
17
19
|
deployment_restart_enabled = service.attribute(:deployment_restart_enabled, default: true)
|
18
20
|
deployment_restart_name = service.attribute(:deployment_restart_name, default: service.uri)
|
19
21
|
if deployment_restart_enabled
|
20
|
-
kubectl_commands.rolling_restart(shell, deployment_restart_name, kubeconfig_path: kubeconfig_path)
|
22
|
+
kubectl_commands.rolling_restart(shell, deployment_restart_name, kubeconfig_path: kubeconfig_path, namespace: deploy_namespace)
|
21
23
|
end
|
22
24
|
end
|
23
25
|
end
|
@@ -2,25 +2,35 @@ require 'json'
|
|
2
2
|
require 'shellwords'
|
3
3
|
|
4
4
|
class KuberKit::Shell::Commands::KubectlCommands
|
5
|
-
def
|
5
|
+
def kubectl_run(shell, command_list, kubeconfig_path: nil, namespace: nil, interactive: false)
|
6
6
|
command_parts = []
|
7
7
|
if kubeconfig_path
|
8
8
|
command_parts << "KUBECONFIG=#{kubeconfig_path}"
|
9
9
|
end
|
10
10
|
|
11
|
-
command_parts << "kubectl
|
11
|
+
command_parts << "kubectl"
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
if namespace
|
14
|
+
command_parts << "-n #{namespace}"
|
15
|
+
end
|
15
16
|
|
16
|
-
|
17
|
-
command_parts = []
|
17
|
+
command_parts += Array(command_list)
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# TODO: investigate how to do it with shell.
|
20
|
+
if interactive
|
21
|
+
system(command_parts.join(" "))
|
22
|
+
else
|
23
|
+
shell.exec!(command_parts.join(" "))
|
21
24
|
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def apply_file(shell, file_path, kubeconfig_path: nil, namespace: nil)
|
28
|
+
kubectl_run(shell, "apply -f #{file_path}", kubeconfig_path: kubeconfig_path, namespace: namespace)
|
29
|
+
end
|
22
30
|
|
23
|
-
|
31
|
+
def exec(shell, pod_name, command, args: nil, kubeconfig_path: nil, interactive: false, namespace: nil)
|
32
|
+
command_parts = []
|
33
|
+
command_parts << "exec"
|
24
34
|
|
25
35
|
if args
|
26
36
|
command_parts << args
|
@@ -28,16 +38,10 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
28
38
|
|
29
39
|
command_parts << pod_name
|
30
40
|
command_parts << "-- #{command}"
|
31
|
-
|
32
|
-
# TODO: investigate how to do it with shell.
|
33
|
-
if interactive
|
34
|
-
system(command_parts.join(" "))
|
35
|
-
else
|
36
|
-
shell.exec!(command_parts.join(" "))
|
37
|
-
end
|
41
|
+
kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, interactive: interactive, namespace: namespace)
|
38
42
|
end
|
39
43
|
|
40
|
-
def rolling_restart(shell, deployment_name, kubeconfig_path: nil)
|
44
|
+
def rolling_restart(shell, deployment_name, kubeconfig_path: nil, namespace: namespace)
|
41
45
|
patch_deployment(shell, deployment_name, {
|
42
46
|
spec: {
|
43
47
|
template: {
|
@@ -48,19 +52,14 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
48
52
|
}
|
49
53
|
}
|
50
54
|
}
|
51
|
-
}, kubeconfig_path: kubeconfig_path)
|
55
|
+
}, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
52
56
|
end
|
53
57
|
|
54
|
-
def patch_deployment(shell, deployment_name, specs, kubeconfig_path: nil)
|
55
|
-
command_parts = []
|
56
|
-
if kubeconfig_path
|
57
|
-
command_parts << "KUBECONFIG=#{kubeconfig_path}"
|
58
|
-
end
|
59
|
-
|
58
|
+
def patch_deployment(shell, deployment_name, specs, kubeconfig_path: nil, namespace: nil)
|
60
59
|
specs_json = JSON.dump(specs).gsub('"', '\"')
|
61
60
|
|
62
|
-
|
61
|
+
command = %Q{patch deployment #{deployment_name} -p "#{specs_json}"}
|
63
62
|
|
64
|
-
shell
|
63
|
+
kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
65
64
|
end
|
66
65
|
end
|
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.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-11-
|
11
|
+
date: 2020-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -283,7 +283,7 @@ homepage: https://github.com/ArtStation/kuber_kit
|
|
283
283
|
licenses:
|
284
284
|
- MIT
|
285
285
|
metadata: {}
|
286
|
-
post_install_message:
|
286
|
+
post_install_message:
|
287
287
|
rdoc_options: []
|
288
288
|
require_paths:
|
289
289
|
- lib
|
@@ -299,7 +299,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
299
299
|
version: '0'
|
300
300
|
requirements: []
|
301
301
|
rubygems_version: 3.0.8
|
302
|
-
signing_key:
|
302
|
+
signing_key:
|
303
303
|
specification_version: 4
|
304
304
|
summary: Docker Containers Build & Deployment
|
305
305
|
test_files: []
|