kuber_kit 0.5.9 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: fa75f8b61926a3178d1592ceb81a35945a073b38d34c80c246872bae6b357d1f
4
- data.tar.gz: fc41c9917961f9bff18ac03a60a16a77f094deae51abc6e28d80524fab793968
3
+ metadata.gz: b9436f738b564585856ce6daa51aae3b55eeb0b33e68710c6d8be4b8a9cfa465
4
+ data.tar.gz: 12ed77727bfb8af6d719576e2676e5f3d12d9d5ab1b9a69b77c3804f4e64e175
5
5
  SHA512:
6
- metadata.gz: 7cb947b2cf303ef0f04a77364c0b6ea4043b2cf6f2b29cea0da1cd5d2808c7f2103799ad711e191e859bce59177372ac795460a1ed13589a6f62f536f4b23eb0
7
- data.tar.gz: 324b1de9e8e762a5bce7bebf29ff9cc0317814f924be886fd10434f2ed2ffc8376025200f7ed2e35e2300bbbb2968061775c6e1f1c07f4a0ad2a61038225e66f
6
+ metadata.gz: 31b571193f5130591b1f2bcfc73e42bb01bb5285beffbab26909e4ebccc765bc161b73897cc3d46e70ed2bc5975e445e02e6a0855493bb8ecad19f7b638d8685
7
+ data.tar.gz: 306aa5f9f87e075abc9fa65884ae211b9235039950dc1985c2f789d85b518f72d46a44c67def3f8af134b7cb1e6fc023b8755dd509f28721fa412bba3fa982ab
data/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ **0.6.2**
2
+ - Added an ability to return build vars as a hash value.
3
+ - Skip local artifacts while updating configuration, it sometimes produce an error
4
+
5
+ **0.6.1**
6
+ - Improve performance of artifacts update by updating in threads.
7
+ - Added an ability to define default services
8
+
9
+ **0.6.0**
10
+ - Cleanup old image build dirs
11
+ - Add rotation to deployment log file
12
+
13
+ **0.5.10**
14
+ - Fix a regression when deployment result would not be properly returned as json.
15
+
1
16
  **0.5.9**
2
17
  - Added an ability to set custom user
3
18
  - Allow setting environment variable in docker strategy
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.5.9)
4
+ kuber_kit (0.6.2)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject (~> 0.7.0)
data/TODO.md CHANGED
@@ -1,8 +1,3 @@
1
- - add kit get method for more interactive kubernetes
2
- - env files should use a separate deployment method (with change detection)
3
1
  - add automatical confirmation support for service deployer
4
2
  - template should be able to set default attributes
5
- - template should be able to depend on image?
6
- - cleanup image builds older than some date
7
- - add some rotation for deploy log
8
- - kit status should show the list of services and their status, with ability to select & view logs
3
+ - template should be able to depend on image?
data/lib/kuber_kit.rb CHANGED
@@ -79,6 +79,7 @@ module KuberKit
79
79
  end
80
80
 
81
81
  module Tools
82
+ autoload :BuildDirCleaner, 'tools/build_dir_cleaner'
82
83
  autoload :FilePresenceChecker, 'tools/file_presence_checker'
83
84
  autoload :LoggerFactory, 'tools/logger_factory'
84
85
  autoload :ProcessCleaner, 'tools/process_cleaner'
@@ -121,7 +122,7 @@ module KuberKit
121
122
 
122
123
  module ArtifactsSync
123
124
  autoload :AbstractArtifactResolver, 'artifacts_sync/abstract_artifact_resolver'
124
- autoload :ArtifactsUpdater, 'artifacts_sync/artifacts_updater'
125
+ autoload :ArtifactUpdater, 'artifacts_sync/artifact_updater'
125
126
  autoload :GitArtifactResolver, 'artifacts_sync/git_artifact_resolver'
126
127
  autoload :NullArtifactResolver, 'artifacts_sync/null_artifact_resolver'
