kuber_kit 0.2.4 → 0.2.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/TODO.md +6 -5
- data/example/config.rb +3 -0
- data/example/images/ruby_app/Dockerfile +1 -1
- data/example/images/ruby_app/image.rb +3 -0
- data/lib/kuber_kit.rb +17 -3
- data/lib/kuber_kit/actions/configuration_loader.rb +18 -0
- data/lib/kuber_kit/actions/template_reader.rb +3 -6
- data/lib/kuber_kit/configs.rb +62 -32
- data/lib/kuber_kit/container.rb +10 -2
- data/lib/kuber_kit/core/configuration.rb +13 -4
- data/lib/kuber_kit/core/configuration_definition.rb +8 -1
- data/lib/kuber_kit/core/configuration_factory.rb +3 -2
- data/lib/kuber_kit/core/context_helper/base_helper.rb +4 -0
- data/lib/kuber_kit/core/context_helper/context_helper_factory.rb +3 -2
- data/lib/kuber_kit/core/context_helper/context_vars.rb +39 -0
- data/lib/kuber_kit/core/context_helper/image_helper.rb +17 -0
- data/lib/kuber_kit/core/image_definition.rb +4 -4
- data/lib/kuber_kit/env_file_reader/reader.rb +10 -6
- data/lib/kuber_kit/extensions/indocker_compat.rb +4 -0
- data/lib/kuber_kit/image_compiler/compiler.rb +1 -1
- data/lib/kuber_kit/service_deployer/deployer.rb +13 -7
- data/lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb +35 -0
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +11 -0
- data/lib/kuber_kit/template_reader/action_handler.rb +13 -0
- data/lib/kuber_kit/template_reader/reader.rb +13 -9
- data/lib/kuber_kit/template_reader/{abstract_template_reader.rb → strategies/abstract.rb} +1 -1
- data/lib/kuber_kit/template_reader/{artifact_file_reader.rb → strategies/artifact_file.rb} +1 -1
- data/lib/kuber_kit/version.rb +1 -1
- metadata +8 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 050f5ef4e2ef34f21bd8d5d92593717770a82c54c40d929cdce949a9f2735171
|
4
|
+
data.tar.gz: 250684c19fc240e0f243ad3c5688cd170912b26c49559569d12717a0bd1655fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3b80414736ee18eb858e383dde9219468b20953d98bbc61439974683b0a0287758e6a039719783ee6c132b94fa999c1e3f4eb9c6c020939313d29d100dc365c3
|
7
|
+
data.tar.gz: e7a7b01fea7a033bf14755dd597ca85079d51e235855c722c5ca8ddba1b25838d70469c2ae4089aca77b48394e5aca52dbcfdb9ef0706892a61437a3eaf8e7a9
|
data/Gemfile.lock
CHANGED
data/TODO.md
CHANGED
@@ -1,9 +1,10 @@
|
|
1
|
-
-
|
1
|
+
- 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
|
+
- add kit logs support, should work similar to kit attach
|
4
|
+
- allow deploying only services enabled for specific configuration
|
5
|
+
- find a way to always deploy some service, e.g. for migrations and env_files
|
2
6
|
- allow setting default configuration for kuberkit using env variable
|
3
|
-
- add ability to set container health
|
7
|
+
- add ability to set container health checks
|
4
8
|
- implement interactive shell.exec!
|
5
|
-
- allow deploying only services enabled for specific configuration
|
6
|
-
- list services and require confirmation before deployment
|
7
|
-
- add build vars support (use images instead of containers)
|
8
9
|
- template should be able to set default attributes
|
9
10
|
- template should be able to depend on image?
|
data/example/config.rb
ADDED
@@ -2,6 +2,9 @@ KuberKit
|
|
2
2
|
.define_image(:ruby_app)
|
3
3
|
.registry(:default)
|
4
4
|
.depends_on(:ruby, :app_sources)
|
5
|
+
.build_vars({
|
6
|
+
example_file_name: "example.txt"
|
7
|
+
})
|
5
8
|
.before_build do |context_helper, build_dir|
|
6
9
|
# copy file: local artifact
|
7
10
|
source_path = context_helper.artifact_path(:kuber_kit_example_data, "test.txt")
|
data/lib/kuber_kit.rb
CHANGED
@@ -57,6 +57,7 @@ module KuberKit
|
|
57
57
|
autoload :ImageHelper, 'core/context_helper/image_helper'
|
58
58
|
autoload :ServiceHelper, 'core/context_helper/service_helper'
|
59
59
|
autoload :ContextHelperFactory, 'core/context_helper/context_helper_factory'
|
60
|
+
autoload :ContextVars, 'core/context_helper/context_vars'
|
60
61
|
end
|
61
62
|
|
62
63
|
module Registries
|
@@ -127,9 +128,13 @@ module KuberKit
|
|
127
128
|
end
|
128
129
|
|
129
130
|
module TemplateReader
|
131
|
+
autoload :ActionHandler, 'template_reader/action_handler'
|
130
132
|
autoload :Reader, 'template_reader/reader'
|
131
|
-
|
132
|
-
|
133
|
+
|
134
|
+
module Strategies
|
135
|
+
autoload :Abstract, 'template_reader/strategies/abstract'
|
136
|
+
autoload :ArtifactFile, 'template_reader/strategies/artifact_file'
|
137
|
+
end
|
133
138
|
end
|
134
139
|
|
135
140
|
module ServiceDeployer
|
@@ -141,6 +146,7 @@ module KuberKit
|
|
141
146
|
module Strategies
|
142
147
|
autoload :Abstract, 'service_deployer/strategies/abstract'
|
143
148
|
autoload :Kubernetes, 'service_deployer/strategies/kubernetes'
|
149
|
+
autoload :KubernetesRunner, 'service_deployer/strategies/kubernetes_runner'
|
144
150
|
end
|
145
151
|
end
|
146
152
|
|
@@ -169,9 +175,9 @@ module KuberKit
|
|
169
175
|
autoload :Simple, 'ui/simple'
|
170
176
|
end
|
171
177
|
|
172
|
-
autoload :Configs, 'configs'
|
173
178
|
autoload :CLI, 'cli'
|
174
179
|
autoload :Container, 'container'
|
180
|
+
autoload :Configs, 'configs'
|
175
181
|
|
176
182
|
Import = Dry::AutoInject(Container)
|
177
183
|
|
@@ -210,6 +216,10 @@ module KuberKit
|
|
210
216
|
@current_configuration ||= Container['core.configuration_store'].get_configuration(@configuration_name)
|
211
217
|
end
|
212
218
|
|
219
|
+
def global_build_vars
|
220
|
+
KuberKit::Core::ContextHelper::ContextVars.new(current_configuration.global_build_vars)
|
221
|
+
end
|
222
|
+
|
213
223
|
def add_registry(registry)
|
214
224
|
Container["core.registry_store"].add(registry)
|
215
225
|
end
|
@@ -233,6 +243,10 @@ module KuberKit
|
|
233
243
|
def build_helper(&proc)
|
234
244
|
KuberKit::Core::ContextHelper::BaseHelper.class_exec(&proc)
|
235
245
|
end
|
246
|
+
|
247
|
+
def configure(&proc)
|
248
|
+
yield(Container["configs"])
|
249
|
+
end
|
236
250
|
end
|
237
251
|
end
|
238
252
|
|
@@ -1,4 +1,6 @@
|
|
1
1
|
class KuberKit::Actions::ConfigurationLoader
|
2
|
+
APP_CONFIG_FILENAME = "config.rb".freeze
|
3
|
+
|
2
4
|
include KuberKit::Import[
|
3
5
|
"core.registry_store",
|
4
6
|
"core.image_store",
|
@@ -14,6 +16,13 @@ class KuberKit::Actions::ConfigurationLoader
|
|
14
16
|
Contract Hash => Any
|
15
17
|
def call(options)
|
16
18
|
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
|
+
|
17
26
|
images_path = options[:images_path] || File.join(root_path, configs.images_dirname)
|
18
27
|
services_path = options[:services_path] || File.join(root_path, configs.services_dirname)
|
19
28
|
infra_path = options[:infra_path] || File.join(root_path, configs.infra_dirname)
|
@@ -32,6 +41,10 @@ class KuberKit::Actions::ConfigurationLoader
|
|
32
41
|
ui.print_warning "WARNING", "KuberKit root path #{root_path} doesn't exist. You may want to pass it --path parameter."
|
33
42
|
end
|
34
43
|
|
44
|
+
if Gem::Version.new(KuberKit::VERSION) < Gem::Version.new(configs.kuber_kit_min_version)
|
45
|
+
raise KuberKit::Error, "The minimal required kuber_kit version is #{configs.kuber_kit_min_version}"
|
46
|
+
end
|
47
|
+
|
35
48
|
load_configurations(configurations_path, configuration_name)
|
36
49
|
load_infrastructure(infra_path)
|
37
50
|
|
@@ -43,6 +56,11 @@ class KuberKit::Actions::ConfigurationLoader
|
|
43
56
|
|
44
57
|
ui.create_task("Loading image definitions") do |task|
|
45
58
|
files = image_store.load_definitions(images_path)
|
59
|
+
|
60
|
+
configs.additional_images_paths.each do |path|
|
61
|
+
files += image_store.load_definitions(path)
|
62
|
+
end
|
63
|
+
|
46
64
|
task.update_title("Loaded #{files.count} image definitions")
|
47
65
|
end
|
48
66
|
|
@@ -1,16 +1,13 @@
|
|
1
1
|
class KuberKit::Actions::TemplateReader
|
2
2
|
include KuberKit::Import[
|
3
|
-
"core.template_store",
|
4
|
-
"template_reader.reader",
|
5
3
|
"shell.local_shell",
|
6
|
-
"ui"
|
4
|
+
"ui",
|
5
|
+
template_reader: "template_reader.action_handler",
|
7
6
|
]
|
8
7
|
|
9
8
|
Contract Symbol, Hash => Any
|
10
9
|
def call(template_name, options)
|
11
|
-
|
12
|
-
|
13
|
-
result = reader.read(local_shell, template)
|
10
|
+
result = template_reader.call(local_shell, template_name)
|
14
11
|
|
15
12
|
ui.print_info(template_name.to_s, result)
|
16
13
|
|
data/lib/kuber_kit/configs.rb
CHANGED
@@ -1,8 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class KuberKit::Configs
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
4
|
+
AVAILABLE_CONFIGS = [
|
5
|
+
:image_dockerfile_name, :image_build_context_dir, :image_tag, :docker_ignore_list, :image_compile_dir,
|
6
|
+
:kuber_kit_dirname, :kuber_kit_min_version, :images_dirname, :services_dirname, :infra_dirname, :configurations_dirname,
|
7
|
+
:artifact_clone_dir, :service_config_dir, :deploy_strategy, :compile_simultaneous_limit,
|
8
|
+
:additional_images_paths
|
9
|
+
]
|
6
10
|
DOCKER_IGNORE_LIST = [
|
7
11
|
'Dockerfile',
|
8
12
|
'.DS_Store',
|
@@ -14,35 +18,61 @@ class KuberKit::Configs
|
|
14
18
|
'tmp',
|
15
19
|
'logs'
|
16
20
|
]
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
attr_accessor :image_dockerfile_name, :image_build_context_dir, :image_tag,
|
28
|
-
:docker_ignore_list, :image_compile_dir,
|
29
|
-
:kuber_kit_dirname, :images_dirname, :services_dirname, :infra_dirname, :configurations_dirname,
|
30
|
-
:artifact_clone_dir, :service_config_dir, :deploy_strategy, :compile_simultaneous_limit
|
21
|
+
|
22
|
+
AVAILABLE_CONFIGS.each do |config_name|
|
23
|
+
define_method(config_name) do
|
24
|
+
get(config_name.to_sym)
|
25
|
+
end
|
26
|
+
|
27
|
+
define_method(:"#{config_name}=") do |value|
|
28
|
+
set(config_name.to_sym, value)
|
29
|
+
end
|
30
|
+
end
|
31
31
|
|
32
32
|
def initialize
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
33
|
+
add_default_configs unless items.any?
|
34
|
+
end
|
35
|
+
|
36
|
+
def add_default_configs
|
37
|
+
set :image_dockerfile_name, "Dockerfile"
|
38
|
+
set :image_build_context_dir, "build_context"
|
39
|
+
set :image_tag, 'latest'
|
40
|
+
set :image_compile_dir, "/tmp/kuber_kit/image_builds"
|
41
|
+
set :docker_ignore_list, DOCKER_IGNORE_LIST
|
42
|
+
set :kuber_kit_dirname, "kuber_kit"
|
43
|
+
set :kuber_kit_min_version, KuberKit::VERSION
|
44
|
+
set :images_dirname, "images"
|
45
|
+
set :services_dirname, "services"
|
46
|
+
set :infra_dirname, "infrastructure"
|
47
|
+
set :configurations_dirname, "configurations"
|
48
|
+
set :artifact_clone_dir, "/tmp/kuber_kit/artifacts"
|
49
|
+
set :service_config_dir, "/tmp/kuber_kit/services"
|
50
|
+
set :deploy_strategy, :kubernetes
|
51
|
+
set :compile_simultaneous_limit, 5
|
52
|
+
set :additional_images_paths, []
|
53
|
+
end
|
54
|
+
|
55
|
+
def items
|
56
|
+
@@items ||= {}
|
57
|
+
end
|
58
|
+
|
59
|
+
def set(key, value)
|
60
|
+
unless AVAILABLE_CONFIGS.include?(key)
|
61
|
+
raise ArgumentError, "#{key} is not a valid configuration key"
|
62
|
+
end
|
63
|
+
|
64
|
+
items[key] = value
|
65
|
+
end
|
66
|
+
|
67
|
+
def get(key)
|
68
|
+
unless AVAILABLE_CONFIGS.include?(key)
|
69
|
+
raise ArgumentError, "#{key} is not a valid configuration key"
|
70
|
+
end
|
71
|
+
|
72
|
+
items[key]
|
73
|
+
end
|
74
|
+
|
75
|
+
def reset!
|
76
|
+
@@items = {}
|
47
77
|
end
|
48
78
|
end
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -197,12 +197,16 @@ class KuberKit::Container
|
|
197
197
|
KuberKit::EnvFileReader::Strategies::ArtifactFile.new
|
198
198
|
end
|
199
199
|
|
200
|
+
register "template_reader.action_handler" do
|
201
|
+
KuberKit::TemplateReader::ActionHandler.new
|
202
|
+
end
|
203
|
+
|
200
204
|
register "template_reader.reader" do
|
201
205
|
KuberKit::TemplateReader::Reader.new
|
202
206
|
end
|
203
207
|
|
204
|
-
register "template_reader.
|
205
|
-
KuberKit::TemplateReader::
|
208
|
+
register "template_reader.strategies.artifact_file" do
|
209
|
+
KuberKit::TemplateReader::Strategies::ArtifactFile.new
|
206
210
|
end
|
207
211
|
|
208
212
|
register "service_deployer.action_handler" do
|
@@ -225,6 +229,10 @@ class KuberKit::Container
|
|
225
229
|
KuberKit::ServiceDeployer::Strategies::Kubernetes.new
|
226
230
|
end
|
227
231
|
|
232
|
+
register "service_deployer.strategies.kubernetes_runner" do
|
233
|
+
KuberKit::ServiceDeployer::Strategies::KubernetesRunner.new
|
234
|
+
end
|
235
|
+
|
228
236
|
register "service_reader.action_handler" do
|
229
237
|
KuberKit::ServiceReader::ActionHandler.new
|
230
238
|
end
|
@@ -1,6 +1,7 @@
|
|
1
1
|
class KuberKit::Core::Configuration
|
2
2
|
attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path,
|
3
|
-
:deploy_strategy, :deploy_namespace, :services_attributes, :build_servers
|
3
|
+
:deploy_strategy, :deploy_namespace, :services_attributes, :build_servers,
|
4
|
+
:global_build_vars
|
4
5
|
|
5
6
|
Contract KeywordArgs[
|
6
7
|
name: Symbol,
|
@@ -12,10 +13,12 @@ class KuberKit::Core::Configuration
|
|
12
13
|
deploy_strategy: Symbol,
|
13
14
|
deploy_namespace: Maybe[Symbol],
|
14
15
|
services_attributes: HashOf[Symbol => Hash],
|
15
|
-
build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer]
|
16
|
+
build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer],
|
17
|
+
global_build_vars: HashOf[Symbol => Any],
|
16
18
|
] => Any
|
17
19
|
def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:,
|
18
|
-
deploy_strategy:, deploy_namespace:, services_attributes:, build_servers
|
20
|
+
deploy_strategy:, deploy_namespace:, services_attributes:, build_servers:,
|
21
|
+
global_build_vars:)
|
19
22
|
@name = name
|
20
23
|
@artifacts = artifacts
|
21
24
|
@registries = registries
|
@@ -24,11 +27,17 @@ class KuberKit::Core::Configuration
|
|
24
27
|
@kubeconfig_path = kubeconfig_path
|
25
28
|
@deploy_strategy = deploy_strategy
|
26
29
|
@deploy_namespace = deploy_namespace
|
27
|
-
@services_attributes = services_attributes
|
28
30
|
@build_servers = build_servers
|
31
|
+
@services_attributes = services_attributes
|
32
|
+
@global_build_vars = global_build_vars
|
29
33
|
end
|
30
34
|
|
31
35
|
def service_attributes(service_name)
|
32
36
|
services_attributes[service_name.to_sym] || {}
|
33
37
|
end
|
38
|
+
|
39
|
+
def global_build_args
|
40
|
+
puts "WARNING: global_build_args is deprecated, please use global_build_vars instead"
|
41
|
+
global_build_vars
|
42
|
+
end
|
34
43
|
end
|
@@ -27,7 +27,8 @@ class KuberKit::Core::ConfigurationDefinition
|
|
27
27
|
deploy_namespace: @deploy_namespace,
|
28
28
|
enabled_services: @enabled_services,
|
29
29
|
build_servers: @build_servers,
|
30
|
-
services_attributes:
|
30
|
+
services_attributes: @services_attributes,
|
31
|
+
global_build_vars: @global_build_vars,
|
31
32
|
)
|
32
33
|
end
|
33
34
|
|
@@ -99,4 +100,10 @@ class KuberKit::Core::ConfigurationDefinition
|
|
99
100
|
|
100
101
|
self
|
101
102
|
end
|
103
|
+
|
104
|
+
def global_build_vars(variables)
|
105
|
+
@global_build_vars = variables
|
106
|
+
|
107
|
+
self
|
108
|
+
end
|
102
109
|
end
|
@@ -28,8 +28,9 @@ class KuberKit::Core::ConfigurationFactory
|
|
28
28
|
kubeconfig_path: configuration_attrs.kubeconfig_path,
|
29
29
|
deploy_strategy: configuration_attrs.deploy_strategy || configs.deploy_strategy,
|
30
30
|
deploy_namespace: configuration_attrs.deploy_namespace,
|
31
|
-
|
32
|
-
|
31
|
+
build_servers: build_servers,
|
32
|
+
services_attributes: configuration_attrs.services_attributes,
|
33
|
+
global_build_vars: configuration_attrs.global_build_vars || {},
|
33
34
|
)
|
34
35
|
end
|
35
36
|
|
@@ -5,12 +5,13 @@ class KuberKit::Core::ContextHelper::ContextHelperFactory
|
|
5
5
|
env_file_reader: "env_file_reader.action_handler"
|
6
6
|
]
|
7
7
|
|
8
|
-
def build_image_context(shell)
|
8
|
+
def build_image_context(shell, image)
|
9
9
|
KuberKit::Core::ContextHelper::ImageHelper.new(
|
10
10
|
image_store: image_store,
|
11
11
|
artifact_store: artifact_store,
|
12
12
|
shell: shell,
|
13
|
-
env_file_reader: env_file_reader
|
13
|
+
env_file_reader: env_file_reader,
|
14
|
+
image: image
|
14
15
|
)
|
15
16
|
end
|
16
17
|
|
@@ -0,0 +1,39 @@
|
|
1
|
+
class KuberKit::Core::ContextHelper::ContextVars
|
2
|
+
attr_reader :parent, :parent_name
|
3
|
+
|
4
|
+
def initialize(context_vars, parent_name = nil, parent = nil)
|
5
|
+
@context_vars = context_vars
|
6
|
+
@parent_name = parent_name
|
7
|
+
@parent = parent
|
8
|
+
end
|
9
|
+
|
10
|
+
def method_missing(name, *args)
|
11
|
+
if args.size > 0
|
12
|
+
raise ArgumentError.new("context args does not accept any arguments")
|
13
|
+
end
|
14
|
+
|
15
|
+
value = @context_vars.fetch(name) do
|
16
|
+
raise(KuberKit::Error, "build arg '#{format_arg(name)}' is not defined, available args: #{@context_vars.inspect}")
|
17
|
+
end
|
18
|
+
|
19
|
+
if value.is_a?(Hash)
|
20
|
+
return self.class.new(value, name, self)
|
21
|
+
end
|
22
|
+
|
23
|
+
value
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def format_arg(name)
|
29
|
+
string = [@parent_name, name].compact.join(".")
|
30
|
+
parent = @parent
|
31
|
+
|
32
|
+
while parent do
|
33
|
+
string = [parent.parent_name, string].compact.join(".")
|
34
|
+
parent = parent.parent
|
35
|
+
end
|
36
|
+
|
37
|
+
string
|
38
|
+
end
|
39
|
+
end
|
@@ -1,2 +1,19 @@
|
|
1
1
|
class KuberKit::Core::ContextHelper::ImageHelper < KuberKit::Core::ContextHelper::BaseHelper
|
2
|
+
def initialize(image_store:, artifact_store:, shell:, env_file_reader:, image:)
|
3
|
+
super(
|
4
|
+
image_store: image_store,
|
5
|
+
artifact_store: artifact_store,
|
6
|
+
shell: shell,
|
7
|
+
env_file_reader: env_file_reader
|
8
|
+
)
|
9
|
+
@image = image
|
10
|
+
end
|
11
|
+
|
12
|
+
def image_name
|
13
|
+
@image.name.to_s
|
14
|
+
end
|
15
|
+
|
16
|
+
def build_vars
|
17
|
+
KuberKit::Core::ContextHelper::ContextVars.new(@image.build_vars)
|
18
|
+
end
|
2
19
|
end
|
@@ -66,14 +66,14 @@ class KuberKit::Core::ImageDefinition
|
|
66
66
|
self
|
67
67
|
end
|
68
68
|
|
69
|
-
def before_build(&block)
|
70
|
-
@before_build_callback = block
|
69
|
+
def before_build(lambda_arg = nil, &block)
|
70
|
+
@before_build_callback = lambda_arg || block
|
71
71
|
|
72
72
|
self
|
73
73
|
end
|
74
74
|
|
75
|
-
def after_build(&block)
|
76
|
-
@after_build_callback = block
|
75
|
+
def after_build(lambda_arg = nil, &block)
|
76
|
+
@after_build_callback = lambda_arg || block
|
77
77
|
|
78
78
|
self
|
79
79
|
end
|
@@ -5,6 +5,11 @@ class KuberKit::EnvFileReader::Reader
|
|
5
5
|
"env_file_reader.strategies.artifact_file",
|
6
6
|
]
|
7
7
|
|
8
|
+
def initialize(**injected_deps)
|
9
|
+
super(injected_deps)
|
10
|
+
add_default_strategies
|
11
|
+
end
|
12
|
+
|
8
13
|
def use_reader(env_file_reader, env_file_class:)
|
9
14
|
@@readers ||= {}
|
10
15
|
|
@@ -16,8 +21,6 @@ class KuberKit::EnvFileReader::Reader
|
|
16
21
|
end
|
17
22
|
|
18
23
|
def read(shell, env_file)
|
19
|
-
add_default_readers
|
20
|
-
|
21
24
|
reader = @@readers[env_file.class]
|
22
25
|
|
23
26
|
raise ReaderNotFoundError, "Can't find reader for env file #{env_file}" if reader.nil?
|
@@ -25,11 +28,12 @@ class KuberKit::EnvFileReader::Reader
|
|
25
28
|
reader.read(shell, env_file)
|
26
29
|
end
|
27
30
|
|
28
|
-
def add_default_readers
|
29
|
-
use_reader(artifact_file, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
|
30
|
-
end
|
31
|
-
|
32
31
|
def reset!
|
33
32
|
@@readers = {}
|
34
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def add_default_strategies
|
37
|
+
use_reader(artifact_file, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
|
38
|
+
end
|
35
39
|
end
|
@@ -9,7 +9,7 @@ class KuberKit::ImageCompiler::Compiler
|
|
9
9
|
def compile(shell, image, builds_dir)
|
10
10
|
image_build_dir = File.join(builds_dir, image.name.to_s)
|
11
11
|
|
12
|
-
context_helper = context_helper_factory.build_image_context(shell)
|
12
|
+
context_helper = context_helper_factory.build_image_context(shell, image)
|
13
13
|
image_build_dir_creator.create(shell, image, image_build_dir, context_helper: context_helper)
|
14
14
|
|
15
15
|
image_builder.build(shell, image, image_build_dir, context_helper: context_helper)
|
@@ -3,9 +3,15 @@ class KuberKit::ServiceDeployer::Deployer
|
|
3
3
|
|
4
4
|
include KuberKit::Import[
|
5
5
|
"core.service_store",
|
6
|
-
"service_deployer.strategies.kubernetes"
|
6
|
+
"service_deployer.strategies.kubernetes",
|
7
|
+
"service_deployer.strategies.kubernetes_runner"
|
7
8
|
]
|
8
9
|
|
10
|
+
def initialize(**injected_deps)
|
11
|
+
super(injected_deps)
|
12
|
+
add_default_strategies
|
13
|
+
end
|
14
|
+
|
9
15
|
def register_strategy(strategy_name, strategy)
|
10
16
|
@@strategies ||= {}
|
11
17
|
|
@@ -18,8 +24,6 @@ class KuberKit::ServiceDeployer::Deployer
|
|
18
24
|
|
19
25
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, Symbol => Any
|
20
26
|
def deploy(shell, service, strategy_name)
|
21
|
-
add_default_strategies
|
22
|
-
|
23
27
|
deployer = @@strategies[strategy_name]
|
24
28
|
|
25
29
|
raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if deployer.nil?
|
@@ -27,11 +31,13 @@ class KuberKit::ServiceDeployer::Deployer
|
|
27
31
|
deployer.deploy(shell, service)
|
28
32
|
end
|
29
33
|
|
30
|
-
def add_default_strategies
|
31
|
-
register_strategy(:kubernetes, kubernetes)
|
32
|
-
end
|
33
|
-
|
34
34
|
def reset!
|
35
35
|
@@strategies = {}
|
36
36
|
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def add_default_strategies
|
40
|
+
register_strategy(:kubernetes, kubernetes)
|
41
|
+
register_strategy(:kubernetes_runner, kubernetes_runner)
|
42
|
+
end
|
37
43
|
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
deploy_namespace = KuberKit.current_configuration.deploy_namespace
|
16
|
+
|
17
|
+
deployment_resource_name = service.attribute(:deployment_resource_name, default: service.uri)
|
18
|
+
deployment_resource_type = service.attribute(:deployment_resource_type, default: "job")
|
19
|
+
|
20
|
+
deployment_delete_enabled = service.attribute(:deployment_delete_enabled, default: true)
|
21
|
+
if deployment_delete_enabled
|
22
|
+
delete_resource_if_exists(shell, deployment_resource_type, deployment_resource_name, kubeconfig_path: kubeconfig_path, namespace: deploy_namespace)
|
23
|
+
end
|
24
|
+
|
25
|
+
kubectl_commands.apply_file(shell, config_path, kubeconfig_path: kubeconfig_path, namespace: deploy_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
|
@@ -41,6 +41,17 @@ class KuberKit::Shell::Commands::KubectlCommands
|
|
41
41
|
kubectl_run(shell, command_parts, kubeconfig_path: kubeconfig_path, interactive: interactive, namespace: namespace)
|
42
42
|
end
|
43
43
|
|
44
|
+
def resource_exists?(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
45
|
+
result = find_resources(shell, resource_type, resource_name, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
46
|
+
result && result != ""
|
47
|
+
end
|
48
|
+
|
49
|
+
def find_resources(shell, resource_type, resource_name, jsonpath: ".items[*].metadata.name", kubeconfig_path: nil, namespace: nil)
|
50
|
+
command = %Q{get #{resource_type} --field-selector=metadata.name=#{resource_name} -o jsonpath='{#{jsonpath}}'}
|
51
|
+
|
52
|
+
kubectl_run(shell, command, kubeconfig_path: kubeconfig_path, namespace: namespace)
|
53
|
+
end
|
54
|
+
|
44
55
|
def delete_resource(shell, resource_type, resource_name, kubeconfig_path: nil, namespace: nil)
|
45
56
|
command = %Q{delete #{resource_type} #{resource_name}}
|
46
57
|
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class KuberKit::TemplateReader::ActionHandler
|
2
|
+
include KuberKit::Import[
|
3
|
+
"template_reader.reader",
|
4
|
+
"core.template_store",
|
5
|
+
]
|
6
|
+
|
7
|
+
Contract KuberKit::Shell::AbstractShell, Symbol => Any
|
8
|
+
def call(shell, template_name)
|
9
|
+
template = template_store.get(template_name)
|
10
|
+
|
11
|
+
reader.read(shell, template)
|
12
|
+
end
|
13
|
+
end
|
@@ -2,22 +2,25 @@ class KuberKit::TemplateReader::Reader
|
|
2
2
|
ReaderNotFoundError = Class.new(KuberKit::NotFoundError)
|
3
3
|
|
4
4
|
include KuberKit::Import[
|
5
|
-
"template_reader.
|
5
|
+
"template_reader.strategies.artifact_file",
|
6
6
|
]
|
7
7
|
|
8
|
+
def initialize(**injected_deps)
|
9
|
+
super(injected_deps)
|
10
|
+
add_default_strategies
|
11
|
+
end
|
12
|
+
|
8
13
|
def use_reader(template_reader, template_class:)
|
9
14
|
@@readers ||= {}
|
10
15
|
|
11
|
-
if !template_reader.is_a?(KuberKit::TemplateReader::
|
12
|
-
raise ArgumentError.new("should be an instance of KuberKit::TemplateReader::
|
16
|
+
if !template_reader.is_a?(KuberKit::TemplateReader::Strategies::Abstract)
|
17
|
+
raise ArgumentError.new("should be an instance of KuberKit::TemplateReader::Strategies::Abstract, got: #{template_reader.inspect}")
|
13
18
|
end
|
14
19
|
|
15
20
|
@@readers[template_class] = template_reader
|
16
21
|
end
|
17
22
|
|
18
23
|
def read(shell, template)
|
19
|
-
add_default_readers
|
20
|
-
|
21
24
|
reader = @@readers[template.class]
|
22
25
|
|
23
26
|
raise ReaderNotFoundError, "Can't find reader for template #{template}" if reader.nil?
|
@@ -25,11 +28,12 @@ class KuberKit::TemplateReader::Reader
|
|
25
28
|
reader.read(shell, template)
|
26
29
|
end
|
27
30
|
|
28
|
-
def add_default_readers
|
29
|
-
use_reader(artifact_file_reader, template_class: KuberKit::Core::Templates::ArtifactFile)
|
30
|
-
end
|
31
|
-
|
32
31
|
def reset!
|
33
32
|
@@readers = {}
|
34
33
|
end
|
34
|
+
|
35
|
+
private
|
36
|
+
def add_default_strategies
|
37
|
+
use_reader(artifact_file, template_class: KuberKit::Core::Templates::ArtifactFile)
|
38
|
+
end
|
35
39
|
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.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Iskander Khaziev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -162,6 +162,7 @@ files:
|
|
162
162
|
- example/app_data/service.yml
|
163
163
|
- example/app_data/test.env
|
164
164
|
- example/app_data/test.txt
|
165
|
+
- example/config.rb
|
165
166
|
- example/configurations/review.rb
|
166
167
|
- example/images/app_sources/Dockerfile
|
167
168
|
- example/images/app_sources/build_context/source.rb
|
@@ -212,6 +213,7 @@ files:
|
|
212
213
|
- lib/kuber_kit/core/configuration_store.rb
|
213
214
|
- lib/kuber_kit/core/context_helper/base_helper.rb
|
214
215
|
- lib/kuber_kit/core/context_helper/context_helper_factory.rb
|
216
|
+
- lib/kuber_kit/core/context_helper/context_vars.rb
|
215
217
|
- lib/kuber_kit/core/context_helper/image_helper.rb
|
216
218
|
- lib/kuber_kit/core/context_helper/service_helper.rb
|
217
219
|
- lib/kuber_kit/core/env_files/abstract_env_file.rb
|
@@ -257,6 +259,7 @@ files:
|
|
257
259
|
- lib/kuber_kit/service_deployer/service_list_resolver.rb
|
258
260
|
- lib/kuber_kit/service_deployer/strategies/abstract.rb
|
259
261
|
- lib/kuber_kit/service_deployer/strategies/kubernetes.rb
|
262
|
+
- lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb
|
260
263
|
- lib/kuber_kit/service_deployer/strategy_detector.rb
|
261
264
|
- lib/kuber_kit/service_reader/action_handler.rb
|
262
265
|
- lib/kuber_kit/service_reader/reader.rb
|
@@ -270,9 +273,10 @@ files:
|
|
270
273
|
- lib/kuber_kit/shell/local_shell.rb
|
271
274
|
- lib/kuber_kit/shell/ssh_session.rb
|
272
275
|
- lib/kuber_kit/shell/ssh_shell.rb
|
273
|
-
- lib/kuber_kit/template_reader/
|
274
|
-
- lib/kuber_kit/template_reader/artifact_file_reader.rb
|
276
|
+
- lib/kuber_kit/template_reader/action_handler.rb
|
275
277
|
- lib/kuber_kit/template_reader/reader.rb
|
278
|
+
- lib/kuber_kit/template_reader/strategies/abstract.rb
|
279
|
+
- lib/kuber_kit/template_reader/strategies/artifact_file.rb
|
276
280
|
- lib/kuber_kit/tools/file_presence_checker.rb
|
277
281
|
- lib/kuber_kit/tools/logger_factory.rb
|
278
282
|
- lib/kuber_kit/ui.rb
|