kuber_kit 0.5.2 → 0.5.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/CHANGELOG.md +19 -0
- data/Gemfile.lock +5 -5
- data/TODO.md +0 -1
- data/example/services/docker_app.rb +2 -1
- data/example/services/env_file.rb +1 -1
- data/example/services/ruby_app.rb +1 -1
- data/lib/kuber_kit.rb +6 -0
- data/lib/kuber_kit/actions/configuration_loader.rb +2 -1
- data/lib/kuber_kit/actions/kubectl_get.rb +32 -0
- data/lib/kuber_kit/actions/service_checker.rb +5 -0
- data/lib/kuber_kit/actions/service_deployer.rb +10 -2
- data/lib/kuber_kit/cli.rb +15 -4
- data/lib/kuber_kit/configs.rb +8 -5
- data/lib/kuber_kit/container.rb +20 -0
- data/lib/kuber_kit/core/artifacts/artifact_store.rb +3 -0
- data/lib/kuber_kit/core/configuration.rb +4 -2
- data/lib/kuber_kit/core/configuration_definition.rb +7 -0
- data/lib/kuber_kit/core/configuration_factory.rb +1 -0
- data/lib/kuber_kit/core/env_files/abstract_env_file.rb +4 -0
- data/lib/kuber_kit/core/env_files/artifact_file.rb +4 -0
- data/lib/kuber_kit/core/env_files/env_file_store.rb +3 -0
- data/lib/kuber_kit/core/env_files/env_group.rb +12 -0
- data/lib/kuber_kit/core/registries/registry_store.rb +3 -0
- data/lib/kuber_kit/core/templates/template_store.rb +3 -0
- data/lib/kuber_kit/env_file_reader/env_file_parser.rb +51 -0
- data/lib/kuber_kit/env_file_reader/env_file_tempfile_creator.rb +17 -0
- data/lib/kuber_kit/env_file_reader/reader.rb +2 -0
- data/lib/kuber_kit/env_file_reader/strategies/artifact_file.rb +9 -65
- data/lib/kuber_kit/env_file_reader/strategies/env_group.rb +21 -0
- data/lib/kuber_kit/service_deployer/service_list_resolver.rb +11 -6
- data/lib/kuber_kit/service_deployer/strategies/docker.rb +31 -12
- data/lib/kuber_kit/shell/local_shell.rb +15 -1
- data/lib/kuber_kit/template_reader/strategies/artifact_file.rb +3 -3
- data/lib/kuber_kit/tools/logger_factory.rb +14 -0
- data/lib/kuber_kit/tools/workdir_detector.rb +33 -0
- data/lib/kuber_kit/version.rb +1 -1
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9193e2d8c2f37a0ab10c3784fc353b2a7db990852aed41c12370624a4604eee3
|
4
|
+
data.tar.gz: e8effb3c080cdf273076f60998ef90fe70c0be31f36537edc06c1f6871b54541
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f9322e5dee8ef3385e4ceba437257bb7a549e0aba7804420fe44c7bb42731f9d22419a83e584a121226f1ea80192e1b9041b343756a947177e89f7be62f488c
|
7
|
+
data.tar.gz: 053c5fcbffe7c9246ede5e166abd17d7a62a20d0e63a5c5d10a21b63cf5ea9c02eacaee6f54ecab01c7c90f6f9d89b0300a9f9da38d213d7c512302cf5c4303c
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,22 @@
|
|
1
|
+
**0.5.7**
|
2
|
+
- Look for kuber_kit root path in parent folders, so kit command will work in sub-folders
|
3
|
+
|
4
|
+
**0.5.6**
|
5
|
+
- Pre-process env file if it has .erb extension
|
6
|
+
- Allow attaching env file from configuration to docker container
|
7
|
+
- Change default data paths to use home directory
|
8
|
+
- Add env groups support to combine multiple env files
|
9
|
+
|
10
|
+
**0.5.5**
|
11
|
+
- Added ability to skip services during deployment using -S option
|
12
|
+
|
13
|
+
**0.5.4**
|
14
|
+
- Added disabled services support
|
15
|
+
|
16
|
+
**0.5.3**
|
17
|
+
- Change the symbol to exclude service from "-" to "!", you can pass "-s !auth_app" to exclude "auth_app"
|
18
|
+
- Added kit get command to find pods
|
19
|
+
|
1
20
|
**0.5.2**
|
2
21
|
- Added dependencies support to services
|
3
22
|
- Added an option to deploy all services in `kit deloy`
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
kuber_kit (0.5.
|
4
|
+
kuber_kit (0.5.7)
|
5
5
|
cli-ui
|
6
6
|
contracts-lite
|
7
7
|
dry-auto_inject
|
@@ -12,9 +12,9 @@ PATH
|
|
12
12
|
GEM
|
13
13
|
remote: https://rubygems.org/
|
14
14
|
specs:
|
15
|
-
cli-ui (1.
|
15
|
+
cli-ui (1.5.1)
|
16
16
|
coderay (1.1.3)
|
17
|
-
concurrent-ruby (1.1.
|
17
|
+
concurrent-ruby (1.1.9)
|
18
18
|
contracts-lite (0.15.0)
|
19
19
|
diff-lcs (1.4.4)
|
20
20
|
docile (1.3.2)
|
@@ -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.
|
29
|
+
dry-core (0.6.0)
|
30
30
|
concurrent-ruby (~> 1.0)
|
31
31
|
method_source (1.0.0)
|
32
32
|
net-ssh (6.1.0)
|
@@ -58,7 +58,7 @@ GEM
|
|
58
58
|
thor (1.1.0)
|
59
59
|
tty-color (0.6.0)
|
60
60
|
tty-cursor (0.7.1)
|
61
|
-
tty-prompt (0.23.
|
61
|
+
tty-prompt (0.23.1)
|
62
62
|
pastel (~> 0.8)
|
63
63
|
tty-reader (~> 0.8)
|
64
64
|
tty-reader (0.9.0)
|
data/TODO.md
CHANGED
data/lib/kuber_kit.rb
CHANGED
@@ -54,6 +54,7 @@ module KuberKit
|
|
54
54
|
autoload :EnvFileStore, 'core/env_files/env_file_store'
|
55
55
|
autoload :AbstractEnvFile, 'core/env_files/abstract_env_file'
|
56
56
|
autoload :ArtifactFile, 'core/env_files/artifact_file'
|
57
|
+
autoload :EnvGroup, 'core/env_files/env_group'
|
57
58
|
end
|
58
59
|
|
59
60
|
module ContextHelper
|
@@ -81,6 +82,7 @@ module KuberKit
|
|
81
82
|
autoload :FilePresenceChecker, 'tools/file_presence_checker'
|
82
83
|
autoload :LoggerFactory, 'tools/logger_factory'
|
83
84
|
autoload :ProcessCleaner, 'tools/process_cleaner'
|
85
|
+
autoload :WorkdirDetector, 'tools/workdir_detector'
|
84
86
|
end
|
85
87
|
|
86
88
|
module Shell
|
@@ -127,10 +129,13 @@ module KuberKit
|
|
127
129
|
module EnvFileReader
|
128
130
|
autoload :ActionHandler, 'env_file_reader/action_handler'
|
129
131
|
autoload :Reader, 'env_file_reader/reader'
|
132
|
+
autoload :EnvFileParser, 'env_file_reader/env_file_parser'
|
133
|
+
autoload :EnvFileTempfileCreator, 'env_file_reader/env_file_tempfile_creator'
|
130
134
|
|
131
135
|
module Strategies
|
132
136
|
autoload :Abstract, 'env_file_reader/strategies/abstract'
|
133
137
|
autoload :ArtifactFile, 'env_file_reader/strategies/artifact_file'
|
138
|
+
autoload :EnvGroup, 'env_file_reader/strategies/env_group'
|
134
139
|
end
|
135
140
|
end
|
136
141
|
|
@@ -176,6 +181,7 @@ module KuberKit
|
|
176
181
|
autoload :KubectlAttacher, 'actions/kubectl_attacher'
|
177
182
|
autoload :KubectlConsole, 'actions/kubectl_console'
|
178
183
|
autoload :KubectlDescribe, 'actions/kubectl_describe'
|
184
|
+
autoload :KubectlGet, 'actions/kubectl_get'
|
179
185
|
autoload :KubectlLogs, 'actions/kubectl_logs'
|
180
186
|
autoload :KubectlEnv, 'actions/kubectl_env'
|
181
187
|
end
|
@@ -4,6 +4,7 @@ class KuberKit::Actions::ConfigurationLoader
|
|
4
4
|
"core.image_store",
|
5
5
|
"core.service_store",
|
6
6
|
"core.configuration_store",
|
7
|
+
"tools.workdir_detector",
|
7
8
|
"artifacts_sync.artifacts_updater",
|
8
9
|
"shell.local_shell",
|
9
10
|
"ui",
|
@@ -12,7 +13,7 @@ class KuberKit::Actions::ConfigurationLoader
|
|
12
13
|
|
13
14
|
Contract Hash => Any
|
14
15
|
def call(options)
|
15
|
-
root_path =
|
16
|
+
root_path = workdir_detector.call(options)
|
16
17
|
images_path = options[:images_path] || File.join(root_path, configs.images_dirname)
|
17
18
|
services_path = options[:services_path] || File.join(root_path, configs.services_dirname)
|
18
19
|
infra_path = options[:infra_path] || File.join(root_path, configs.infra_dirname)
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class KuberKit::Actions::KubectlGet
|
2
|
+
include KuberKit::Import[
|
3
|
+
"shell.kubectl_commands",
|
4
|
+
"shell.local_shell",
|
5
|
+
"kubernetes.resource_selector",
|
6
|
+
"ui"
|
7
|
+
]
|
8
|
+
|
9
|
+
Contract Maybe[String], Hash => Any
|
10
|
+
def call(resource_name, options)
|
11
|
+
kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
|
12
|
+
deployer_namespace = KuberKit.current_configuration.deployer_namespace
|
13
|
+
|
14
|
+
resources = kubectl_commands.get_resources(
|
15
|
+
local_shell, "pod",
|
16
|
+
kubeconfig_path: kubeconfig_path,
|
17
|
+
namespace: deployer_namespace
|
18
|
+
)
|
19
|
+
|
20
|
+
if resource_name
|
21
|
+
resources = resources.select{|r| r.include?(resource_name) }
|
22
|
+
end
|
23
|
+
|
24
|
+
ui.print_info("Pods", resources.join("\n"))
|
25
|
+
|
26
|
+
true
|
27
|
+
rescue KuberKit::Error => e
|
28
|
+
ui.print_error("Error", e.message)
|
29
|
+
|
30
|
+
false
|
31
|
+
end
|
32
|
+
end
|
@@ -15,6 +15,11 @@ class KuberKit::Actions::ServiceChecker
|
|
15
15
|
services = services.select{ |s| enabled_services.include?(s) }
|
16
16
|
end
|
17
17
|
|
18
|
+
disabled_services = KuberKit.current_configuration.disabled_services.map(&:to_s)
|
19
|
+
if disabled_services.any?
|
20
|
+
services = services.select{ |s| !disabled_services.include?(s) }
|
21
|
+
end
|
22
|
+
|
18
23
|
resources = resources_fetcher.call("deployments") + resources_fetcher.call("cronjobs")
|
19
24
|
|
20
25
|
missing_services = services.select{ |s| !resources.include?(s.gsub("_", "-")) }
|
@@ -14,18 +14,26 @@ class KuberKit::Actions::ServiceDeployer
|
|
14
14
|
Contract KeywordArgs[
|
15
15
|
services: Maybe[ArrayOf[String]],
|
16
16
|
tags: Maybe[ArrayOf[String]],
|
17
|
+
skip_services: Maybe[ArrayOf[String]],
|
17
18
|
skip_compile: Maybe[Bool],
|
18
19
|
require_confirmation: Maybe[Bool],
|
19
20
|
] => Any
|
20
|
-
def call(services:, tags:, skip_compile: false, require_confirmation: false)
|
21
|
+
def call(services:, tags:, skip_services: nil, skip_compile: false, require_confirmation: false)
|
22
|
+
current_configuration = KuberKit.current_configuration
|
23
|
+
|
21
24
|
if services.empty? && tags.empty?
|
22
25
|
services, tags = show_tags_selection
|
23
26
|
end
|
24
27
|
|
28
|
+
|
29
|
+
disabled_services = current_configuration.disabled_services.map(&:to_s)
|
30
|
+
disabled_services += skip_services if skip_services
|
31
|
+
|
25
32
|
service_names = service_list_resolver.resolve(
|
26
33
|
services: services || [],
|
27
34
|
tags: tags || [],
|
28
|
-
enabled_services:
|
35
|
+
enabled_services: current_configuration.enabled_services.map(&:to_s),
|
36
|
+
disabled_services: disabled_services
|
29
37
|
).map(&:to_sym)
|
30
38
|
|
31
39
|
# Return the list of services with all dependencies.
|
data/lib/kuber_kit/cli.rb
CHANGED
@@ -30,9 +30,10 @@ class KuberKit::CLI < Thor
|
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
33
|
-
desc "deploy -t
|
33
|
+
desc "deploy -t TAG_NAME", "Deploy CONTEXT_NAME with kubectl"
|
34
34
|
method_option :services, :type => :array, aliases: ["-s"], repeatable: true
|
35
35
|
method_option :tags, :type => :array, aliases: ["-t"], repeatable: true
|
36
|
+
method_option :skip_services, :type => :array, aliases: ["-S"], repeatable: true
|
36
37
|
method_option :skip_compile, :type => :boolean, aliases: ["-B"]
|
37
38
|
method_option :require_confirmation, :type => :boolean, aliases: ["-r"]
|
38
39
|
def deploy
|
@@ -46,6 +47,7 @@ class KuberKit::CLI < Thor
|
|
46
47
|
result = KuberKit::Container['actions.service_deployer'].call(
|
47
48
|
services: (options[:services] || []).flatten.uniq,
|
48
49
|
tags: (options[:tags] || []).flatten.uniq,
|
50
|
+
skip_services: (options[:skip_services] || []).flatten.uniq,
|
49
51
|
skip_compile: options[:skip_compile] || false,
|
50
52
|
require_confirmation: require_confirmation
|
51
53
|
)
|
@@ -59,8 +61,8 @@ class KuberKit::CLI < Thor
|
|
59
61
|
end
|
60
62
|
end
|
61
63
|
|
62
|
-
desc "
|
63
|
-
def
|
64
|
+
desc "envfile ENV_FILE_NAME", "Return content of Env File ENV_FILE_NAME"
|
65
|
+
def envfile(env_file_name)
|
64
66
|
setup(options)
|
65
67
|
|
66
68
|
if KuberKit::Container['actions.configuration_loader'].call(options)
|
@@ -150,6 +152,15 @@ class KuberKit::CLI < Thor
|
|
150
152
|
end
|
151
153
|
end
|
152
154
|
|
155
|
+
desc "get RESOURCE_NAME", "List pods matching RESOURCE_NAME using kubectl"
|
156
|
+
def get(pod_name = nil)
|
157
|
+
setup(options)
|
158
|
+
|
159
|
+
if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
|
160
|
+
KuberKit::Container['actions.kubectl_get'].call(pod_name, options)
|
161
|
+
end
|
162
|
+
end
|
163
|
+
|
153
164
|
desc "version", "Print current version"
|
154
165
|
def version
|
155
166
|
puts KuberKit::VERSION
|
@@ -168,7 +179,7 @@ class KuberKit::CLI < Thor
|
|
168
179
|
end
|
169
180
|
|
170
181
|
# We should load config before loading any bean, to make sure that bean won't be built with default config
|
171
|
-
root_path
|
182
|
+
root_path = KuberKit::Container['tools.workdir_detector'].call(options)
|
172
183
|
config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
|
173
184
|
if File.exists?(config_file_path)
|
174
185
|
require config_file_path
|
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, :deploy_simultaneous_limit,
|
8
|
-
:additional_images_paths, :deprecation_warnings_disabled, :log_file_path
|
8
|
+
:additional_images_paths, :deprecation_warnings_disabled, :log_file_path, :env_file_compile_dir
|
9
9
|
]
|
10
10
|
DOCKER_IGNORE_LIST = [
|
11
11
|
'Dockerfile',
|
@@ -34,10 +34,12 @@ class KuberKit::Configs
|
|
34
34
|
end
|
35
35
|
|
36
36
|
def add_default_configs
|
37
|
+
home_kuber_kit_path = File.expand_path(File.join("~", ".kuber_kit"))
|
38
|
+
|
37
39
|
set :image_dockerfile_name, "Dockerfile"
|
38
40
|
set :image_build_context_dir, "build_context"
|
39
41
|
set :image_tag, 'latest'
|
40
|
-
set :image_compile_dir, "
|
42
|
+
set :image_compile_dir, File.join(home_kuber_kit_path, "image_builds")
|
41
43
|
set :docker_ignore_list, DOCKER_IGNORE_LIST
|
42
44
|
set :kuber_kit_dirname, "kuber_kit"
|
43
45
|
set :kuber_kit_min_version, KuberKit::VERSION
|
@@ -45,14 +47,15 @@ class KuberKit::Configs
|
|
45
47
|
set :services_dirname, "services"
|
46
48
|
set :infra_dirname, "infrastructure"
|
47
49
|
set :configurations_dirname, "configurations"
|
48
|
-
set :artifact_clone_dir, "
|
49
|
-
set :service_config_dir, "
|
50
|
+
set :artifact_clone_dir, File.join(home_kuber_kit_path, "artifacts")
|
51
|
+
set :service_config_dir, File.join(home_kuber_kit_path, "services")
|
50
52
|
set :deployer_strategy, :kubernetes
|
51
53
|
set :compile_simultaneous_limit, 5
|
52
54
|
set :deploy_simultaneous_limit, 5
|
53
55
|
set :additional_images_paths, []
|
54
56
|
set :deprecation_warnings_disabled, false
|
55
|
-
set :log_file_path, "
|
57
|
+
set :log_file_path, File.join(home_kuber_kit_path, "deploy.log")
|
58
|
+
set :env_file_compile_dir, File.join(home_kuber_kit_path, "env_files")
|
56
59
|
end
|
57
60
|
|
58
61
|
def items
|
data/lib/kuber_kit/container.rb
CHANGED
@@ -45,6 +45,10 @@ class KuberKit::Container
|
|
45
45
|
KuberKit::Actions::KubectlDescribe.new
|
46
46
|
end
|
47
47
|
|
48
|
+
register "actions.kubectl_get" do
|
49
|
+
KuberKit::Actions::KubectlGet.new
|
50
|
+
end
|
51
|
+
|
48
52
|
register "actions.kubectl_logs" do
|
49
53
|
KuberKit::Actions::KubectlLogs.new
|
50
54
|
end
|
@@ -133,6 +137,10 @@ class KuberKit::Container
|
|
133
137
|
KuberKit::Tools::ProcessCleaner.new
|
134
138
|
end
|
135
139
|
|
140
|
+
register "tools.workdir_detector" do
|
141
|
+
KuberKit::Tools::WorkdirDetector.new
|
142
|
+
end
|
143
|
+
|
136
144
|
register "shell.bash_commands" do
|
137
145
|
KuberKit::Shell::Commands::BashCommands.new
|
138
146
|
end
|
@@ -225,10 +233,22 @@ class KuberKit::Container
|
|
225
233
|
KuberKit::EnvFileReader::Reader.new
|
226
234
|
end
|
227
235
|
|
236
|
+
register "env_file_reader.env_file_parser" do
|
237
|
+
KuberKit::EnvFileReader::EnvFileParser.new
|
238
|
+
end
|
239
|
+
|
240
|
+
register "env_file_reader.env_file_tempfile_creator" do
|
241
|
+
KuberKit::EnvFileReader::EnvFileTempfileCreator.new
|
242
|
+
end
|
243
|
+
|
228
244
|
register "env_file_reader.strategies.artifact_file" do
|
229
245
|
KuberKit::EnvFileReader::Strategies::ArtifactFile.new
|
230
246
|
end
|
231
247
|
|
248
|
+
register "env_file_reader.strategies.env_group" do
|
249
|
+
KuberKit::EnvFileReader::Strategies::EnvGroup.new
|
250
|
+
end
|
251
|
+
|
232
252
|
register "template_reader.action_handler" do
|
233
253
|
KuberKit::TemplateReader::ActionHandler.new
|
234
254
|
end
|
@@ -3,6 +3,7 @@ class KuberKit::Core::Artifacts::ArtifactStore
|
|
3
3
|
store.add(artifact.name, artifact)
|
4
4
|
end
|
5
5
|
|
6
|
+
Contract Symbol => Maybe[KuberKit::Core::Artifacts::AbstractArtifact]
|
6
7
|
def get(artifact_name)
|
7
8
|
artifact = get_from_configuration(artifact_name) ||
|
8
9
|
get_global(artifact_name)
|
@@ -10,10 +11,12 @@ class KuberKit::Core::Artifacts::ArtifactStore
|
|
10
11
|
artifact
|
11
12
|
end
|
12
13
|
|
14
|
+
Contract Symbol => Maybe[KuberKit::Core::Artifacts::AbstractArtifact]
|
13
15
|
def get_global(artifact_name)
|
14
16
|
store.get(artifact_name)
|
15
17
|
end
|
16
18
|
|
19
|
+
Contract Symbol => Maybe[KuberKit::Core::Artifacts::AbstractArtifact]
|
17
20
|
def get_from_configuration(artifact_name)
|
18
21
|
artifacts = KuberKit.current_configuration.artifacts
|
19
22
|
artifacts[artifact_name]
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class KuberKit::Core::Configuration
|
2
2
|
attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path,
|
3
|
-
:services_attributes, :enabled_services, :build_servers, :global_build_vars,
|
3
|
+
:services_attributes, :enabled_services, :disabled_services, :build_servers, :global_build_vars,
|
4
4
|
:deployer_strategy, :deployer_namespace, :deployer_require_confirimation
|
5
5
|
|
6
6
|
Contract KeywordArgs[
|
@@ -12,6 +12,7 @@ class KuberKit::Core::Configuration
|
|
12
12
|
kubeconfig_path: Maybe[String],
|
13
13
|
services_attributes: HashOf[Symbol => Hash],
|
14
14
|
enabled_services: ArrayOf[Symbol],
|
15
|
+
disabled_services: ArrayOf[Symbol],
|
15
16
|
build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer],
|
16
17
|
global_build_vars: HashOf[Symbol => Any],
|
17
18
|
deployer_strategy: Symbol,
|
@@ -19,7 +20,7 @@ class KuberKit::Core::Configuration
|
|
19
20
|
deployer_require_confirimation: Bool,
|
20
21
|
] => Any
|
21
22
|
def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:,
|
22
|
-
services_attributes:, enabled_services:, build_servers:, global_build_vars:,
|
23
|
+
services_attributes:, enabled_services:, disabled_services:, build_servers:, global_build_vars:,
|
23
24
|
deployer_strategy:, deployer_namespace:, deployer_require_confirimation:)
|
24
25
|
@name = name
|
25
26
|
@artifacts = artifacts
|
@@ -30,6 +31,7 @@ class KuberKit::Core::Configuration
|
|
30
31
|
@build_servers = build_servers
|
31
32
|
@services_attributes = services_attributes
|
32
33
|
@enabled_services = enabled_services
|
34
|
+
@disabled_services = disabled_services
|
33
35
|
@global_build_vars = global_build_vars
|
34
36
|
@deployer_strategy = deployer_strategy
|
35
37
|
@deployer_namespace = deployer_namespace
|
@@ -12,6 +12,7 @@ class KuberKit::Core::ConfigurationDefinition
|
|
12
12
|
@templates = {}
|
13
13
|
@build_servers = []
|
14
14
|
@enabled_services = []
|
15
|
+
@disabled_services = []
|
15
16
|
@services_attributes = {}
|
16
17
|
end
|
17
18
|
|
@@ -24,6 +25,7 @@ class KuberKit::Core::ConfigurationDefinition
|
|
24
25
|
templates: @templates,
|
25
26
|
kubeconfig_path: @kubeconfig_path,
|
26
27
|
enabled_services: @enabled_services,
|
28
|
+
disabled_services: @disabled_services,
|
27
29
|
build_servers: @build_servers,
|
28
30
|
services_attributes: @services_attributes,
|
29
31
|
global_build_vars: @global_build_vars,
|
@@ -116,6 +118,11 @@ class KuberKit::Core::ConfigurationDefinition
|
|
116
118
|
raise KuberKit::Error, "#enabled_services method accepts only Array or Hash"
|
117
119
|
end
|
118
120
|
|
121
|
+
def disabled_services(services)
|
122
|
+
@disabled_services += services.map(&:to_sym)
|
123
|
+
return self
|
124
|
+
end
|
125
|
+
|
119
126
|
def service_attributes(services)
|
120
127
|
@services_attributes = @services_attributes.merge(services)
|
121
128
|
self
|
@@ -29,6 +29,7 @@ class KuberKit::Core::ConfigurationFactory
|
|
29
29
|
build_servers: build_servers,
|
30
30
|
services_attributes: configuration_attrs.services_attributes,
|
31
31
|
enabled_services: configuration_attrs.enabled_services,
|
32
|
+
disabled_services: configuration_attrs.disabled_services,
|
32
33
|
global_build_vars: configuration_attrs.global_build_vars || {},
|
33
34
|
deployer_strategy: configuration_attrs.deployer_strategy || configs.deployer_strategy,
|
34
35
|
deployer_namespace: configuration_attrs.deployer_namespace,
|
@@ -3,6 +3,7 @@ class KuberKit::Core::EnvFiles::EnvFileStore
|
|
3
3
|
store.add(env_file.name, env_file)
|
4
4
|
end
|
5
5
|
|
6
|
+
Contract Symbol => Maybe[KuberKit::Core::EnvFiles::AbstractEnvFile]
|
6
7
|
def get(env_file_name)
|
7
8
|
env_file = get_from_configuration(env_file_name) ||
|
8
9
|
get_global(env_file_name)
|
@@ -10,10 +11,12 @@ class KuberKit::Core::EnvFiles::EnvFileStore
|
|
10
11
|
env_file
|
11
12
|
end
|
12
13
|
|
14
|
+
Contract Symbol => Maybe[KuberKit::Core::EnvFiles::AbstractEnvFile]
|
13
15
|
def get_global(env_file_name)
|
14
16
|
store.get(env_file_name)
|
15
17
|
end
|
16
18
|
|
19
|
+
Contract Symbol => Maybe[KuberKit::Core::EnvFiles::AbstractEnvFile]
|
17
20
|
def get_from_configuration(env_file_name)
|
18
21
|
env_files = KuberKit.current_configuration.env_files
|
19
22
|
env_files[env_file_name]
|
@@ -0,0 +1,12 @@
|
|
1
|
+
class KuberKit::Core::EnvFiles::EnvGroup < KuberKit::Core::EnvFiles::AbstractEnvFile
|
2
|
+
attr_reader :env_files
|
3
|
+
|
4
|
+
def initialize(env_group_name, env_files:)
|
5
|
+
super(env_group_name)
|
6
|
+
@env_files = env_files
|
7
|
+
end
|
8
|
+
|
9
|
+
def uniq_name
|
10
|
+
"env-group-#{@name.to_s}"
|
11
|
+
end
|
12
|
+
end
|
@@ -3,6 +3,7 @@ class KuberKit::Core::Registries::RegistryStore
|
|
3
3
|
store.add(registry.name, registry)
|
4
4
|
end
|
5
5
|
|
6
|
+
Contract Symbol => Maybe[KuberKit::Core::Registries::AbstractRegistry]
|
6
7
|
def get(registry_name)
|
7
8
|
registry = get_from_configuration(registry_name) ||
|
8
9
|
get_global(registry_name)
|
@@ -10,10 +11,12 @@ class KuberKit::Core::Registries::RegistryStore
|
|
10
11
|
registry
|
11
12
|
end
|
12
13
|
|
14
|
+
Contract Symbol => Maybe[KuberKit::Core::Registries::AbstractRegistry]
|
13
15
|
def get_global(registry_name)
|
14
16
|
store.get(registry_name)
|
15
17
|
end
|
16
18
|
|
19
|
+
Contract Symbol => Maybe[KuberKit::Core::Registries::AbstractRegistry]
|
17
20
|
def get_from_configuration(registry_name)
|
18
21
|
registries = KuberKit.current_configuration.registries
|
19
22
|
registries[registry_name]
|
@@ -3,6 +3,7 @@ class KuberKit::Core::Templates::TemplateStore
|
|
3
3
|
store.add(template.name, template)
|
4
4
|
end
|
5
5
|
|
6
|
+
Contract Symbol => Maybe[KuberKit::Core::Templates::AbstractTemplate]
|
6
7
|
def get(template_name)
|
7
8
|
template = get_from_configuration(template_name) ||
|
8
9
|
get_global(template_name)
|
@@ -10,10 +11,12 @@ class KuberKit::Core::Templates::TemplateStore
|
|
10
11
|
template
|
11
12
|
end
|
12
13
|
|
14
|
+
Contract Symbol => Maybe[KuberKit::Core::Templates::AbstractTemplate]
|
13
15
|
def get_global(template_name)
|
14
16
|
store.get(template_name)
|
15
17
|
end
|
16
18
|
|
19
|
+
Contract Symbol => Maybe[KuberKit::Core::Templates::AbstractTemplate]
|
17
20
|
def get_from_configuration(template_name)
|
18
21
|
templates = KuberKit.current_configuration.templates
|
19
22
|
templates[template_name]
|
@@ -0,0 +1,51 @@
|
|
1
|
+
class KuberKit::EnvFileReader::EnvFileParser
|
2
|
+
# Parser is based on:
|
3
|
+
# https://github.com/bkeepers/dotenv/blob/master/lib/dotenv/parser.rb
|
4
|
+
LINE = /
|
5
|
+
(?:^|\A) # beginning of line
|
6
|
+
\s* # leading whitespace
|
7
|
+
(?:export\s+)? # optional export
|
8
|
+
([\w\.]+) # key
|
9
|
+
(?:\s*=\s*?|:\s+?) # separator
|
10
|
+
( # optional value begin
|
11
|
+
\s*'(?:\\'|[^'])*' # single quoted value
|
12
|
+
| # or
|
13
|
+
\s*"(?:\\"|[^"])*" # double quoted value
|
14
|
+
| # or
|
15
|
+
[^\#\r\n]+ # unquoted value
|
16
|
+
)? # value end
|
17
|
+
\s* # trailing whitespace
|
18
|
+
(?:\#.*)? # optional comment
|
19
|
+
(?:$|\z) # end of line
|
20
|
+
/x
|
21
|
+
|
22
|
+
Contract String => Hash
|
23
|
+
def call(string)
|
24
|
+
hash = {}
|
25
|
+
string.gsub(/\r\n?/, "\n").scan(LINE).each do |key, value|
|
26
|
+
hash[key] = parse_value(value || "")
|
27
|
+
end
|
28
|
+
hash
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def parse_value(value)
|
34
|
+
# Remove surrounding quotes
|
35
|
+
value = value.strip.sub(/\A(['"])(.*)\1\z/m, '\2')
|
36
|
+
|
37
|
+
if Regexp.last_match(1) == '"'
|
38
|
+
value = unescape_characters(expand_newlines(value))
|
39
|
+
end
|
40
|
+
|
41
|
+
value
|
42
|
+
end
|
43
|
+
|
44
|
+
def unescape_characters(value)
|
45
|
+
value.gsub(/\\([^$])/, '\1')
|
46
|
+
end
|
47
|
+
|
48
|
+
def expand_newlines(value)
|
49
|
+
value.gsub('\n', "\n").gsub('\r', "\r")
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
class KuberKit::EnvFileReader::EnvFileTempfileCreator
|
2
|
+
include KuberKit::Import[
|
3
|
+
"env_file_reader.reader",
|
4
|
+
"configs"
|
5
|
+
]
|
6
|
+
|
7
|
+
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::EnvFiles::AbstractEnvFile => String
|
8
|
+
def call(shell, env_file)
|
9
|
+
env_file_hash = reader.read(shell, env_file)
|
10
|
+
env_file_raw = env_file_hash.to_a.map{|k,v| "#{k}=#{v}"}.join("\r\n")
|
11
|
+
temp_file_path = File.join(configs.env_file_compile_dir, env_file.uniq_name)
|
12
|
+
|
13
|
+
shell.write(temp_file_path, env_file_raw)
|
14
|
+
|
15
|
+
temp_file_path
|
16
|
+
end
|
17
|
+
end
|
@@ -3,6 +3,7 @@ class KuberKit::EnvFileReader::Reader
|
|
3
3
|
|
4
4
|
include KuberKit::Import[
|
5
5
|
"env_file_reader.strategies.artifact_file",
|
6
|
+
"env_file_reader.strategies.env_group",
|
6
7
|
]
|
7
8
|
|
8
9
|
def initialize(**injected_deps)
|
@@ -35,5 +36,6 @@ class KuberKit::EnvFileReader::Reader
|
|
35
36
|
private
|
36
37
|
def add_default_strategies
|
37
38
|
use_reader(artifact_file, env_file_class: KuberKit::Core::EnvFiles::ArtifactFile)
|
39
|
+
use_reader(env_group, env_file_class: KuberKit::Core::EnvFiles::EnvGroup)
|
38
40
|
end
|
39
41
|
end
|
@@ -1,8 +1,12 @@
|
|
1
1
|
class KuberKit::EnvFileReader::Strategies::ArtifactFile < KuberKit::EnvFileReader::Strategies::Abstract
|
2
2
|
include KuberKit::Import[
|
3
|
-
"core.artifact_store"
|
3
|
+
"core.artifact_store",
|
4
|
+
"env_file_reader.env_file_parser",
|
5
|
+
"preprocessing.text_preprocessor"
|
4
6
|
]
|
5
7
|
|
8
|
+
PREPROCESS_EXTENSIONS = [".erb"]
|
9
|
+
|
6
10
|
def read(shell, env_file)
|
7
11
|
artifact = artifact_store.get(env_file.artifact_name)
|
8
12
|
|
@@ -16,71 +20,11 @@ class KuberKit::EnvFileReader::Strategies::ArtifactFile < KuberKit::EnvFileReade
|
|
16
20
|
def read_file(shell, file_path)
|
17
21
|
result = {}
|
18
22
|
content = shell.read(file_path)
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
# Parser is based on:
|
23
|
-
# https://github.com/bkeepers/dotenv/blob/master/lib/dotenv/parser.rb
|
24
|
-
class Parser
|
25
|
-
LINE = /
|
26
|
-
(?:^|\A) # beginning of line
|
27
|
-
\s* # leading whitespace
|
28
|
-
(?:export\s+)? # optional export
|
29
|
-
([\w\.]+) # key
|
30
|
-
(?:\s*=\s*?|:\s+?) # separator
|
31
|
-
( # optional value begin
|
32
|
-
\s*'(?:\\'|[^'])*' # single quoted value
|
33
|
-
| # or
|
34
|
-
\s*"(?:\\"|[^"])*" # double quoted value
|
35
|
-
| # or
|
36
|
-
[^\#\r\n]+ # unquoted value
|
37
|
-
)? # value end
|
38
|
-
\s* # trailing whitespace
|
39
|
-
(?:\#.*)? # optional comment
|
40
|
-
(?:$|\z) # end of line
|
41
|
-
/x
|
42
|
-
|
43
|
-
class << self
|
44
|
-
def call(string, is_load = false)
|
45
|
-
new(string, is_load).call
|
23
|
+
enable_preprocessing = PREPROCESS_EXTENSIONS.any?{ |e| e == File.extname(file_path) }
|
24
|
+
if enable_preprocessing
|
25
|
+
content = text_preprocessor.compile(content)
|
46
26
|
end
|
47
|
-
end
|
48
27
|
|
49
|
-
|
50
|
-
@string = string
|
51
|
-
@hash = {}
|
52
|
-
@is_load = is_load
|
28
|
+
env_file_parser.call(content)
|
53
29
|
end
|
54
|
-
|
55
|
-
def call
|
56
|
-
# Convert line breaks to same format
|
57
|
-
lines = @string.gsub(/\r\n?/, "\n")
|
58
|
-
# Process matches
|
59
|
-
lines.scan(LINE).each do |key, value|
|
60
|
-
@hash[key] = parse_value(value || "")
|
61
|
-
end
|
62
|
-
@hash
|
63
|
-
end
|
64
|
-
|
65
|
-
private
|
66
|
-
|
67
|
-
def parse_value(value)
|
68
|
-
# Remove surrounding quotes
|
69
|
-
value = value.strip.sub(/\A(['"])(.*)\1\z/m, '\2')
|
70
|
-
|
71
|
-
if Regexp.last_match(1) == '"'
|
72
|
-
value = unescape_characters(expand_newlines(value))
|
73
|
-
end
|
74
|
-
|
75
|
-
value
|
76
|
-
end
|
77
|
-
|
78
|
-
def unescape_characters(value)
|
79
|
-
value.gsub(/\\([^$])/, '\1')
|
80
|
-
end
|
81
|
-
|
82
|
-
def expand_newlines(value)
|
83
|
-
value.gsub('\n', "\n").gsub('\r', "\r")
|
84
|
-
end
|
85
|
-
end
|
86
30
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
class KuberKit::EnvFileReader::Strategies::EnvGroup < KuberKit::EnvFileReader::Strategies::Abstract
|
2
|
+
include KuberKit::Import[
|
3
|
+
"env_file_reader.strategies.artifact_file",
|
4
|
+
"core.env_file_store",
|
5
|
+
]
|
6
|
+
|
7
|
+
def read(shell, env_group)
|
8
|
+
content = {}
|
9
|
+
env_group.env_files.each do |env_file_name|
|
10
|
+
env_file = env_file_store.get(env_file_name)
|
11
|
+
|
12
|
+
if env_file.is_a?(KuberKit::Core::EnvFiles::EnvGroup)
|
13
|
+
raise "EnvGroup inside another EnvGroup is not supported"
|
14
|
+
end
|
15
|
+
|
16
|
+
result = artifact_file.read(shell, env_file)
|
17
|
+
content = content.merge(result)
|
18
|
+
end
|
19
|
+
content
|
20
|
+
end
|
21
|
+
end
|
@@ -4,11 +4,12 @@ class KuberKit::ServiceDeployer::ServiceListResolver
|
|
4
4
|
]
|
5
5
|
|
6
6
|
Contract KeywordArgs[
|
7
|
-
services:
|
8
|
-
tags:
|
9
|
-
enabled_services:
|
7
|
+
services: Optional[ArrayOf[String]],
|
8
|
+
tags: Optional[ArrayOf[String]],
|
9
|
+
enabled_services: Optional[ArrayOf[String]],
|
10
|
+
disabled_services: Optional[ArrayOf[String]]
|
10
11
|
] => ArrayOf[String]
|
11
|
-
def resolve(services: [], tags: [], enabled_services: [])
|
12
|
+
def resolve(services: [], tags: [], enabled_services: [], disabled_services: [])
|
12
13
|
all_definitions = service_store.all_definitions.values
|
13
14
|
|
14
15
|
included_services, excluded_services = split_by_inclusion(services)
|
@@ -36,14 +37,18 @@ class KuberKit::ServiceDeployer::ServiceListResolver
|
|
36
37
|
included_services = included_services.select{ |s| enabled_services.include?(s) }
|
37
38
|
end
|
38
39
|
|
40
|
+
if disabled_services.any?
|
41
|
+
included_services = included_services.select{ |s| !disabled_services.include?(s) }
|
42
|
+
end
|
43
|
+
|
39
44
|
included_services
|
40
45
|
end
|
41
46
|
|
42
47
|
Contract Array => Array
|
43
48
|
def split_by_inclusion(array)
|
44
|
-
excluded, included = array.partition{|e| e.start_with?('
|
49
|
+
excluded, included = array.partition{|e| e.start_with?('^') }
|
45
50
|
|
46
|
-
excluded.map!{ |item| item.gsub(
|
51
|
+
excluded.map!{ |item| item.gsub(/^\^/, "") }
|
47
52
|
|
48
53
|
[included, excluded]
|
49
54
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer::Strategies::Abstract
|
2
2
|
include KuberKit::Import[
|
3
|
+
"env_file_reader.env_file_tempfile_creator",
|
3
4
|
"shell.docker_commands",
|
5
|
+
"core.env_file_store",
|
4
6
|
"core.image_store",
|
5
7
|
"configs",
|
6
8
|
]
|
@@ -18,6 +20,7 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
18
20
|
:networks,
|
19
21
|
:expose,
|
20
22
|
:publish,
|
23
|
+
:env_file_names
|
21
24
|
]
|
22
25
|
|
23
26
|
Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
|
@@ -28,16 +31,19 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
28
31
|
raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
|
29
32
|
end
|
30
33
|
|
31
|
-
namespace
|
32
|
-
container_name
|
33
|
-
command_name
|
34
|
-
|
35
|
-
custom_args
|
36
|
-
networks
|
37
|
-
volumes
|
38
|
-
expose_ports
|
39
|
-
publish_ports
|
40
|
-
hostname
|
34
|
+
namespace = strategy_options.fetch(:namespace, nil)
|
35
|
+
container_name = strategy_options.fetch(:container_name, [namespace, service.name].compact.join("_"))
|
36
|
+
command_name = strategy_options.fetch(:command_name, nil)
|
37
|
+
custom_env_file = strategy_options.fetch(:env_file, nil)
|
38
|
+
custom_args = strategy_options.fetch(:custom_args, nil)
|
39
|
+
networks = strategy_options.fetch(:networks, [])
|
40
|
+
volumes = strategy_options.fetch(:volumes, [])
|
41
|
+
expose_ports = strategy_options.fetch(:expose, [])
|
42
|
+
publish_ports = strategy_options.fetch(:publish, [])
|
43
|
+
hostname = strategy_options.fetch(:hostname, container_name)
|
44
|
+
|
45
|
+
env_file_names = strategy_options.fetch(:env_file_names, [])
|
46
|
+
env_files = prepare_env_files(shell, env_file_names)
|
41
47
|
|
42
48
|
image_name = strategy_options.fetch(:image_name, nil)
|
43
49
|
if image_name.nil?
|
@@ -54,8 +60,8 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
54
60
|
if container_name
|
55
61
|
custom_args << "--name #{container_name}"
|
56
62
|
end
|
57
|
-
if
|
58
|
-
custom_args << "--env-file #{
|
63
|
+
if custom_env_file
|
64
|
+
custom_args << "--env-file #{custom_env_file}"
|
59
65
|
end
|
60
66
|
if hostname
|
61
67
|
custom_args << "--hostname #{hostname}"
|
@@ -75,6 +81,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
75
81
|
Array(publish_ports).each do |publish_port|
|
76
82
|
custom_args << "--publish #{publish_port}"
|
77
83
|
end
|
84
|
+
Array(env_files).each do |env_file|
|
85
|
+
custom_args << "--env-file #{env_file}"
|
86
|
+
end
|
78
87
|
|
79
88
|
docker_commands.run(
|
80
89
|
shell, image.remote_registry_url,
|
@@ -84,4 +93,14 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
|
|
84
93
|
interactive: !strategy_options[:detached]
|
85
94
|
)
|
86
95
|
end
|
96
|
+
|
97
|
+
private
|
98
|
+
def prepare_env_files(shell, env_file_names)
|
99
|
+
env_files = env_file_names.map do |env_file_name|
|
100
|
+
env_file_store.get(env_file_name)
|
101
|
+
end
|
102
|
+
env_files.map do |env_file|
|
103
|
+
env_file_tempfile_creator.call(shell, env_file)
|
104
|
+
end
|
105
|
+
end
|
87
106
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
4
|
+
MAX_LINES_TO_PRINT = 50
|
5
|
+
|
4
6
|
include KuberKit::Import[
|
5
7
|
"shell.command_counter",
|
6
8
|
"shell.rsync_commands",
|
@@ -20,7 +22,19 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
|
|
20
22
|
end
|
21
23
|
|
22
24
|
if result && result != "" && log_command
|
23
|
-
|
25
|
+
print_result = result
|
26
|
+
print_result_lines = print_result.split("\n")
|
27
|
+
|
28
|
+
if print_result_lines.count >= MAX_LINES_TO_PRINT
|
29
|
+
print_result = [
|
30
|
+
"[Result is too long, showing only first and last items]".yellow,
|
31
|
+
print_result_lines.first,
|
32
|
+
"[#{print_result_lines.count - 2} lines not showing]".yellow,
|
33
|
+
print_result_lines.last
|
34
|
+
].join("\n")
|
35
|
+
end
|
36
|
+
|
37
|
+
ui.print_debug("LocalShell", "Finished [#{command_number}] with result: \n ----\n#{print_result.grey}\n ----")
|
24
38
|
end
|
25
39
|
|
26
40
|
if $?.exitstatus != 0
|
@@ -3,10 +3,10 @@ class KuberKit::TemplateReader::Strategies::ArtifactFile < KuberKit::TemplateRea
|
|
3
3
|
"core.artifact_store"
|
4
4
|
]
|
5
5
|
|
6
|
-
def read(shell,
|
7
|
-
artifact = artifact_store.get(
|
6
|
+
def read(shell, template)
|
7
|
+
artifact = artifact_store.get(template.artifact_name)
|
8
8
|
|
9
|
-
file_parts = [artifact.cloned_path,
|
9
|
+
file_parts = [artifact.cloned_path, template.file_path].compact
|
10
10
|
file_path = File.join(*file_parts)
|
11
11
|
|
12
12
|
shell.read(file_path)
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'logger'
|
2
|
+
require 'fileutils'
|
2
3
|
|
3
4
|
class KuberKit::Tools::LoggerFactory
|
4
5
|
SEVERITY_COLORS_BY_LEVEL = {
|
@@ -14,6 +15,10 @@ class KuberKit::Tools::LoggerFactory
|
|
14
15
|
]
|
15
16
|
|
16
17
|
def create(stdout = nil, level = nil)
|
18
|
+
if !stdout
|
19
|
+
prepare_log_file(configs.log_file_path)
|
20
|
+
end
|
21
|
+
|
17
22
|
logger = Logger.new(stdout || configs.log_file_path)
|
18
23
|
|
19
24
|
logger.level = level || Logger::DEBUG
|
@@ -35,4 +40,13 @@ class KuberKit::Tools::LoggerFactory
|
|
35
40
|
|
36
41
|
logger
|
37
42
|
end
|
43
|
+
|
44
|
+
private
|
45
|
+
def prepare_log_file(file_path)
|
46
|
+
dir_path = File.dirname(file_path)
|
47
|
+
unless Dir.exists?(dir_path)
|
48
|
+
FileUtils.mkdir_p(dir_path)
|
49
|
+
end
|
50
|
+
FileUtils.touch(file_path)
|
51
|
+
end
|
38
52
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class KuberKit::Tools::WorkdirDetector
|
2
|
+
include KuberKit::Import[
|
3
|
+
"configs",
|
4
|
+
"tools.file_presence_checker"
|
5
|
+
]
|
6
|
+
|
7
|
+
def call(options, current_dir: nil)
|
8
|
+
current_dir ||= Dir.pwd
|
9
|
+
default_dir = File.join(current_dir, configs.kuber_kit_dirname)
|
10
|
+
workdir_path = options[:path] || ENV['KUBER_KIT_PATH'] || default_dir
|
11
|
+
|
12
|
+
unless file_presence_checker.dir_exists?(workdir_path)
|
13
|
+
workdir_in_ancestors = find_workdir_in_ancestors(current_dir)
|
14
|
+
workdir_path = workdir_in_ancestors if workdir_in_ancestors
|
15
|
+
end
|
16
|
+
|
17
|
+
workdir_path
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def find_workdir_in_ancestors(dir)
|
22
|
+
if dir == "/"
|
23
|
+
return nil
|
24
|
+
end
|
25
|
+
|
26
|
+
workdir_path = File.join(dir, configs.kuber_kit_dirname)
|
27
|
+
if file_presence_checker.dir_exists?(workdir_path)
|
28
|
+
return workdir_path
|
29
|
+
end
|
30
|
+
|
31
|
+
find_workdir_in_ancestors(File.dirname(dir))
|
32
|
+
end
|
33
|
+
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.5.
|
4
|
+
version: 0.5.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: 2021-
|
11
|
+
date: 2021-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contracts-lite
|
@@ -211,6 +211,7 @@ files:
|
|
211
211
|
- lib/kuber_kit/actions/kubectl_console.rb
|
212
212
|
- lib/kuber_kit/actions/kubectl_describe.rb
|
213
213
|
- lib/kuber_kit/actions/kubectl_env.rb
|
214
|
+
- lib/kuber_kit/actions/kubectl_get.rb
|
214
215
|
- lib/kuber_kit/actions/kubectl_logs.rb
|
215
216
|
- lib/kuber_kit/actions/service_checker.rb
|
216
217
|
- lib/kuber_kit/actions/service_deployer.rb
|
@@ -244,6 +245,7 @@ files:
|
|
244
245
|
- lib/kuber_kit/core/env_files/abstract_env_file.rb
|
245
246
|
- lib/kuber_kit/core/env_files/artifact_file.rb
|
246
247
|
- lib/kuber_kit/core/env_files/env_file_store.rb
|
248
|
+
- lib/kuber_kit/core/env_files/env_group.rb
|
247
249
|
- lib/kuber_kit/core/image.rb
|
248
250
|
- lib/kuber_kit/core/image_definition.rb
|
249
251
|
- lib/kuber_kit/core/image_definition_factory.rb
|
@@ -262,9 +264,12 @@ files:
|
|
262
264
|
- lib/kuber_kit/core/templates/artifact_file.rb
|
263
265
|
- lib/kuber_kit/core/templates/template_store.rb
|
264
266
|
- lib/kuber_kit/env_file_reader/action_handler.rb
|
267
|
+
- lib/kuber_kit/env_file_reader/env_file_parser.rb
|
268
|
+
- lib/kuber_kit/env_file_reader/env_file_tempfile_creator.rb
|
265
269
|
- lib/kuber_kit/env_file_reader/reader.rb
|
266
270
|
- lib/kuber_kit/env_file_reader/strategies/abstract.rb
|
267
271
|
- lib/kuber_kit/env_file_reader/strategies/artifact_file.rb
|
272
|
+
- lib/kuber_kit/env_file_reader/strategies/env_group.rb
|
268
273
|
- lib/kuber_kit/extensions/colored_string.rb
|
269
274
|
- lib/kuber_kit/extensions/contracts.rb
|
270
275
|
- lib/kuber_kit/extensions/indocker_compat.rb
|
@@ -311,6 +316,7 @@ files:
|
|
311
316
|
- lib/kuber_kit/tools/file_presence_checker.rb
|
312
317
|
- lib/kuber_kit/tools/logger_factory.rb
|
313
318
|
- lib/kuber_kit/tools/process_cleaner.rb
|
319
|
+
- lib/kuber_kit/tools/workdir_detector.rb
|
314
320
|
- lib/kuber_kit/ui.rb
|
315
321
|
- lib/kuber_kit/ui/api.rb
|
316
322
|
- lib/kuber_kit/ui/debug.rb
|