127
128
  end
@@ -153,6 +154,7 @@ module KuberKit
153
154
  autoload :ActionHandler, 'service_deployer/action_handler'
154
155
  autoload :StrategyDetector, 'service_deployer/strategy_detector'
155
156
  autoload :Deployer, 'service_deployer/deployer'
157
+ autoload :DeploymentOptionsSelector, 'service_deployer/deployment_options_selector'
156
158
  autoload :ServiceListResolver, 'service_deployer/service_list_resolver'
157
159
  autoload :ServiceDependencyResolver, 'service_deployer/service_dependency_resolver'
158
160
 
@@ -1,8 +1,8 @@
1
1
  class KuberKit::Actions::ActionResult
2
- attr_reader :finished_tasks, :result, :error
2
+ attr_reader :finished_tasks, :all_results, :error
3
3
 
4
4
  def initialize()
5
- @results = {}
5
+ @all_results = {}
6
6
  @started_tasks = []
7
7
  @finished_tasks = []
8
8
  @mutex = Mutex.new
@@ -14,11 +14,11 @@ class KuberKit::Actions::ActionResult
14
14
  end
15
15
  end
16
16
 
17
- def finish_task(task, result)
17
+ def finish_task(task, result = nil)
18
18
  @mutex.synchronize do
19
19
  @started_tasks.delete(task)
20
20
  @finished_tasks.push(task)
21
- @results[task] = result
21
+ @all_results[task] = result
22
22
  end
23
23
  end
24
24
 
@@ -5,7 +5,7 @@ class KuberKit::Actions::ConfigurationLoader
5
5
  "core.service_store",
6
6
  "core.configuration_store",
7
7
  "tools.workdir_detector",
8
- "artifacts_sync.artifacts_updater",
8
+ "artifacts_sync.artifact_updater",
9
9
  "shell.local_shell",
10
10
  "ui",
11
11
  "configs"
@@ -43,11 +43,7 @@ class KuberKit::Actions::ConfigurationLoader
43
43
  load_infrastructure(infra_path)
44
44
 
45
45
  if load_inventory
46
- ui.create_task("Updating artifacts") do |task|
47
- artifacts = KuberKit.current_configuration.artifacts.values
48
- artifacts_updater.update(local_shell, artifacts)
49
- task.update_title("Updated #{artifacts.count} artifacts")
50
- end
46
+ update_artifacts(KuberKit.current_configuration.artifacts.values)
51
47
 
52
48
  ui.create_task("Loading image definitions") do |task|
53
49
  files = image_store.load_definitions(images_path)
@@ -101,4 +97,21 @@ class KuberKit::Actions::ConfigurationLoader
101
97
  rescue KuberKit::Shell::AbstractShell::DirNotFoundError
102
98
  ui.print_warning("ConfigurationLoader", "Directory with infrastructure not found: #{infra_path}")
103
99
  end
100
+
101
+ def update_artifacts(artifacts)
102
+ return unless artifacts.any?
103
+
104
+ # Skip local artifacts, they sometimes produce error in CLI::UI::SpinGroup task,
105
+ # because the task is executed too quickly
106
+ not_local_artifacts = artifacts.reject{ |a| a.is_a?(KuberKit::Core::Artifacts::Local) }
107
+
108
+ artifact_task_group = ui.create_task_group
109
+ not_local_artifacts.each do |artifact|
110
+ artifact_task_group.add("Updating #{artifact.name.to_s.yellow}") do |task|
111
+ artifact_updater.update(local_shell, artifact)
112
+ task.update_title("Updated #{artifact.name.to_s.green}")
113
+ end
114
+ end
115
+ artifact_task_group.wait
116
+ end
104
117
  end
@@ -30,7 +30,7 @@ class KuberKit::Actions::ImageCompiler
30
30
  ui.print_error("Error", e.message)
31
31
 
32
32
  compilation_result.failed!(e.message)
