kuber_kit 0.2.7 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +15 -13
- data/TODO.md +5 -7
- data/example/app_data/docker_compose.yml +6 -0
- data/example/config.rb +3 -0
- data/example/configurations/review.rb +1 -1
- data/example/images/ruby_app/Dockerfile +1 -1
- data/example/images/ruby_app/image.rb +3 -0
- data/example/infrastructure/build_servers.rb +5 -5
- data/example/infrastructure/templates.rb +5 -0
- data/example/services/compose_app.rb +10 -0
- data/example/services/env_file.rb +1 -1
- data/lib/kuber_kit.rb +22 -3
- data/lib/kuber_kit/actions/configuration_loader.rb +19 -1
- data/lib/kuber_kit/actions/kubectl_applier.rb +2 -2
- data/lib/kuber_kit/actions/kubectl_attacher.rb +2 -2
- data/lib/kuber_kit/actions/template_reader.rb +3 -6
- data/lib/kuber_kit/configs.rb +63 -32
- data/lib/kuber_kit/container.rb +14 -2
- data/lib/kuber_kit/core/configuration.rb +19 -8
- data/lib/kuber_kit/core/configuration_definition.rb +30 -10
- data/lib/kuber_kit/core/configuration_factory.rb +11 -10
- 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.rb +3 -1
- data/lib/kuber_kit/core/image_definition.rb +7 -5
- data/lib/kuber_kit/core/service.rb +4 -4
- data/lib/kuber_kit/core/service_definition.rb +3 -3
- data/lib/kuber_kit/core/service_factory.rb +6 -6
- 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 +14 -8
- data/lib/kuber_kit/service_deployer/strategies/docker_compose.rb +24 -0
- data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +6 -6
- data/lib/kuber_kit/service_deployer/strategies/kubernetes_runner.rb +7 -7
- data/lib/kuber_kit/service_deployer/strategy_detector.rb +1 -1
- data/lib/kuber_kit/shell/abstract_shell.rb +4 -0
- data/lib/kuber_kit/shell/commands/docker_commands.rb +14 -0
- data/lib/kuber_kit/shell/commands/docker_compose_commands.rb +17 -0
- data/lib/kuber_kit/shell/commands/kubectl_commands.rb +5 -6
- data/lib/kuber_kit/shell/local_shell.rb +14 -0
- data/lib/kuber_kit/shell/ssh_shell.rb +4 -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 +11 -4
@@ -1,6 +1,7 @@
|
|
1
1
|
class KuberKit::Core::Configuration
|
2
2
|
attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path,
|
3
|
-
:
|
3
|
+
:deployer_strategy, :deployer_namespace, :services_attributes, :build_servers,
|
4
|
+
:global_build_vars
|
4
5
|
|
5
6
|
Contract KeywordArgs[
|
6
7
|
name: Symbol,
|
@@ -9,26 +10,36 @@ class KuberKit::Core::Configuration
|
|
9
10
|
env_files: Hash,
|
10
11
|
templates: Hash,
|
11
12
|
kubeconfig_path: Maybe[String],
|
12
|
-
|
13
|
-
|
13
|
+
deployer_strategy: Symbol,
|
14
|
+
deployer_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
|
-
|
20
|
+
deployer_strategy:, deployer_namespace:, services_attributes:, build_servers:,
|
21
|
+
global_build_vars:)
|
19
22
|
@name = name
|
20
23
|
@artifacts = artifacts
|
21
24
|
@registries = registries
|
22
25
|
@env_files = env_files
|
23
26
|
@templates = templates
|
24
27
|
@kubeconfig_path = kubeconfig_path
|
25
|
-
@
|
26
|
-
@
|
27
|
-
@services_attributes = services_attributes
|
28
|
+
@deployer_strategy = deployer_strategy
|
29
|
+
@deployer_namespace = deployer_namespace
|
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
|
+
unless KuberKit.deprecation_warnings_disabled?
|
41
|
+
puts "DEPRECATION: global_build_args is deprecated, please use global_build_vars instead"
|
42
|
+
end
|
43
|
+
global_build_vars
|
44
|
+
end
|
34
45
|
end
|
@@ -23,11 +23,12 @@ class KuberKit::Core::ConfigurationDefinition
|
|
23
23
|
env_files: @env_files,
|
24
24
|
templates: @templates,
|
25
25
|
kubeconfig_path: @kubeconfig_path,
|
26
|
-
|
27
|
-
|
26
|
+
deployer_strategy: @deployer_strategy,
|
27
|
+
deployer_namespace: @deployer_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
|
|
@@ -81,21 +82,40 @@ class KuberKit::Core::ConfigurationDefinition
|
|
81
82
|
self
|
82
83
|
end
|
83
84
|
|
84
|
-
def
|
85
|
-
@
|
85
|
+
def deployer_namespace(namespace)
|
86
|
+
@deployer_namespace = namespace
|
86
87
|
|
87
88
|
self
|
88
89
|
end
|
89
90
|
|
90
|
-
def
|
91
|
-
@
|
91
|
+
def deployer_strategy(path)
|
92
|
+
@deployer_strategy = path
|
92
93
|
|
93
94
|
self
|
94
95
|
end
|
95
96
|
|
96
|
-
def enabled_services(
|
97
|
-
|
98
|
-
|
97
|
+
def enabled_services(services)
|
98
|
+
if services.is_a?(Hash)
|
99
|
+
@enabled_services += services.keys.map(&:to_sym)
|
100
|
+
@services_attributes = @services_attributes.merge(services)
|
101
|
+
return self
|
102
|
+
end
|
103
|
+
|
104
|
+
if services.is_a?(Array)
|
105
|
+
@enabled_services += services.map(&:to_sym)
|
106
|
+
return self
|
107
|
+
end
|
108
|
+
|
109
|
+
raise KuberKit::Error, "#enabled_services method accepts only Array or Hash"
|
110
|
+
end
|
111
|
+
|
112
|
+
def service_attributes(services)
|
113
|
+
@services_attributes = @services_attributes.merge(services)
|
114
|
+
self
|
115
|
+
end
|
116
|
+
|
117
|
+
def global_build_vars(variables)
|
118
|
+
@global_build_vars = variables
|
99
119
|
|
100
120
|
self
|
101
121
|
end
|
@@ -20,16 +20,17 @@ class KuberKit::Core::ConfigurationFactory
|
|
20
20
|
build_servers = fetch_build_servers(configuration_attrs.build_servers)
|
21
21
|
|
22
22
|
KuberKit::Core::Configuration.new(
|
23
|
-
name:
|
24
|
-
artifacts:
|
25
|
-
registries:
|
26
|
-
env_files:
|
27
|
-
templates:
|
28
|
-
kubeconfig_path:
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
23
|
+
name: configuration_attrs.name,
|
24
|
+
artifacts: artifacts,
|
25
|
+
registries: registries,
|
26
|
+
env_files: env_files,
|
27
|
+
templates: templates,
|
28
|
+
kubeconfig_path: configuration_attrs.kubeconfig_path,
|
29
|
+
deployer_strategy: configuration_attrs.deployer_strategy || configs.deployer_strategy,
|
30
|
+
deployer_namespace: configuration_attrs.deployer_namespace,
|
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
|
data/lib/kuber_kit/core/image.rb
CHANGED
@@ -33,7 +33,9 @@ class KuberKit::Core::Image
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def build_args
|
36
|
-
|
36
|
+
unless KuberKit.deprecation_warnings_disabled?
|
37
|
+
puts "WARNING: build_args is deprecated, please use build_vars instead"
|
38
|
+
end
|
37
39
|
build_vars
|
38
40
|
end
|
39
41
|
end
|
@@ -44,7 +44,9 @@ class KuberKit::Core::ImageDefinition
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def build_args(value = nil, &block)
|
47
|
-
|
47
|
+
unless KuberKit.deprecation_warnings_disabled?
|
48
|
+
puts "WARNING: build_args is deprecated, please use build_vars instead"
|
49
|
+
end
|
48
50
|
build_vars(value, *block)
|
49
51
|
end
|
50
52
|
|
@@ -66,14 +68,14 @@ class KuberKit::Core::ImageDefinition
|
|
66
68
|
self
|
67
69
|
end
|
68
70
|
|
69
|
-
def before_build(&block)
|
70
|
-
@before_build_callback = block
|
71
|
+
def before_build(lambda_arg = nil, &block)
|
72
|
+
@before_build_callback = lambda_arg || block
|
71
73
|
|
72
74
|
self
|
73
75
|
end
|
74
76
|
|
75
|
-
def after_build(&block)
|
76
|
-
@after_build_callback = block
|
77
|
+
def after_build(lambda_arg = nil, &block)
|
78
|
+
@after_build_callback = lambda_arg || block
|
77
79
|
|
78
80
|
self
|
79
81
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
class KuberKit::Core::Service
|
2
2
|
AttributeNotSet = Class.new(Indocker::Error)
|
3
3
|
|
4
|
-
attr_reader :name, :template_name, :tags, :images, :attributes, :
|
4
|
+
attr_reader :name, :template_name, :tags, :images, :attributes, :deployer_strategy
|
5
5
|
|
6
6
|
Contract KeywordArgs[
|
7
7
|
name: Symbol,
|
@@ -9,15 +9,15 @@ class KuberKit::Core::Service
|
|
9
9
|
tags: ArrayOf[Symbol],
|
10
10
|
images: ArrayOf[Symbol],
|
11
11
|
attributes: HashOf[Symbol => Any],
|
12
|
-
|
12
|
+
deployer_strategy: Maybe[Symbol]
|
13
13
|
] => Any
|
14
|
-
def initialize(name:, template_name:, tags:, images:, attributes:,
|
14
|
+
def initialize(name:, template_name:, tags:, images:, attributes:, deployer_strategy:)
|
15
15
|
@name = name
|
16
16
|
@template_name = template_name
|
17
17
|
@tags = tags
|
18
18
|
@images = images
|
19
19
|
@attributes = attributes
|
20
|
-
@
|
20
|
+
@deployer_strategy = deployer_strategy
|
21
21
|
end
|
22
22
|
|
23
23
|
def uri
|
@@ -13,7 +13,7 @@ class KuberKit::Core::ServiceDefinition
|
|
13
13
|
tags: Array(get_value(@tags)).map(&:to_sym),
|
14
14
|
images: Array(get_value(@images)).map(&:to_sym),
|
15
15
|
attributes: get_value(@attributes),
|
16
|
-
|
16
|
+
deployer_strategy: get_value(@deployer_strategy),
|
17
17
|
)
|
18
18
|
end
|
19
19
|
|
@@ -41,8 +41,8 @@ class KuberKit::Core::ServiceDefinition
|
|
41
41
|
self
|
42
42
|
end
|
43
43
|
|
44
|
-
def
|
45
|
-
@
|
44
|
+
def deployer_strategy(value = nil, &block)
|
45
|
+
@deployer_strategy = block_given? ? block : value
|
46
46
|
|
47
47
|
self
|
48
48
|
end
|
@@ -12,12 +12,12 @@ class KuberKit::Core::ServiceFactory
|
|
12
12
|
attributes = (service_attrs.attributes || {}).merge(configuration_attributes)
|
13
13
|
|
14
14
|
KuberKit::Core::Service.new(
|
15
|
-
name:
|
16
|
-
template_name:
|
17
|
-
tags:
|
18
|
-
images:
|
19
|
-
attributes:
|
20
|
-
|
15
|
+
name: service_attrs.name,
|
16
|
+
template_name: service_attrs.template_name,
|
17
|
+
tags: service_attrs.tags,
|
18
|
+
images: service_attrs.images,
|
19
|
+
attributes: attributes,
|
20
|
+
deployer_strategy: service_attrs.deployer_strategy,
|
21
21
|
)
|
22
22
|
end
|
23
23
|
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)
|
@@ -4,9 +4,15 @@ class KuberKit::ServiceDeployer::Deployer
|
|
4
4
|
include KuberKit::Import[
|
5
5
|
"core.service_store",
|
6
6
|
"service_deployer.strategies.kubernetes",
|
7
|
-
"service_deployer.strategies.kubernetes_runner"
|
7
|
+
"service_deployer.strategies.kubernetes_runner",
|
8
|
+
"service_deployer.strategies.docker_compose"
|
8
9
|
]
|
9
10
|
|
11
|
+
def initialize(**injected_deps)
|
12
|
+
super(injected_deps)
|
13
|
+
add_default_strategies
|
14
|
+
end
|
15
|
+
|
10
16
|
def register_strategy(strategy_name, strategy)
|
11
17
|
@@strategies ||= {}
|
12
18
|
|
@@ -19,8 +25,6 @@ class KuberKit::ServiceDeployer::Deployer
|
|
19
25
|
|
20
26
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service, Symbol => Any
|
21
27
|
def deploy(shell, service, strategy_name)
|
22
|
-
add_default_strategies
|
23
|
-
|
24
28
|
deployer = @@strategies[strategy_name]
|
25
29
|
|
26
30
|
raise StrategyNotFoundError, "Can't find strategy with name #{strategy_name}" if deployer.nil?
|
@@ -28,12 +32,14 @@ class KuberKit::ServiceDeployer::Deployer
|
|
28
32
|
deployer.deploy(shell, service)
|
29
33
|
end
|
30
34
|
|
31
|
-
def add_default_strategies
|
32
|
-
register_strategy(:kubernetes, kubernetes)
|
33
|
-
register_strategy(:kubernetes_runner, kubernetes_runner)
|
34
|
-
end
|
35
|
-
|
36
35
|
def reset!
|
37
36
|
@@strategies = {}
|
38
37
|
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def add_default_strategies
|
41
|
+
register_strategy(:kubernetes, kubernetes)
|
42
|
+
register_strategy(:kubernetes_runner, kubernetes_runner)
|
43
|
+
register_strategy(:docker_compose, docker_compose)
|
44
|
+
end
|
39
45
|
end
|