kuber_kit 1.1.4 → 1.1.6

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.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +32 -0
  3. data/README.md +2 -1
  4. data/kuber_kit.gemspec +3 -6
  5. data/lib/kuber_kit/actions/configuration_loader.rb +7 -1
  6. data/lib/kuber_kit/actions/kubectl_attacher.rb +7 -4
  7. data/lib/kuber_kit/actions/kubectl_logs.rb +7 -4
  8. data/lib/kuber_kit/actions/service_deployer.rb +33 -26
  9. data/lib/kuber_kit/actions/service_generator.rb +20 -0
  10. data/lib/kuber_kit/artifacts_sync/artifact_updater.rb +19 -9
  11. data/lib/kuber_kit/artifacts_sync/strategies/abstract.rb +9 -0
  12. data/lib/kuber_kit/artifacts_sync/strategies/git_updater.rb +46 -0
  13. data/lib/kuber_kit/artifacts_sync/strategies/null_updater.rb +12 -0
  14. data/lib/kuber_kit/cli.rb +29 -1
  15. data/lib/kuber_kit/configs.rb +3 -1
  16. data/lib/kuber_kit/container.rb +28 -4
  17. data/lib/kuber_kit/core/artifacts/abstract_artifact.rb +4 -0
  18. data/lib/kuber_kit/core/artifacts/git.rb +6 -1
  19. data/lib/kuber_kit/core/artifacts/local.rb +4 -0
  20. data/lib/kuber_kit/core/configuration.rb +10 -6
  21. data/lib/kuber_kit/core/configuration_definition.rb +30 -9
  22. data/lib/kuber_kit/core/configuration_factory.rb +3 -1
  23. data/lib/kuber_kit/core/context_helper/abstract_helper.rb +5 -0
  24. data/lib/kuber_kit/core/context_helper/base_helper.rb +1 -7
  25. data/lib/kuber_kit/core/context_helper/context_helper_factory.rb +3 -1
  26. data/lib/kuber_kit/core/context_helper/context_vars.rb +20 -4
  27. data/lib/kuber_kit/core/context_helper/local_context_helper.rb +14 -0
  28. data/lib/kuber_kit/core/context_helper/service_helper.rb +15 -1
  29. data/lib/kuber_kit/core/dependencies/abstract_dependency_resolver.rb +7 -0
  30. data/lib/kuber_kit/core/service.rb +8 -5
  31. data/lib/kuber_kit/core/service_definition.rb +16 -4
  32. data/lib/kuber_kit/core/service_factory.rb +2 -1
  33. data/lib/kuber_kit/defaults.rb +13 -4
  34. data/lib/kuber_kit/image_compiler/image_builder.rb +1 -1
  35. data/lib/kuber_kit/service_deployer/service_dependency_resolver.rb +1 -1
  36. data/lib/kuber_kit/service_deployer/strategies/helm.rb +41 -0
  37. data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +8 -2
  38. data/lib/kuber_kit/service_generator/action_handler.rb +16 -0
  39. data/lib/kuber_kit/service_generator/generator.rb +26 -0
  40. data/lib/kuber_kit/service_generator/strategies/abstract.rb +5 -0
  41. data/lib/kuber_kit/service_generator/strategies/helm.rb +33 -0
  42. data/lib/kuber_kit/service_generator/strategy_detector.rb +6 -0
  43. data/lib/kuber_kit/service_reader/reader.rb +2 -10
  44. data/lib/kuber_kit/shell/commands/docker_commands.rb +1 -1
  45. data/lib/kuber_kit/shell/commands/git_commands.rb +10 -0
  46. data/lib/kuber_kit/shell/commands/helm_commands.rb +42 -0
  47. data/lib/kuber_kit/shell/commands/kubectl_commands.rb +3 -2
  48. data/lib/kuber_kit/shell/local_shell.rb +1 -1
  49. data/lib/kuber_kit/shell_launcher/strategies/kubernetes.rb +1 -1
  50. data/lib/kuber_kit/template_reader/reader.rb +1 -0
  51. data/lib/kuber_kit/template_reader/renderer.rb +17 -0
  52. data/lib/kuber_kit/template_reader/strategies/artifact_file.rb +1 -0
  53. data/lib/kuber_kit/tools/logger_factory.rb +1 -1
  54. data/lib/kuber_kit/version.rb +1 -1
  55. data/lib/kuber_kit.rb +23 -3
  56. metadata +35 -10
  57. data/lib/kuber_kit/artifacts_sync/abstract_artifact_resolver.rb +0 -5
  58. data/lib/kuber_kit/artifacts_sync/git_artifact_resolver.rb +0 -31
  59. data/lib/kuber_kit/artifacts_sync/null_artifact_resolver.rb +0 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b70bdef220e67c9789122ab7eb7ee064dff475174ec1e497b0baf11566da6e1f