33
-
33
+
34
34
  false
35
35
  end
36
36
 
@@ -3,6 +3,7 @@ class KuberKit::Actions::ServiceDeployer
3
3
  "actions.image_compiler",
4
4
  "service_deployer.service_list_resolver",
5
5
  "service_deployer.service_dependency_resolver",
6
+ "service_deployer.deployment_options_selector",
6
7
  "core.service_store",
7
8
  "shell.local_shell",
8
9
  "tools.process_cleaner",
@@ -23,18 +24,20 @@ class KuberKit::Actions::ServiceDeployer
23
24
  current_configuration = KuberKit.current_configuration
24
25
 
25
26
  if services.empty? && tags.empty?
26
- services, tags = show_tags_selection
27
+ services, tags = deployment_options_selector.call()
27
28
  end
28
29
 
29
-
30
+ default_services = current_configuration.default_services.map(&:to_s)
30
31
  disabled_services = current_configuration.disabled_services.map(&:to_s)
31
32
  disabled_services += skip_services if skip_services
33
+
32
34
 
33
35
  service_names = service_list_resolver.resolve(
34
36
  services: services || [],
35
37
  tags: tags || [],
36
38
  enabled_services: current_configuration.enabled_services.map(&:to_s),
37
- disabled_services: disabled_services
39
+ disabled_services: disabled_services,
40
+ default_services: default_services
38
41
  ).map(&:to_sym)
39
42
 
40
43
  # Return the list of services with all dependencies.
@@ -45,20 +48,12 @@ class KuberKit::Actions::ServiceDeployer
45
48
  return false
46
49
  end
47
50
 
48
- services_list = all_service_names.map(&:to_s).map(&:yellow).join(", ")
49
- ui.print_info "ServiceDeployer", "The following services will be deployed: #{services_list}"
50
-
51
- if require_confirmation
52
- result = ui.prompt("Please confirm to continue deployment", ["confirm".green, "cancel".red])
53
- return false unless ["confirm".green, "confirm", "yes"].include?(result)
54
- end
55
-
56
- services = all_service_names.map do |service_name|
57
- service_store.get_service(service_name.to_sym)
51
+ unless allow_deployment?(require_confirmation: require_confirmation, service_names: all_service_names)
52
+ return false
58
53
  end
59
54
 
60
- images_names = services.map(&:images).flatten.uniq
61
-
55
+ # Compile images for all services and dependencies
56
+ images_names = get_image_names(service_names: all_service_names)
62
57
  unless skip_compile
63
58
  compilation_result = compile_images(images_names)
64
59
 
@@ -77,11 +72,13 @@ class KuberKit::Actions::ServiceDeployer
77
72
  rescue KuberKit::Error => e
78
73
  ui.print_error("Error", e.message)
79
74
 
80
- compilation_result.failed!(e.message)
81
-
75
+ deployment_result.failed!(e.message)
76
+
82
77
  false
83
78
  rescue Interrupt => e
84
79
  process_cleaner.clean
80
+
81
+ false
85
82
  end
86
83
 
87
84
  private
@@ -109,46 +106,23 @@ class KuberKit::Actions::ServiceDeployer
109
106
  image_compiler.call(images_names, {})
110
107
  end
111
108
 
112
- def show_tags_selection()
113
- specific_service_option = "deploy specific service"
114
- all_services_option = "deploy all services"
115
-
116
- tags = [specific_service_option, all_services_option]
117
- tags += service_store
118
- .all_definitions
119
- .values
120
- .map(&:to_service_attrs)
121
- .map(&:tags)
122
- .flatten
123
- .uniq
124
- .sort
125
- .map(&:to_s)
126
-
127
- selected_tag = ui.prompt("Please select which tag to deploy", tags)
128
-
129
- if selected_tag == specific_service_option
130
- show_service_selection
131
- elsif selected_tag == all_services_option
132
- [["*"], []]
133
- else
134
- [[], [selected_tag]]
109
+ def get_image_names(service_names:)
110
+ services = service_names.map do |service_name|
111
+ service_store.get_service(service_name.to_sym)
135
112
  end
