kuber_kit 0.3.5 → 0.3.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +35 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/TODO.md +2 -2
- data/lib/kuber_kit.rb +2 -0
- data/lib/kuber_kit/actions/configuration_loader.rb +2 -9
- 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/cli.rb +42 -9
- data/lib/kuber_kit/configs.rb +2 -1
- data/lib/kuber_kit/container.rb +9 -1
- data/lib/kuber_kit/core/service.rb +5 -5
- data/lib/kuber_kit/core/service_factory.rb +0 -6
- data/lib/kuber_kit/service_deployer/strategies/docker.rb +17 -6
- data/lib/kuber_kit/service_deployer/strategies/docker_compose.rb +8 -3
- data/lib/kuber_kit/service_reader/reader.rb +6 -0
- data/lib/kuber_kit/shell/commands/docker_commands.rb +9 -4
- data/lib/kuber_kit/shell/commands/docker_compose_commands.rb +7 -3
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +29 -6
- data/lib/kuber_kit/shell/local_shell.rb +1 -1
- data/lib/kuber_kit/tools/logger_factory.rb +6 -2
- 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 +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ed4a9c2ac89b73ddd0b9d7c0c95845318c46e6389869f4b3a876af67b2d122f6
|
4
|
+
data.tar.gz: 5fb51bb82cc685ee370e880c255ec87e957f5b75c929baf256188582e63fb13f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: df0ceafb8c37a8c216f08eb5c8692fcc6eb2f909bbcc929beb9725fdaea0a73976b5a462d5904361e20c01b121dd5efa16185c6e8f388fe01a9ae7b2c55531f8
|
7
|
+
data.tar.gz: 56a8bdf92b31851078a50c679fc1680adb8f598d3a33ca0010de4789e338a7047a3a34e030cbc186f6b59da7899f64291eec44c34eb18c520e1cc04019414958
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# This workflow uses actions that are not certified by GitHub.
|
2
|
+
# They are provided by a third-party and are governed by
|
3
|
+
# separate terms of service, privacy policy, and support
|
4
|
+
# documentation.
|
5
|
+
# This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
|
6
|
+
# For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
|
7
|
+
|
8
|
+
name: Rspec
|
9
|
+
|
10
|
+
on:
|
11
|
+
push:
|
12
|
+
branches: [ main ]
|
13
|
+
pull_request:
|
14
|
+
branches: [ main ]
|
15
|
+
|
16
|
+
jobs:
|
17
|
+
test:
|
18
|
+
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby-version: ['2.5', '2.7']
|
23
|
+
|
24
|
+
steps:
|
25
|
+
- uses: actions/checkout@v2
|
26
|
+
- name: Set up Ruby
|
27
|
+
# To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
|
28
|
+
# change this to (see https://github.com/ruby/setup-ruby#versioning):
|
29
|
+
# uses: ruby/setup-ruby@v1
|
30
|
+
uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby-version }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rspec spec/
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# KuberKit
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Rspec](https://github.com/ArtStation/kuber_kit/workflows/Rspec/badge.svg)](https://github.com/ArtStation/kuber_kit/actions?query=workflow%3ARspec)
|
4
4
|
|
5
5
|
Solution for building & deploying applications on Kubernetes, written in Ruby.
|
6
6
|
|
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/lib/kuber_kit.rb
CHANGED
@@ -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
|
@@ -1,6 +1,4 @@
|
|
1
1
|
class KuberKit::Actions::ConfigurationLoader
|
2
|
-
APP_CONFIG_FILENAME = "config.rb".freeze
|
3
|
-
|
4
2
|
include KuberKit::Import[
|
5
3
|
"core.registry_store",
|
6
4
|
"core.image_store",
|
@@ -16,13 +14,6 @@ class KuberKit::Actions::ConfigurationLoader
|
|
16
14
|
Contract Hash => Any
|
17
15
|
def call(options)
|
18
16
|
root_path = options[:path] || File.join(Dir.pwd, configs.kuber_kit_dirname)
|
19
|
-
|
20
|
-
# require config file first, in case if other dirs are overriden in config
|
21
|
-
config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
|
22
|
-
if File.exists?(config_file_path)
|
23
|
-
require config_file_path
|
24
|
-
end
|
25
|
-
|
26
17
|
images_path = options[:images_path] || File.join(root_path, configs.images_dirname)
|
27
18
|
services_path = options[:services_path] || File.join(root_path, configs.services_dirname)
|
28
19
|
infra_path = options[:infra_path] || File.join(root_path, configs.infra_dirname)
|
@@ -37,6 +28,8 @@ class KuberKit::Actions::ConfigurationLoader
|
|
37
28
|
logger.info " Configurations path: #{configurations_path.to_s.yellow}"
|
38
29
|
logger.info " Configuration name: #{configuration_name.to_s.yellow}"
|
39
30
|
|
31
|
+
ui.print_info("Logs", "See logs at: #{configs.log_file_path}")
|
32
|
+
|
40
33
|
unless File.exists?(root_path)
|
41
34
|
ui.print_warning "WARNING", "KuberKit root path #{root_path} doesn't exist. You may want to pass it --path parameter."
|
42
35
|
end
|
@@ -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
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'thor'
|
2
2
|
|
3
3
|
class KuberKit::CLI < Thor
|
4
|
+
APP_CONFIG_FILENAME = "config.rb".freeze
|
5
|
+
|
4
6
|
class_option :path, :type => :string
|
5
7
|
class_option :images_path, :type => :string
|
6
8
|
class_option :infra_path, :type => :string
|
@@ -10,7 +12,7 @@ class KuberKit::CLI < Thor
|
|
10
12
|
|
11
13
|
desc "compile IMAGE_NAMES", "Compile image with IMAGE_NAMES (comma-separated)"
|
12
14
|
def compile(image_names_str)
|
13
|
-
|
15
|
+
setup(options)
|
14
16
|
|
15
17
|
image_names = image_names_str.split(",").map(&:strip).map(&:to_sym)
|
16
18
|
|
@@ -35,7 +37,7 @@ class KuberKit::CLI < Thor
|
|
35
37
|
method_option :tags, :type => :array, aliases: ["-t"]
|
36
38
|
method_option :skip_compile, :type => :boolean, aliases: ["-B"]
|
37
39
|
def deploy
|
38
|
-
|
40
|
+
setup(options)
|
39
41
|
|
40
42
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
41
43
|
result = KuberKit::Container['actions.service_deployer'].call(
|
@@ -59,7 +61,7 @@ class KuberKit::CLI < Thor
|
|
59
61
|
|
60
62
|
desc "env ENV_FILE_NAME", "Return content of Env File ENV_FILE_NAME"
|
61
63
|
def env(env_file_name)
|
62
|
-
|
64
|
+
setup(options)
|
63
65
|
|
64
66
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
65
67
|
KuberKit::Container['actions.env_file_reader'].call(env_file_name.to_sym, options)
|
@@ -68,7 +70,7 @@ class KuberKit::CLI < Thor
|
|
68
70
|
|
69
71
|
desc "template TEMPLATE_NAME", "Return content of Template TEMPLATE_NAME"
|
70
72
|
def template(template_name)
|
71
|
-
|
73
|
+
setup(options)
|
72
74
|
|
73
75
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
74
76
|
KuberKit::Container['actions.template_reader'].call(template_name.to_sym, options)
|
@@ -77,7 +79,7 @@ class KuberKit::CLI < Thor
|
|
77
79
|
|
78
80
|
desc "service SERVICE_NAME", "Return content of Service SERVICE_NAME"
|
79
81
|
def service(service_name)
|
80
|
-
|
82
|
+
setup(options)
|
81
83
|
|
82
84
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
83
85
|
KuberKit::Container['actions.service_reader'].call(service_name.to_sym, options)
|
@@ -86,22 +88,41 @@ class KuberKit::CLI < Thor
|
|
86
88
|
|
87
89
|
desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
|
88
90
|
def apply(file_path)
|
89
|
-
|
91
|
+
setup(options)
|
90
92
|
|
91
93
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
92
94
|
KuberKit::Container['actions.kubectl_applier'].call(File.expand_path(file_path), options)
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
96
|
-
desc "attach POD_NAME", "Attach to POD_NAME
|
97
|
-
def attach(pod_name)
|
98
|
-
|
98
|
+
desc "attach POD_NAME", "Attach to POD_NAME using kubectl"
|
99
|
+
def attach(pod_name = nil)
|
100
|
+
setup(options)
|
99
101
|
|
100
102
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
101
103
|
KuberKit::Container['actions.kubectl_attacher'].call(pod_name, options)
|
102
104
|
end
|
103
105
|
end
|
104
106
|
|
107
|
+
desc "console POD_NAME", "Attach to POD_NAME using kubectl & launch bin/console"
|
108
|
+
def console(pod_name = nil)
|
109
|
+
setup(options)
|
110
|
+
|
111
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
112
|
+
KuberKit::Container['actions.kubectl_console'].call(pod_name, options)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
desc "logs POD_NAME", "Show logs for POD_NAME using kubectl"
|
117
|
+
method_option :follow, :type => :boolean, aliases: ["-f"]
|
118
|
+
def logs(pod_name = nil)
|
119
|
+
setup(options)
|
120
|
+
|
121
|
+
if KuberKit::Container['actions.configuration_loader'].call(options)
|
122
|
+
KuberKit::Container['actions.kubectl_logs'].call(pod_name, options)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
105
126
|
desc "version", "Print current version"
|
106
127
|
def version
|
107
128
|
puts KuberKit::VERSION
|
@@ -110,4 +131,16 @@ class KuberKit::CLI < Thor
|
|
110
131
|
def self.exit_on_failure?
|
111
132
|
true
|
112
133
|
end
|
134
|
+
|
135
|
+
private
|
136
|
+
def setup(options)
|
137
|
+
KuberKit.set_debug_mode(options[:debug])
|
138
|
+
|
139
|
+
# We should load config before loading any bean, to make sure that bean won't be built with default config
|
140
|
+
root_path = options[:path] || File.join(Dir.pwd, KuberKit::Container['configs'].kuber_kit_dirname)
|
141
|
+
config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
|
142
|
+
if File.exists?(config_file_path)
|
143
|
+
require config_file_path
|
144
|
+
end
|
145
|
+
end
|
113
146
|
end
|
data/lib/kuber_kit/configs.rb
CHANGED
@@ -5,7 +5,7 @@ class KuberKit::Configs
|
|
5
5
|
:image_dockerfile_name, :image_build_context_dir, :image_tag, :docker_ignore_list, :image_compile_dir,
|
6
6
|
:kuber_kit_dirname, :kuber_kit_min_version, :images_dirname, :services_dirname, :infra_dirname, :configurations_dirname,
|
7
7
|
:artifact_clone_dir, :service_config_dir, :deployer_strategy, :compile_simultaneous_limit,
|
8
|
-
:additional_images_paths, :deprecation_warnings_disabled
|
8
|
+
:additional_images_paths, :deprecation_warnings_disabled, :log_file_path
|
9
9
|
]
|
10
10
|
DOCKER_IGNORE_LIST = [
|
11
11
|
'Dockerfile',
|
@@ -51,6 +51,7 @@ class KuberKit::Configs
|
|
51
51
|
set :compile_simultaneous_limit, 5
|
52
52
|
set :additional_images_paths, []
|
53
53
|
set :deprecation_warnings_disabled, false
|
54
|
+
set :log_file_path, "/tmp/kuber_kit.log"
|
54
55
|
end
|
55
56
|
|
56
57
|
def items
|
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
|
@@ -106,7 +114,7 @@ class KuberKit::Container
|
|
106
114
|
end
|
107
115
|
|
108
116
|
register "tools.logger" do
|
109
|
-
KuberKit::Container["tools.logger_factory"].create(
|
117
|
+
KuberKit::Container["tools.logger_factory"].create()
|
110
118
|
end
|
111
119
|
|
112
120
|
register "shell.bash_commands" do
|
@@ -4,11 +4,11 @@ class KuberKit::Core::Service
|
|
4
4
|
attr_reader :name, :template_name, :tags, :images, :attributes, :deployer_strategy
|
5
5
|
|
6
6
|
Contract KeywordArgs[
|
7
|
-
name:
|
8
|
-
template_name:
|
9
|
-
tags:
|
10
|
-
images:
|
11
|
-
attributes:
|
7
|
+
name: Symbol,
|
8
|
+
template_name: Maybe[Symbol],
|
9
|
+
tags: ArrayOf[Symbol],
|
10
|
+
images: ArrayOf[Symbol],
|
11
|
+
attributes: HashOf[Symbol => Any],
|
12
12
|
deployer_strategy: Maybe[Symbol]
|
13
13
|
] => Any
|
14
14
|
def initialize(name:, template_name:, tags:, images:, attributes:, deployer_strategy:)
|
@@ -1,13 +1,7 @@
|
|
1
1
|
class KuberKit::Core::ServiceFactory
|
2
|
-
AttributeNotSetError = Class.new(KuberKit::Error)
|
3
|
-
|
4
2
|
def create(definition)
|
5
3
|
service_attrs = definition.to_service_attrs
|
6
4
|
|
7
|
-
if service_attrs.template_name.nil?
|
8
|
-
raise AttributeNotSetError, "Please set template for service using #template method"
|
9
|
-
end
|
10
|
-
|
11
5
|
configuration_attributes = KuberKit.current_configuration.service_attributes(service_attrs.name)
|
12
6
|
attributes = (service_attrs.attributes || {}).merge(configuration_attributes)
|
13
7
|
|
@@ -8,8 +8,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
8
8
|
STRATEGY_OPTIONS = [
|
9
9
|
:container_name,
|
10
10
|
:image_name,
|
11
|
-
:
|
12
|
-
:
|
11
|
+
:detached,
|
12
|
+
:command_name,
|
13
|
+
:command_args,
|
13
14
|
:delete_if_exists
|
14
15
|
]
|
15
16
|
|
@@ -21,9 +22,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
21
22
|
raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
|
22
23
|
end
|
23
24
|
|
24
|
-
container_name
|
25
|
-
|
26
|
-
|
25
|
+
container_name = strategy_options.fetch(:container_name, service.uri)
|
26
|
+
command_name = strategy_options.fetch(:command_name, "bash")
|
27
|
+
command_args = strategy_options.fetch(:command_args, nil)
|
27
28
|
|
28
29
|
image_name = strategy_options.fetch(:image_name, nil)
|
29
30
|
if image_name.nil?
|
@@ -36,6 +37,16 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
36
37
|
docker_commands.delete_container(shell, container_name)
|
37
38
|
end
|
38
39
|
|
39
|
-
|
40
|
+
command_args = Array(command_args)
|
41
|
+
if container_name
|
42
|
+
command_args << "-n #{container_name}"
|
43
|
+
end
|
44
|
+
|
45
|
+
docker_commands.run(
|
46
|
+
shell, image.remote_registry_url,
|
47
|
+
command: command_name,
|
48
|
+
args: command_args,
|
49
|
+
detached: !!strategy_options[:detached]
|
50
|
+
)
|
40
51
|
end
|
41
52
|
end
|
@@ -7,7 +7,9 @@ class KuberKit::ServiceDeployer::Strategies::DockerCompose < KuberKit::ServiceDe
|
|
7
7
|
|
8
8
|
STRATEGY_OPTIONS = [
|
9
9
|
:service_name,
|
10
|
-
:command_name
|
10
|
+
:command_name,
|
11
|
+
:command_args,
|
12
|
+
:detached
|
11
13
|
]
|
12
14
|
|
13
15
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
|
@@ -24,10 +26,13 @@ class KuberKit::ServiceDeployer::Strategies::DockerCompose < KuberKit::ServiceDe
|
|
24
26
|
|
25
27
|
service_name = strategy_options.fetch(:service_name, service.name.to_s)
|
26
28
|
command_name = strategy_options.fetch(:command_name, "bash")
|
29
|
+
command_args = strategy_options.fetch(:command_args, nil)
|
27
30
|
|
28
31
|
docker_compose_commands.run(shell, config_path,
|
29
|
-
service:
|
30
|
-
command:
|
32
|
+
service: service_name,
|
33
|
+
command: command_name,
|
34
|
+
args: command_args,
|
35
|
+
detached: !!strategy_options[:detached]
|
31
36
|
)
|
32
37
|
end
|
33
38
|
end
|
@@ -6,8 +6,14 @@ class KuberKit::ServiceReader::Reader
|
|
6
6
|
"preprocessing.text_preprocessor"
|
7
7
|
]
|
8
8
|
|
9
|
+
AttributeNotSetError = Class.new(KuberKit::Error)
|
10
|
+
|
9
11
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
|
10
12
|
def read(shell, service)
|
13
|
+
if service.template_name.nil?
|
14
|
+
raise AttributeNotSetError, "Please set template for service using #template method"
|
15
|
+
end
|
16
|
+
|
11
17
|
template = template_store.get(service.template_name)
|
12
18
|
|
13
19
|
context_helper = context_helper_factory.build_service_context(shell, service)
|
@@ -14,14 +14,19 @@ 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,
|
17
|
+
def run(shell, image_name, args: nil, command: nil, detached: false, interactive: false)
|
18
18
|
command_parts = []
|
19
19
|
command_parts << "docker run"
|
20
|
-
command_parts <<
|
20
|
+
command_parts << "-d" if detached
|
21
|
+
command_parts << Array(args).join(" ") if args
|
21
22
|
command_parts << image_name
|
22
|
-
command_parts <<
|
23
|
+
command_parts << command if command
|
23
24
|
|
24
|
-
|
25
|
+
if interactive
|
26
|
+
shell.interactive!(command_parts.join(" "))
|
27
|
+
else
|
28
|
+
shell.exec!(command_parts.join(" "))
|
29
|
+
end
|
25
30
|
end
|
26
31
|
|
27
32
|
def container_exists?(shell, container_name)
|
@@ -1,13 +1,17 @@
|
|
1
1
|
class KuberKit::Shell::Commands::DockerComposeCommands
|
2
|
-
def run(shell, path, service:, command
|
2
|
+
def run(shell, path, service:, args: nil, command: nil, detached: false, interactive: false)
|
3
3
|
command_parts = [
|
4
4
|
"docker-compose",
|
5
5
|
"-f #{path}",
|
6
6
|
"run",
|
7
|
-
service,
|
8
|
-
command
|
9
7
|
]
|
10
8
|
|
9
|
+
|
10
|
+
command_parts << "-d" if detached
|
11
|
+
command_parts << Array(args).join(" ") if args
|
12
|
+
command_parts << service
|
13
|
+
command_parts << command if command
|
14
|
+
|
11
15
|
if interactive
|
12
16
|
shell.interactive!(command_parts.join(" "))
|
13
17
|
else
|
@@ -40,15 +40,38 @@ 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
|
44
|
-
|
45
|
-
|
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)
|
46
53
|
end
|
47
54
|
|
48
|
-
def
|
49
|
-
|
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}"
|
50
58
|
|
51
|
-
|
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
|
+
|
70
|
+
def resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
71
|
+
result = get_resources(shell, resource_type,
|
72
|
+
field_selector: "metadata.name=#{resource_name}", kubeconfig_path: kubeconfig_path, namespace: namespace
|
73
|
+
)
|
74
|
+
result && result != ""
|
52
75
|
end
|
53
76
|
|
54
77
|
def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
@@ -76,7 +76,7 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
76
76
|
|
77
77
|
def recursive_list_files(path, name: nil)
|
78
78
|
command = %Q{find -L #{path} -type f}
|
79
|
-
command += " -name #{name}" if name
|
79
|
+
command += " -name '#{name}'" if name
|
80
80
|
exec!(command).split(/[\r\n]+/)
|
81
81
|
rescue => e
|
82
82
|
if e.message.include?("No such file or directory")
|
@@ -9,8 +9,12 @@ class KuberKit::Tools::LoggerFactory
|
|
9
9
|
Logger::FATAL => String::Colors::PURPLE,
|
10
10
|
}
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
include KuberKit::Import[
|
13
|
+
"configs",
|
14
|
+
]
|
15
|
+
|
16
|
+
def create(stdout = nil, level = nil)
|
17
|
+
logger = Logger.new(stdout || configs.log_file_path)
|
14
18
|
|
15
19
|
logger.level = level || Logger::DEBUG
|
16
20
|
|
@@ -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.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -145,6 +145,7 @@ executables:
|
|
145
145
|
extensions: []
|
146
146
|
extra_rdoc_files: []
|
147
147
|
files:
|
148
|
+
- ".github/workflows/rspec.yml"
|
148
149
|
- ".gitignore"
|
149
150
|
- ".rspec"
|
150
151
|
- ".ruby-gemset"
|
@@ -191,6 +192,8 @@ files:
|
|
191
192
|
- lib/kuber_kit/actions/image_compiler.rb
|
192
193
|
- lib/kuber_kit/actions/kubectl_applier.rb
|
193
194
|
- lib/kuber_kit/actions/kubectl_attacher.rb
|
195
|
+
- lib/kuber_kit/actions/kubectl_console.rb
|
196
|
+
- lib/kuber_kit/actions/kubectl_logs.rb
|
194
197
|
- lib/kuber_kit/actions/service_deployer.rb
|
195
198
|
- lib/kuber_kit/actions/service_reader.rb
|
196
199
|
- lib/kuber_kit/actions/template_reader.rb
|