4
- data.tar.gz: 004b9a6c4e8265f1f3f498b1b42fa35a0447567ef428abef4b571cce635c0cd9
3
+ metadata.gz: fffaf809577e0796e0b18bcc8d61894276308e5792ba1e3c67b7d792dce32d0a
4
+ data.tar.gz: 73470e476a996467fe60b6e6966b9821e14f75492d0b53aee231db21995dfeb8
5
5
  SHA512:
6
- metadata.gz: 1e60b51c8108814fc41f89b41a28732e59a8f5bddb938ee94d8cb765ccc5f2ea3de260aed0a52a212649389814884c40734c7f60fe77502e78e3814821c31790
7
- data.tar.gz: 5f165249b8d91cd8bc148f9cc5f3a3a9a57402355c371b30f7f8511fcb6bf8d0650a7ba7a08c072dcba550837e52aced3a1d9cec4959be98c18d5b526678fb29
6
+ metadata.gz: 13a911f81ba63ff223073ffa2d4363827a5334b08bd8d99ea027b5de0d135a4b4323b87ddaf650dc1e63e7515022cd4ca119c968a12b1c7adb6a2a3ef897feff
7
+ data.tar.gz: b26560006e1c3c27cbf4a25363a8c4e3a5ebf673f55ffc549e9bf4d415023eec8e6b18cc8052859bde4efb24fe9d0d1a82ff55d9e0ead9284c68a4959b02f225
data/CHANGELOG.md CHANGED
@@ -1,3 +1,35 @@
1
+ **1.3.3**
2
+ - Support "partials" in the templates with "render" method.
3
+ - Cleanup artifacts after deployment if cache_result: false
4
+ - Improve fetching git artifact when branch name has changed
5
+
6
+ **1.3.2**
7
+ - Added an ability to generate helm templates using `kit generate` command
8
+
9
+ **1.3.1**
10
+ - Fix upgrade command for helm strategy
11
+
12
+ **1.3.0**
13
+ - Allow sending custom apply command for k8s deploy strategy
14
+ - Added initial support for helm deploy strategy
15
+
16
+ **1.2.7**
17
+ - Added an option to skip deployment and only build images for `deploy` command
18
+
19
+ **1.2.6**
20
+ - Lock cli-ui version on 2.1.0 (2.2.x has some bugs)
21
+
22
+ **1.2.5**
23
+ - Improve handling ContextVars, ability to convert context var to OpenStruct
24
+
25
+ **1.2.4**
26
+ - Fix a mistake in setting env variables
27
+ - Added an option to set "use local deployment" variable
28
+ - Allow finding job resources in kit attach and kit log
29
+
30
+ **1.2.2**
31
+ - Support Ruby 3.2.0
32
+
1
33
  **1.2.1**
2
34
  - Update shell commands so that STDERR stream won't be merged for commands using the command result.
3
35
  - kit sh would also set current default configuration
data/README.md CHANGED
@@ -19,7 +19,8 @@ Please install specific kuber_kit version, depending on Ruby version.
19
19
  | Ruby Version | KuberKit Version |
20
20
  | ------------ | ------------ |
21
21
  | 2.6 | 1.0.1 |
22
- | 2.7 | 1.1.4 |
22
+ | 2.7 | 1.1.5 |
23
+ | > 3.0 | 1.2.6 |
23
24
 
24
25
  ## Usage
25
26
 
data/kuber_kit.gemspec CHANGED
@@ -25,11 +25,7 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.required_ruby_version = ">= 2.7.0"
27
27
 