113
+
114
+ services.map(&:images).flatten.uniq
136
115
  end
137
116
 
138
- def show_service_selection()
139
- services = service_store
140
- .all_definitions
141
- .values
142
- .map(&:service_name)
143
- .uniq
144
- .sort
145
- .map(&:to_s)
146
-
147
- if services.empty?
148
- return [[], []]
117
+ def allow_deployment?(require_confirmation:, service_names:)
118
+ services_list = service_names.map(&:to_s).map(&:yellow).join(", ")
119
+ ui.print_info "ServiceDeployer", "The following services will be deployed: #{services_list}"
120
+
121
+ unless require_confirmation
122
+ return true
149
123
  end
150
124
 
151
- selected_service = ui.prompt("Please select which service to deploy", services)
152
- [[selected_service], []]
125
+ result = ui.prompt("Please confirm to continue deployment", ["confirm".green, "cancel".red])
126
+ return ["confirm".green, "confirm", "yes"].include?(result)
153
127
  end
154
128
  end
@@ -1,4 +1,4 @@
1
- class KuberKit::ArtifactsSync::ArtifactsUpdater
1
+ class KuberKit::ArtifactsSync::ArtifactUpdater
2
2
  ResolverNotFoundError = Class.new(KuberKit::NotFoundError)
3
3
 