28
- if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
29
- spec.add_dependency "contracts", '0.17.0'
30
- else
31
- spec.add_dependency "contracts", '0.16.0'
32
- end
28
+ spec.add_dependency "contracts", '0.16.0'
33
29
 
34
30
  spec.add_dependency "dry-auto_inject", "~> 0.9.0"
35
31
  spec.add_dependency "dry-core", "~> 0.8.1"
@@ -37,9 +33,10 @@ Gem::Specification.new do |spec|
37
33
  spec.add_dependency "dry-container", "~> 0.10.1"
38
34
 
39
35
  spec.add_dependency "thor"
40
- spec.add_dependency "cli-ui"
36
+ spec.add_dependency "cli-ui", '2.1.0'
41
37
  spec.add_dependency "net-ssh"
42
38
  spec.add_dependency "tty-prompt"
39
+ spec.add_dependency 'ed25519'
43
40
 
44
41
  spec.add_development_dependency "bundler", "~> 2.2"
45
42
  spec.add_development_dependency "rake", "~> 10.0"
@@ -20,6 +20,7 @@ class KuberKit::Actions::ConfigurationLoader
20
20
  configurations_path = options[:configurations_path] || File.join(root_path, configs.configurations_dirname)
21
21
  configuration_name = options[:configuration] || ENV["KUBER_KIT_CONFIGURATION"]
22
22
  load_inventory = options.fetch(:load_inventory, true)
23
+ use_local_deploy = options.fetch(:use_local_deploy, false)
23
24
 
24
25
  ui.print_debug "ConfigurationLoader", "Launching kuber_kit with:"
25
26
  ui.print_debug "ConfigurationLoader", " Root path: #{root_path.to_s.yellow}"
@@ -28,10 +29,11 @@ class KuberKit::Actions::ConfigurationLoader
28
29
  ui.print_debug "ConfigurationLoader", " Infrastructure path: #{infra_path.to_s.yellow}"
29
30
  ui.print_debug "ConfigurationLoader", " Configurations path: #{configurations_path.to_s.yellow}"
30
31
  ui.print_debug "ConfigurationLoader", " Configuration name: #{configuration_name.to_s.yellow}"
32
+ ui.print_debug "ConfigurationLoader", " Use local deploy: #{use_local_deploy.to_s.yellow}"
31
33
 
32
34
  ui.print_info("Logs", "See logs at: #{configs.log_file_path}")
33
35
 
34
- unless File.exists?(root_path)
36
+ unless File.exist?(root_path)
35
37
  ui.print_warning "ConfigurationLoader", "KuberKit root path #{root_path} doesn't exist. You may want to pass it --path parameter."
36
38
  end
37
39
 
@@ -39,6 +41,10 @@ class KuberKit::Actions::ConfigurationLoader
39
41
  raise KuberKit::Error, "The minimal required kuber_kit version is #{configs.kuber_kit_min_version}"
40
42
  end
41
43
 
44
+ if use_local_deploy
45
+ ENV["KUBER_KIT_USE_LOCAL_DEPLOYMENT"] = "true"
46
+ end
47
+
42
48
  load_configurations(configurations_path, configuration_name)
43
49
  load_infrastructure(infra_path)
44
50
 
@@ -7,17 +7,20 @@ class KuberKit::Actions::KubectlAttacher
7
7
  ]
8
8
 
9
9
  Contract Maybe[String], Hash => Any
10
- def call(pod_name, options)
10
+ def call(resource_name, options)
11
11
  kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
12
12
  kubectl_entrypoint = KuberKit.current_configuration.kubectl_entrypoint
13
13
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
14
14
 
15
- if !pod_name
16
- pod_name = resource_selector.call("attach")
15
+ if !resource_name
16
+ resource_name = resource_selector.call("attach", additional_resources: [
17
+ KuberKit::Kubernetes::Resources::POD,
18
+ KuberKit::Kubernetes::Resources::JOB
19
+ ])
17
20
  end
18
21
 
19
22
  kubectl_commands.exec(
20
- local_shell, pod_name, "bash", args: "-it",
23
+ local_shell, resource_name, "bash", args: "-it",
21
24
  kubeconfig_path: kubeconfig_path,
22
25
  interactive: true,
23
26
  namespace: deployer_namespace,
@@ -7,12 +7,15 @@ class KuberKit::Actions::KubectlLogs
7
7
  ]