4
4
  include KuberKit::Import[
@@ -18,18 +18,16 @@ class KuberKit::ArtifactsSync::ArtifactsUpdater
18
18
  @@resolvers[artifact_class] = artifact_resolver
19
19
  end
20
20
 
21
- def update(shell, artifacts)
21
+ def update(shell, artifact)
22
22
  add_default_resolvers
23
23
 
24
- artifacts.each do |artifact|
25
- resolver = @@resolvers[artifact.class]
24
+ resolver = @@resolvers[artifact.class]
26
25
 
27
- ui.print_debug "ArtifactUpdater", "Updating artifact #{artifact.name.to_s.green}"
28
-
29
- raise ResolverNotFoundError, "Can't find resolver for artifact #{artifact}" if resolver.nil?
26
+ ui.print_debug "ArtifactUpdater", "Updating artifact #{artifact.name.to_s.green}"
27
+
28
+ raise ResolverNotFoundError, "Can't find resolver for artifact #{artifact}" if resolver.nil?
30
29
 
31
- resolver.resolve(shell, artifact)
32
- end
30
+ resolver.resolve(shell, artifact)
33
31
  end
34
32
 
35
33
  def add_default_resolvers
data/lib/kuber_kit/cli.rb CHANGED
@@ -27,7 +27,7 @@ class KuberKit::CLI < Thor
27
27
  time = (Time.now.to_i - started_at)
28
28
  print_result("Image compilation finished! (#{time}s)", result: {
29
29
  images: action_result.finished_tasks,
30
- compilation: action_result.result
30
+ compilation: action_result.all_results
31
31
  })
32
32
  else
33
33
  exit 1
@@ -45,7 +45,7 @@ class KuberKit::CLI < Thor
45
45
 
46
46
  if KuberKit::Container['actions.configuration_loader'].call(options)
47
47
  require_confirmation = options[:require_confirmation] ||
48
- KuberKit.current_configuration.deployer_require_confirimation ||
48
+ KuberKit.current_configuration.deployer_require_confirmation ||
49
49
  false
50
50
  started_at = Time.now.to_i
51
51
  action_result = KuberKit::Container['actions.service_deployer'].call(
@@ -61,7 +61,7 @@ class KuberKit::CLI < Thor
61
61
  time = (Time.now.to_i - started_at)
62
62
  print_result("Service deployment finished! (#{time}s)", result: {
63
63
  services: action_result.finished_tasks,
64
- deployment: action_result.result
64
+ deployment: action_result.all_results
65
65
  })
66
66
  else
67
67
  exit 1
@@ -121,6 +121,10 @@ class KuberKit::Container
121
121
  KuberKit::Core::ContextHelper::ContextHelperFactory.new
122
122
  end
123
123
 
124
+ register "tools.build_dir_cleaner" do
125
+ KuberKit::Tools::BuildDirCleaner.new
126
+ end
127
+
124
128
  register "tools.file_presence_checker" do
125
129
  KuberKit::Tools::FilePresenceChecker.new
126
130
  end
@@ -213,8 +217,8 @@ class KuberKit::Container
213
217
  KuberKit::ImageCompiler::VersionTagBuilder.new
214
218
  end
215
219
 
216
- register "artifacts_sync.artifacts_updater" do
217
- KuberKit::ArtifactsSync::ArtifactsUpdater.new
220
+ register "artifacts_sync.artifact_updater" do
221
+ KuberKit::ArtifactsSync::ArtifactUpdater.new
218
222
  end
219
223
 
220
224
  register "artifacts_sync.git_artifact_resolver" do
@@ -273,6 +277,10 @@ class KuberKit::Container
273
277
  KuberKit::ServiceDeployer::Deployer.new
274
278
  end
275
279
 
280
+ register "service_deployer.deployment_options_selector" do
281
+ KuberKit::ServiceDeployer::DeploymentOptionsSelector.new
282
+ end
283
+
276
284
  register "service_deployer.service_list_resolver" do
277
285
  KuberKit::ServiceDeployer::ServiceListResolver.new
278
286
  end
@@ -1,7 +1,8 @@
1
1
  class KuberKit::Core::Configuration
2
2
  attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path,
3
- :services_attributes, :enabled_services, :disabled_services, :build_servers, :global_build_vars,
4
- :deployer_strategy, :deployer_namespace, :deployer_require_confirimation
3
+ :services_attributes, :enabled_services, :disabled_services, :default_services,
4
+ :build_servers, :global_build_vars,
5
+ :deployer_strategy, :deployer_namespace, :deployer_require_confirmation
5
6
 
6
7
  Contract KeywordArgs[
7
8
  name: Symbol,
@@ -13,15 +14,17 @@ class KuberKit::Core::Configuration
13
14
  services_attributes: HashOf[Symbol => Hash],
14
15
  enabled_services: ArrayOf[Symbol],
15
16
  disabled_services: ArrayOf[Symbol],
17
+ default_services: ArrayOf[Symbol],
16
18
  build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer],
17
19
  global_build_vars: HashOf[Symbol => Any],
18
20
  deployer_strategy: Symbol,
19
21
  deployer_namespace: Maybe[Symbol],
20
- deployer_require_confirimation: Bool,
22
+ deployer_require_confirmation: Bool,
21
23
  ] => Any
22
24
  def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:,
23
- services_attributes:, enabled_services:, disabled_services:, build_servers:, global_build_vars:,
24
- deployer_strategy:, deployer_namespace:, deployer_require_confirimation:)
25
+ services_attributes:, enabled_services:, disabled_services:, default_services:,
26
+ build_servers:, global_build_vars:,
27
+ deployer_strategy:, deployer_namespace:, deployer_require_confirmation:)
25
28
  @name = name
26
29
  @artifacts = artifacts
27
30
  @registries = registries
@@ -32,10 +35,11 @@ class KuberKit::Core::Configuration
32
35
  @services_attributes = services_attributes
33
36
  @enabled_services = enabled_services
34
37
  @disabled_services = disabled_services
38
+ @default_services = default_services
35
39
  @global_build_vars = global_build_vars
36
40
  @deployer_strategy = deployer_strategy
37
41
  @deployer_namespace = deployer_namespace
38
- @deployer_require_confirimation = deployer_require_confirimation
42
+ @deployer_require_confirmation = deployer_require_confirmation
39
43
  end
40
44
 
41
45
  def service_attributes(service_name)
@@ -13,6 +13,7 @@ class KuberKit::Core::ConfigurationDefinition
13
13
  @build_servers = []
14
14
  @enabled_services = []
15
15
  @disabled_services = []
16
+ @default_services = []
16
17
  @services_attributes = {}
17
18
  end
18
19
 
@@ -26,12 +27,13 @@ class KuberKit::Core::ConfigurationDefinition
26
27
  kubeconfig_path: @kubeconfig_path,
27
28
  enabled_services: @enabled_services,
28
29
  disabled_services: @disabled_services,
30
+ default_services: @default_services,
29
31
  build_servers: @build_servers,
30
32
  services_attributes: @services_attributes,
31
33
  global_build_vars: @global_build_vars,
32
34
  deployer_strategy: @deployer_strategy,
33
35
  deployer_namespace: @deployer_namespace,
34
- deployer_require_confirimation: @deployer_require_confirimation || false,
36
+ deployer_require_confirmation: @deployer_require_confirmation || false,
35
37
  )
36
38
  end
37
39
 
@@ -97,11 +99,12 @@ class KuberKit::Core::ConfigurationDefinition
97
99
  self
98
100
  end
99
101
 
100
- def deployer_require_confirimation
101
- @deployer_require_confirimation = true
102
+ def deployer_require_confirmation
103
+ @deployer_require_confirmation = true
102
104
 
103
105
  self
104
106
  end
107
+ alias_method :deployer_require_confirimation, :deployer_require_confirmation
105
108
 
106
109
  def enabled_services(services)
107
110
  if services.is_a?(Hash)
@@ -118,6 +121,11 @@ class KuberKit::Core::ConfigurationDefinition
118
121
  raise KuberKit::Error, "#enabled_services method accepts only Array or Hash"
119
122
  end
120
123
 
124
+ def default_services(services)
125
+ @default_services += services.map(&:to_sym)
126
+ return self
127
+ end
128
+
121
129
  def disabled_services(services)
122
130
  @disabled_services += services.map(&:to_sym)
123
131
  return self
@@ -30,10 +30,11 @@ class KuberKit::Core::ConfigurationFactory
30
30
  services_attributes: configuration_attrs.services_attributes,
31
31
  enabled_services: configuration_attrs.enabled_services,
32
32
  disabled_services: configuration_attrs.disabled_services,
33
+ default_services: configuration_attrs.default_services,
33
34
  global_build_vars: configuration_attrs.global_build_vars || {},
34
35
  deployer_strategy: configuration_attrs.deployer_strategy || configs.deployer_strategy,
35
36
  deployer_namespace: configuration_attrs.deployer_namespace,
36
- deployer_require_confirimation: configuration_attrs.deployer_require_confirimation,
37
+ deployer_require_confirmation: configuration_attrs.deployer_require_confirmation,
37
38
  )
38
39
  end
39
40
 
@@ -23,6 +23,14 @@ class KuberKit::Core::ContextHelper::ContextVars
23
23
  value
24
24
  end
25
25
 
26
+ def to_h
27
+ if @context_vars.is_a?(Hash)
28
+ return @context_vars
29
+ else
30
+ return {value: @context_vars}
31
+ end
32
+ end
33
+
26
34
  private
27
35
 
28
36
  def format_arg(name)
@@ -2,12 +2,15 @@ class KuberKit::ImageCompiler::ActionHandler
2
2
  include KuberKit::Import[
3
3
  "image_compiler.compiler",
4
4
  "core.image_store",
5
+ "tools.build_dir_cleaner",
5
6
  "configs",
6
7
  ]
7
8
 
8
9
  Contract KuberKit::Shell::AbstractShell, Symbol, String => Any
9
10
  def call(shell, image_name, build_id)