8
8
 
9
9
  Contract Maybe[String], Hash => Any
10
- def call(pod_name, options)
10
+ def call(resource_name, options)
11
11
  kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
12
12
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
13
13
 
14
- if !pod_name
15
- pod_name = resource_selector.call("attach")
14
+ if !resource_name
15
+ resource_name = resource_selector.call("attach", additional_resources: [
16
+ KuberKit::Kubernetes::Resources::POD,
17
+ KuberKit::Kubernetes::Resources::JOB
18
+ ])
16
19
  end
17
20
 
18
21
  args = nil
@@ -21,7 +24,7 @@ class KuberKit::Actions::KubectlLogs
21
24
  end
22
25
 
23
26
  kubectl_commands.logs(
24
- local_shell, pod_name,
27
+ local_shell, resource_name,
25
28
  args: args,
26
29
  kubeconfig_path: kubeconfig_path,
27
30
  namespace: deployer_namespace
@@ -29,11 +29,11 @@ class KuberKit::Actions::ServiceDeployer
29
29
  services, tags = deployment_options_selector.call()
30
30
  end
31
31
 
32
- disabled_services = current_configuration.disabled_services.map(&:to_s)
33
- disabled_services += skip_services if skip_services
34
- default_services = current_configuration.default_services.map(&:to_s) - disabled_services
35
- initial_services = current_configuration.initial_services.map(&:to_s) - disabled_services
36
- initial_service_names = initial_services.map(&:to_sym)
32
+ disabled_services = current_configuration.disabled_services.map(&:to_s)
33
+ disabled_services += skip_services if skip_services
34
+ default_services = current_configuration.default_services.map(&:to_s) - disabled_services
35
+ pre_deploy_services = current_configuration.pre_deploy_services.map(&:to_s) - disabled_services
36
+ post_deploy_services = current_configuration.post_deploy_services.map(&:to_s) - disabled_services
37
37
 
38
38
  service_names = service_list_resolver.resolve(
39
39
  services: services || [],
@@ -50,17 +50,19 @@ class KuberKit::Actions::ServiceDeployer
50
50
  all_service_names = service_dependency_resolver.get_all(service_names)
51
51
  end
52
52
 
53
+ all_service_names_with_hooks = (pre_deploy_services.map(&:to_sym) + all_service_names + post_deploy_services.map(&:to_sym)).uniq
54
+
53
55
  unless all_service_names.any?
54
56
  ui.print_warning "ServiceDeployer", "No service found with given options, nothing will be deployed."
55
57
  return false
56
58
  end
57
59
 
58
- unless allow_deployment?(require_confirmation: require_confirmation, service_names: (initial_service_names + all_service_names).uniq)
60
+ unless allow_deployment?(require_confirmation: require_confirmation, service_names: all_service_names_with_hooks)
59
61
  return false
60
62
  end
61
63
 
62
64
  # Compile images for all services and dependencies
63
- images_names = get_image_names(service_names: (initial_service_names + all_service_names).uniq)
65
+ images_names = get_image_names(service_names: all_service_names_with_hooks.uniq)
64
66
  unless skip_compile
65
67
  compilation_result = compile_images(images_names)
66
68
 
@@ -72,33 +74,31 @@ class KuberKit::Actions::ServiceDeployer
72
74
  return deployment_result
73
75
  end
74
76
 
75
- # First deploy initial services.
77
+ # First, deploy pre-deploy services.
76
78
  # This feature is used to deploy some services, required for deployment of other services, e.g. env files
77
79
  # Note: Initial services are deployed without dependencies
78
- initial_services.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
79
- ui.print_debug("ServiceDeployer", "Scheduling to compile: #{batch_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
80
+ pre_deploy_services.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
81
+ deploy_simultaneously(batch_service_names, deployment_result)
82
+ end
80
83
 
81
- if deployment_result.succeeded?
84
+ # Next, deploy all initializers simultaneously.
85
+ # Note: In earlier versions, KuberKit would deploy all dependencies in the order defined by dependency tree.
86
+ # Now it would deploy all dependencies (initializers) at the same time, even if one initializer depends on another initializer.
87
+ unless skip_dependencies
88
+ initializers = service_dependency_resolver.get_all_deps(service_names)
89
+ initializers.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
82
90
  deploy_simultaneously(batch_service_names, deployment_result)
83
91
  end
84
92
  end
85
93
 
86
- if skip_dependencies
87
- service_names.each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
88
- ui.print_debug("ServiceDeployer", "Scheduling to deploy: #{batch_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
89
-
90
- if deployment_result.succeeded?
91
- deploy_simultaneously(batch_service_names, deployment_result)
92
- end
93
- end
94
- else
95
- service_dependency_resolver.each_with_deps(service_names) do |dep_service_names|
96
- ui.print_debug("ServiceDeployer", "Scheduling to deploy: #{dep_service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
94
+ # Next, deploy all requested services.
95
+ service_names.each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
96
+ deploy_simultaneously(batch_service_names, deployment_result)
97
+ end
97
98
 
98
- if deployment_result.succeeded?
99
- deploy_simultaneously(dep_service_names, deployment_result)
100
- end
101
- end
99
+ # Last, deploy post-deploy services.
100
+ post_deploy_services.map(&:to_sym).each_slice(configs.deploy_simultaneous_limit) do |batch_service_names|
101
+ deploy_simultaneously(batch_service_names, deployment_result)
102
102
  end
103
103
 
104
104
  deployment_result
@@ -116,6 +116,13 @@ class KuberKit::Actions::ServiceDeployer
116
116
 
117
117
  private
118
118
  def deploy_simultaneously(service_names, deployment_result)
119
+ unless deployment_result.succeeded?
120
+ ui.print_debug("ServiceDeployer", "Deploymet already failed. Canceling: #{service_names.inspect}")
121
+ return
122
+ end
123
+
124
+ ui.print_debug("ServiceDeployer", "Scheduling to deploy: #{service_names.inspect}. Limit: #{configs.deploy_simultaneous_limit}")
125
+
119
126
  task_group = ui.create_task_group
120
127
 
121
128
  service_names.each do |service_name|
@@ -0,0 +1,20 @@
1
+ class KuberKit::Actions::ServiceGenerator
2
+ include KuberKit::Import[
3
+ "shell.local_shell",
4
+ "service_generator.action_handler",
5
+ "ui",
6
+ ]
7
+
8
+ Contract Symbol, String => Any
9
+ def call(service_name, path)
10
+ expanded_path = File.expand_path(path)
11
+ puts expanded_path
12
+ action_handler.call(local_shell, service_name, expanded_path)
13
+
14
+ true
15
+ rescue KuberKit::Error => e
16
+ ui.print_error("Error", e.message)
17
+
18
+ false
19
+ end
20
+ end
@@ -1,27 +1,37 @@
1
1
  class KuberKit::ArtifactsSync::ArtifactUpdater
2
- ResolverNotFoundError = Class.new(KuberKit::NotFoundError)
2
+ StrategyNotFoundError = Class.new(KuberKit::NotFoundError)
3
3
 
4
4
  include KuberKit::Import[
5
5
  "ui"
6
6
  ]
7
7
 
8
- def use_resolver(artifact_resolver, artifact_class:)
9
- @@resolvers ||= {}
8
+ def use_strategy(strategy, artifact_class:)
9
+ @@strategies ||= {}
10
10
 
11
- if !artifact_resolver.is_a?(KuberKit::ArtifactsSync::AbstractArtifactResolver)
12
- raise ArgumentError.new("should be an instance of KuberKit::ArtifactsSync::AbstractArtifactResolver, got: #{artifact_resolver.inspect}")
11
+ if !strategy.is_a?(KuberKit::ArtifactsSync::Strategies::Abstract)
12
+ raise ArgumentError.new("should be an instance of KuberKit::ArtifactsSync::Strategies::Abstract, got: #{strategy.inspect}")
13
13
  end
14
14
 
15
- @@resolvers[artifact_class] = artifact_resolver
15
+ @@strategies[artifact_class] = strategy
16
16
  end
17
17
 
18
18
  def update(shell, artifact)
19
- resolver = @@resolvers[artifact.class]
19
+ strategy = @@strategies[artifact.class]
20
20
 
21
21
  ui.print_debug "ArtifactUpdater", "Updating artifact #{artifact.name.to_s.green}"
22
22
 
23
- raise ResolverNotFoundError, "Can't find resolver for artifact #{artifact}" if resolver.nil?
23
+ raise StrategyNotFoundError, "Can't find strategy for artifact #{artifact}" if strategy.nil?
24
24
 
25
- resolver.resolve(shell, artifact)
25
+ strategy.update(shell, artifact)
26
+ end
27
+
28
+ def cleanup(shell, artifact)
29
+ strategy = @@strategies[artifact.class]
30
+
31
+ ui.print_debug "ArtifactUpdater", "Cleaning artifact #{artifact.name.to_s.green}"
32
+
33
+ raise StrategyNotFoundError, "Can't find strategy for artifact #{artifact}" if strategy.nil?
34
+
35
+ strategy.cleanup(shell, artifact)
26
36
  end
27
37
  end
@@ -0,0 +1,9 @@
1
+ class KuberKit::ArtifactsSync::Strategies::Abstract
2
+ def update(shell, artifact)
3
+ raise KuberKit::NotImplementedError, "must be implemented"
4
+ end
5
+
6
+ def cleanup(shell, artifact)
7
+ raise KuberKit::NotImplementedError, "must be implemented"
8
+ end
9
+ end
@@ -0,0 +1,46 @@
1
+ class KuberKit::ArtifactsSync::Strategies::GitUpdater < KuberKit::ArtifactsSync::Strategies::Abstract
2
+
3
+ include KuberKit::Import[
4
+ "shell.git_commands",
5
+ "shell.bash_commands",
6
+ ]
7
+
8
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Artifacts::Git => Any
9
+ def update(shell, artifact)
10
+ already_cloned = artifact_already_cloned?(
11
+ shell: shell,
12
+ repo_path: artifact.cloned_path,
13
+ artifact: artifact
14
+ )
15
+
16
+ if already_cloned
17
+ git_commands.force_pull_repo(shell,
18
+ path: artifact.cloned_path, branch: artifact.branch
19
+ )
20
+ else
21
+ git_commands.download_repo(shell,
22
+ remote_url: artifact.remote_url, path: artifact.cloned_path, branch: artifact.branch
23
+ )
24
+ end
25
+ end
26
+
27
+ Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Artifacts::Git => Any
28
+ def cleanup(shell, artifact)
29
+ bash_commands.rm_rf(shell, artifact.cloned_path)
30
+ end
31
+
32
+ private
33
+ def artifact_already_cloned?(shell:, repo_path:, artifact:)
34
+ target_remote_url = git_commands.get_remote_url(shell, repo_path)
35
+ if target_remote_url != artifact.remote_url
36
+ return false
37
+ end
38
+
39
+ target_branch = git_commands.get_branch_name(shell, repo_path)
40
+ if target_branch != artifact.branch
41
+ return false
42
+ end
43
+
44
+ return true
45
+ end
46
+ end
@@ -0,0 +1,12 @@
1
+ class KuberKit::ArtifactsSync::Strategies::NullUpdater < KuberKit::ArtifactsSync::Strategies::Abstract
2
+
3
+ Contract KuberKit::Shell::AbstractShell, Any => Any
4
+ def update(shell, artifact)
5
+ return true
6
+ end
7
+
8
+ Contract KuberKit::Shell::AbstractShell, Any => Any
9
+ def cleanup(shell, artifact)
10
+ return true
11
+ end
12
+ end
data/lib/kuber_kit/cli.rb CHANGED
@@ -11,6 +11,7 @@ class KuberKit::CLI < Thor
11
11
  class_option :debug, :type => :boolean, aliases: ["-d"]
12
12
  class_option :configuration, :type => :string, aliases: ["-C"]
13
13
  class_option :user, :type => :string, aliases: ["-u"]
14
+ class_option :use_local_deploy, :type => :boolean, aliases: ["-l"]
14
15
 
15
16
  desc "compile IMAGE_NAMES", "Compile image with IMAGE_NAMES (comma-separated)"
16
17
  def compile(image_names_str)
@@ -23,6 +24,8 @@ class KuberKit::CLI < Thor
23
24
  action_result = KuberKit::Container['actions.image_compiler'].call(image_names, options)
24
25
  end
25
26
 
27
+ clean_artifacts(options)
28
+
26
29
  if action_result && action_result.succeeded?
27
30
  time = (Time.now.to_i - started_at)
28
31
  print_result("Image compilation finished! (#{time}s)", result: {
@@ -63,6 +66,8 @@ class KuberKit::CLI < Thor
63
66
  )
64
67
  end
65
68
 
69
+ clean_artifacts(options)
70
+
66
71
  if action_result && action_result.succeeded?
67
72
  time = (Time.now.to_i - started_at)
68
73
  print_result("Service deployment finished! (#{time}s)", result: {
@@ -110,6 +115,16 @@ class KuberKit::CLI < Thor
110
115
  end
111
116
  end
112
117
 
118
+
119
+ desc "generate SERVICE_NAME PATH_NAME", "Generates a template for a given service in a given path"
120
+ def generate(service_name, path)
121
+ setup(options)
122
+
123
+ if KuberKit::Container['actions.configuration_loader'].call(options)
124
+ KuberKit::Container['actions.service_generator'].call(service_name.to_sym, path)
125
+ end
126
+ end
127
+
113
128
  desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
114
129
  def apply(file_path)
115
130
  setup(options)
@@ -211,7 +226,7 @@ class KuberKit::CLI < Thor
211
226
  # We should load config before loading any bean, to make sure that bean won't be built with default config
212
227
  root_path = KuberKit::Container['tools.workdir_detector'].call(options)
213
228
  config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
214
- if File.exists?(config_file_path)
229
+ if File.exist?(config_file_path)
215
230
  require config_file_path
216
231
  end
217
232
  end
@@ -219,4 +234,17 @@ class KuberKit::CLI < Thor
219
234
  def print_result(message, data = {})
220
235
  KuberKit::Container['ui'].print_result(message, data)
221
236
  end
237
+
238
+ def clean_artifacts(options)
239
+ artifacts = KuberKit.current_configuration.artifacts.values
240
+ artifacts_to_clean = artifacts.select(&:cleanup_needed?)
241
+
242
+ return unless artifacts_to_clean.any?
243
+
244
+ artifacts_to_clean.each do |artifact|
245
+ KuberKit::Container['artifacts_sync.artifact_updater'].cleanup(
246
+ KuberKit::Container['shell.local_shell'], artifact
247
+ )
248
+ end
249
+ end
222
250
  end
@@ -5,7 +5,8 @@ class KuberKit::Configs
5
5
  :image_dockerfile_name, :image_build_context_dir, :image_tag, :docker_ignore_list, :image_compile_dir, :remote_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, :env_file_compile_dir, :shell_launcher_strategy, :shell_launcher_sets_configration
8
+ :additional_images_paths, :deprecation_warnings_disabled, :log_file_path, :env_file_compile_dir, :shell_launcher_strategy,
9
+ :shell_launcher_sets_configration, :generator_strategy
9
10
  ]
10
11
  DOCKER_IGNORE_LIST = [
11
12
  'Dockerfile',
@@ -60,6 +61,7 @@ class KuberKit::Configs
60
61
  set :log_file_path, File.join(absolute_kuber_kit_path, "deploy.log")
61
62
  set :env_file_compile_dir, File.join(absolute_kuber_kit_path, "env_files")
62
63
  set :shell_launcher_sets_configration, true
64
+ set :generator_strategy, :helm
63
65
  end
64
66
 
65
67
  def items
@@ -25,6 +25,10 @@ class KuberKit::Container
25
25
  KuberKit::Actions::ServiceChecker.new
26
26
  end
27
27
 
28
+ register "actions.service_generator" do
29
+ KuberKit::Actions::ServiceGenerator.new
30
+ end
31
+
28
32
  register "actions.configuration_loader" do
29
33
  KuberKit::Actions::ConfigurationLoader.new
30
34
  end
@@ -181,6 +185,10 @@ class KuberKit::Container
181
185
  KuberKit::Shell::Commands::SystemCommands.new
182
186
  end
183
187
 
188
+ register "shell.helm_commands" do
189
+ KuberKit::Shell::Commands::HelmCommands.new
190
+ end
191
+
184
192
  register "shell.local_shell" do
185
193
  KuberKit::Shell::LocalShell.new
186
194
  end
@@ -229,12 +237,12 @@ class KuberKit::Container
229
237
  KuberKit::ArtifactsSync::ArtifactUpdater.new
230
238
  end
231
239
 
232
- register "artifacts_sync.git_artifact_resolver" do
233
- KuberKit::ArtifactsSync::GitArtifactResolver.new
240
+ register "artifacts_sync.strategies.git_updater" do
241
+ KuberKit::ArtifactsSync::Strategies::GitUpdater.new
234
242
  end
235
243
 
236
- register "artifacts_sync.null_artifact_resolver" do
237
- KuberKit::ArtifactsSync::NullArtifactResolver.new
244
+ register "artifacts_sync.strategies.null_updater" do
245
+ KuberKit::ArtifactsSync::Strategies::NullUpdater.new
238
246
  end
239
247
 
240
248
  register "env_file_reader.action_handler" do
@@ -269,6 +277,10 @@ class KuberKit::Container
269
277
  KuberKit::TemplateReader::Reader.new
270
278
  end
271
279
 
280
+ register "template_reader.renderer" do
281
+ KuberKit::TemplateReader::Renderer.new
282
+ end
283
+
272
284
  register "template_reader.strategies.artifact_file" do
273
285
  KuberKit::TemplateReader::Strategies::ArtifactFile.new
274
286
  end
@@ -297,6 +309,18 @@ class KuberKit::Container
297
309
  KuberKit::ServiceDeployer::ServiceDependencyResolver.new
298
310
  end
299
311
 
312
+ register "service_generator.action_handler" do
313
+ KuberKit::ServiceGenerator::ActionHandler.new
314
+ end
315
+
316
+ register "service_generator.strategy_detector" do
317
+ KuberKit::ServiceGenerator::StrategyDetector.new
318
+ end
319
+
320
+ register "service_generator.generator" do
321
+ KuberKit::ServiceGenerator::Generator.new
322
+ end
323
+
300
324
  register "service_reader.action_handler" do
301
325
  KuberKit::ServiceReader::ActionHandler.new
302
326
  end
@@ -14,4 +14,8 @@ class KuberKit::Core::Artifacts::AbstractArtifact
14
14
  def sync_description
15
15
  raise KuberKit::NotImplementedError, "must be implemented"
16
16
  end
17
+
18
+ def cleanup_needed?
19
+ raise KuberKit::NotImplementedError, "must be implemented"
20
+ end
17
21
  end
@@ -5,12 +5,13 @@ class KuberKit::Core::Artifacts::Git < KuberKit::Core::Artifacts::AbstractArtifa
5
5
  DEFAULT_REMOTE_NAME = "origin"
6
6
  DEFAULT_BRANCH = "master"
7
7
 
8
- def setup(remote_url:, remote_name: DEFAULT_REMOTE_NAME, branch: DEFAULT_BRANCH, clone_path: nil, ssh_key: DEFAULT_SSH_KEY)
8
+ def setup(remote_url:, remote_name: DEFAULT_REMOTE_NAME, branch: DEFAULT_BRANCH, clone_path: nil, ssh_key: DEFAULT_SSH_KEY, cache_result: true)
9
9
  @remote_name = remote_name
10
10
  @remote_url = remote_url
11
11
  @branch = branch
12
12
  @clone_path = clone_path
13
13
  @ssh_key = ssh_key
14
+ @cache_result = cache_result
14
15
  self
15
16
  end
16
17
 
@@ -23,4 +24,8 @@ class KuberKit::Core::Artifacts::Git < KuberKit::Core::Artifacts::AbstractArtifa
23
24
  def sync_description
24
25
  "#{remote_url}:#{branch}"
25
26
  end
27
+
28
+ def cleanup_needed?
29
+ !@cache_result
30
+ end
26
31
  end
@@ -15,4 +15,8 @@ class KuberKit::Core::Artifacts::Local < KuberKit::Core::Artifacts::AbstractArti
15
15
  def sync_description
16
16
  "local"
17
17
  end
18
+
19
+ def cleanup_needed?
20
+ false
21
+ end
18
22
  end