10
11
  image = image_store.get_image(image_name)
12
+
13
+ build_dir_cleaner.call(parent_dir: configs.image_compile_dir)
11
14
 
12
15
  compile_dir = generate_compile_dir(build_id: build_id)
13
16
 
@@ -0,0 +1,49 @@
1
+ class KuberKit::ServiceDeployer::DeploymentOptionsSelector
2
+ include KuberKit::Import[
3
+ "core.service_store",
4
+ "ui"
5
+ ]
6
+
7
+ OPTION_SPECIFIC_SERVICE = "deploy specific service".freeze
8
+ OPTION_ALL_SERVICES = "deploy all services"
9
+
10
+ def call()
11
+ tags = [OPTION_SPECIFIC_SERVICE, OPTION_ALL_SERVICES]
12
+ tags += service_store
13
+ .all_definitions
14
+ .values
15
+ .map(&:to_service_attrs)
16
+ .map(&:tags)
17
+ .flatten
18
+ .uniq
19
+ .sort
20
+ .map(&:to_s)
21
+
22
+ selected_tag = ui.prompt("Please select which tag to deploy", tags)
23
+
24
+ if selected_tag == OPTION_SPECIFIC_SERVICE
25
+ show_service_selection
26
+ elsif selected_tag == OPTION_ALL_SERVICES
27
+ [["*"], []]
28
+ else
29
+ [[], [selected_tag]]
30
+ end
31
+ end
32
+
33
+ def show_service_selection()
34
+ services = service_store
35
+ .all_definitions
36
+ .values
37
+ .map(&:service_name)
38
+ .uniq
39
+ .sort
40
+ .map(&:to_s)
41
+
42
+ if services.empty?
43
+ return [[], []]
44
+ end
45
+
46
+ selected_service = ui.prompt("Please select which service to deploy", services)
47
+ [[selected_service], []]
48
+ end
49
+ end
@@ -7,9 +7,10 @@ class KuberKit::ServiceDeployer::ServiceListResolver
7
7
  services: Optional[ArrayOf[String]],
8
8
  tags: Optional[ArrayOf[String]],
9
9
  enabled_services: Optional[ArrayOf[String]],
10
- disabled_services: Optional[ArrayOf[String]]
10
+ disabled_services: Optional[ArrayOf[String]],
11
+ default_services: Optional[ArrayOf[String]]
11
12
  ] => ArrayOf[String]
12
- def resolve(services: [], tags: [], enabled_services: [], disabled_services: [])
13
+ def resolve(services: [], tags: [], enabled_services: [], disabled_services: [], default_services: [])
13
14
  all_definitions = service_store.all_definitions.values
14
15
 
15
16
  included_services, excluded_services = split_by_inclusion(services)
@@ -41,6 +42,10 @@ class KuberKit::ServiceDeployer::ServiceListResolver
41
42
  included_services = included_services.select{ |s| !disabled_services.include?(s) }
42
43
  end
43
44
 
45
+ if included_services.any?
46
+ included_services += default_services
47
+ end
48
+
44
49
  included_services
45
50
  end
46
51
 
@@ -100,6 +100,18 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
100
100
  end
101
101
  end
102
102
 
103
+ def list_dirs(path)
104
+ command = %Q{find -L #{path} -type f}
105
+ command += " -name '#{name}'" if name
106
+ exec!(command).split(/[\r\n]+/)
107
+ rescue => e
108
+ if e.message.include?("No such file or directory")
109
+ raise DirNotFoundError.new("Dir not found: #{path}")
110
+ else
111
+ raise e
112
+ end
113
+ end
114
+
103
115
  def wrap_command_with_pid(command)
104
116
  "KIT=#{Process.pid} #{command}"
105
117
  end
@@ -0,0 +1,26 @@
1
+ class KuberKit::Tools::BuildDirCleaner
2
+ include KuberKit::Import[
3
+ "shell.bash_commands",
4
+ "shell.local_shell",
5
+ ]
6
+
7
+ KEEP_DIRS_COUNT = 10
8
+
9
+ def call(parent_dir:)
10
+ dirs_to_delete = get_ancient_builds_dirs(parent_dir: parent_dir)
11
+
12
+ dirs_to_delete.each do |dir|
13
+ bash_commands.rm_rf(local_shell, dir)
14
+ end
15
+ end
16
+
17
+ private
18
+ def get_ancient_builds_dirs(parent_dir:)
19
+ all_dirs = Dir.glob("#{parent_dir}/*")
20
+ skip_dirs = all_dirs
21
+ .sort_by{ |f| File.ctime(f) }
22
+ .reverse[0...KEEP_DIRS_COUNT]
23
+
24
+ all_dirs - skip_dirs
25
+ end
26
+ end
@@ -10,16 +10,17 @@ class KuberKit::Tools::LoggerFactory
10
10
  Logger::FATAL => String::Colors::PURPLE,
11
11
  }
12
12
 
13
+ MAX_LOGS_TO_KEEP = 3
14
+ MAX_LOG_FILE_SIZE = 512000
15
+
13
16
  include KuberKit::Import[
14
17
  "configs",
15
18
  ]
16
19
 
17
- def create(stdout = nil, level = nil)
18
- if !stdout
19
- prepare_log_file(configs.log_file_path)
20
- end
20
+ def create(level: nil)
21
+ prepare_log_file(configs.log_file_path)
21
22
 
22
- logger = Logger.new(stdout || configs.log_file_path)
23
+ logger = Logger.new(configs.log_file_path, MAX_LOGS_TO_KEEP, MAX_LOG_FILE_SIZE)
23
24
 
24
25
  logger.level = level || Logger::DEBUG
25
26
 
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.5.9"
2
+ VERSION = "0.6.2"
3
3
  end
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.9
4
+ version: 0.6.2
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-06-21 00:00:00.000000000 Z
11
+ date: 2021-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts-lite
@@ -236,7 +236,7 @@ files:
236
236
  - lib/kuber_kit/actions/service_reader.rb
237
237
  - lib/kuber_kit/actions/template_reader.rb
238
238
  - lib/kuber_kit/artifacts_sync/abstract_artifact_resolver.rb
239
- - lib/kuber_kit/artifacts_sync/artifacts_updater.rb
239
+ - lib/kuber_kit/artifacts_sync/artifact_updater.rb
240
240
  - lib/kuber_kit/artifacts_sync/git_artifact_resolver.rb
241
241
  - lib/kuber_kit/artifacts_sync/null_artifact_resolver.rb
242
242
  - lib/kuber_kit/cli.rb
@@ -306,6 +306,7 @@ files:
306
306
  - lib/kuber_kit/preprocessing/text_preprocessor.rb
307
307
  - lib/kuber_kit/service_deployer/action_handler.rb
308
308
  - lib/kuber_kit/service_deployer/deployer.rb
309
+ - lib/kuber_kit/service_deployer/deployment_options_selector.rb
309
310
  - lib/kuber_kit/service_deployer/service_dependency_resolver.rb
310
311
  - lib/kuber_kit/service_deployer/service_list_resolver.rb
311
312
  - lib/kuber_kit/service_deployer/strategies/abstract.rb
@@ -331,6 +332,7 @@ files:
331
332
  - lib/kuber_kit/template_reader/reader.rb
332
333
  - lib/kuber_kit/template_reader/strategies/abstract.rb
333
334
  - lib/kuber_kit/template_reader/strategies/artifact_file.rb
335
+ - lib/kuber_kit/tools/build_dir_cleaner.rb
334
336
  - lib/kuber_kit/tools/file_presence_checker.rb
335
337
  - lib/kuber_kit/tools/logger_factory.rb
336
338
  - lib/kuber_kit/tools/process_cleaner.rb