kuber_kit 0.1.4 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +4 -2
  3. data/README.md +16 -3
  4. data/TODO.md +4 -4
  5. data/example/app_data/env_file.yml +10 -0
  6. data/example/configurations/review.rb +2 -1
  7. data/example/images/app_sources/Dockerfile +1 -1
  8. data/example/images/ruby_app/image.rb +4 -4
  9. data/example/infrastructure/build_servers.rb +8 -0
  10. data/example/infrastructure/templates.rb +5 -0
  11. data/example/services/env_file.rb +6 -0
  12. data/kuber_kit.gemspec +1 -0
  13. data/lib/kuber_kit.rb +50 -23
  14. data/lib/kuber_kit/actions/configuration_loader.rb +5 -0
  15. data/lib/kuber_kit/actions/env_file_reader.rb +8 -5
  16. data/lib/kuber_kit/actions/image_compiler.rb +18 -22
  17. data/lib/kuber_kit/actions/kubectl_applier.rb +6 -1
  18. data/lib/kuber_kit/actions/service_deployer.rb +13 -3
  19. data/lib/kuber_kit/actions/service_reader.rb +9 -6
  20. data/lib/kuber_kit/actions/template_reader.rb +5 -0
  21. data/lib/kuber_kit/cli.rb +12 -6
  22. data/lib/kuber_kit/configs.rb +24 -22
  23. data/lib/kuber_kit/container.rb +39 -19
  24. data/lib/kuber_kit/core/artifacts/artifact_store.rb +12 -23
  25. data/lib/kuber_kit/core/build_servers/abstract_build_server.rb +21 -0
  26. data/lib/kuber_kit/core/build_servers/build_server.rb +24 -0
  27. data/lib/kuber_kit/core/build_servers/build_server_store.rb +18 -0
  28. data/lib/kuber_kit/core/configuration.rb +14 -4
  29. data/lib/kuber_kit/core/configuration_definition.rb +22 -1
  30. data/lib/kuber_kit/core/configuration_factory.rb +11 -1
  31. data/lib/kuber_kit/core/configuration_store.rb +14 -24
  32. data/lib/kuber_kit/core/context_helper/base_helper.rb +12 -7
  33. data/lib/kuber_kit/core/context_helper/context_helper_factory.rb +11 -8
  34. data/lib/kuber_kit/core/context_helper/service_helper.rb +9 -4
  35. data/lib/kuber_kit/core/env_files/env_file_store.rb +8 -23
  36. data/lib/kuber_kit/core/image_store.rb +8 -18
  37. data/lib/kuber_kit/core/registries/registry_store.rb +8 -23
  38. data/lib/kuber_kit/core/service.rb +19 -3
  39. data/lib/kuber_kit/core/service_definition.rb +7 -0
  40. data/lib/kuber_kit/core/service_factory.rb +5 -1
  41. data/lib/kuber_kit/core/service_store.rb +13 -23
  42. data/lib/kuber_kit/core/store.rb +48 -0
  43. data/lib/kuber_kit/core/templates/template_store.rb +12 -23
  44. data/lib/kuber_kit/env_file_reader/action_handler.rb +12 -0
  45. data/lib/kuber_kit/env_file_reader/reader.rb +4 -4
  46. data/lib/kuber_kit/env_file_reader/{abstract_env_file_reader.rb → strategies/abstract.rb} +1 -1
  47. data/lib/kuber_kit/env_file_reader/{artifact_file_reader.rb → strategies/artifact_file.rb} +1 -1
  48. data/lib/kuber_kit/image_compiler/action_handler.rb +21 -0
  49. data/lib/kuber_kit/image_compiler/build_server_pool.rb +30 -0
  50. data/lib/kuber_kit/image_compiler/build_server_pool_factory.rb +13 -0
  51. data/lib/kuber_kit/image_compiler/compiler.rb +2 -5
  52. data/lib/kuber_kit/image_compiler/image_build_dir_creator.rb +13 -7
  53. data/lib/kuber_kit/image_compiler/image_dependency_resolver.rb +25 -5
  54. data/lib/kuber_kit/preprocessing/file_preprocessor.rb +5 -4
  55. data/lib/kuber_kit/preprocessing/text_preprocessor.rb +1 -1
  56. data/lib/kuber_kit/service_deployer/action_handler.rb +16 -0
  57. data/lib/kuber_kit/service_deployer/deployer.rb +28 -6
  58. data/lib/kuber_kit/service_deployer/strategies/abstract.rb +1 -1
  59. data/lib/kuber_kit/service_deployer/strategies/kubernetes.rb +9 -4
  60. data/lib/kuber_kit/service_deployer/strategy_detector.rb +6 -0
  61. data/lib/kuber_kit/service_reader/action_handler.rb +13 -0
  62. data/lib/kuber_kit/{service_deployer/service_reader.rb → service_reader/reader.rb} +1 -1
  63. data/lib/kuber_kit/shell/abstract_shell.rb +4 -0
  64. data/lib/kuber_kit/shell/{bash_commands.rb → commands/bash_commands.rb} +1 -1
  65. data/lib/kuber_kit/shell/{docker_commands.rb → commands/docker_commands.rb} +1 -1
  66. data/lib/kuber_kit/shell/{git_commands.rb → commands/git_commands.rb} +1 -1
  67. data/lib/kuber_kit/shell/{kubectl_commands.rb → commands/kubectl_commands.rb} +1 -1
  68. data/lib/kuber_kit/shell/{rsync_commands.rb → commands/rsync_commands.rb} +9 -3
  69. data/lib/kuber_kit/shell/local_shell.rb +24 -5
  70. data/lib/kuber_kit/shell/ssh_session.rb +60 -0
  71. data/lib/kuber_kit/shell/ssh_shell.rb +77 -0
  72. data/lib/kuber_kit/tools/file_presence_checker.rb +6 -2
  73. data/lib/kuber_kit/version.rb +1 -1
  74. metadata +40 -13
  75. data/lib/kuber_kit/preprocessing/dir_preprocessor.rb +0 -19
  76. data/lib/kuber_kit/service_deployer/service_restarter.rb +0 -37
  77. data/lib/kuber_kit/tools/files_sync.rb +0 -10
@@ -1,17 +1,20 @@
1
1
  class KuberKit::Actions::ServiceReader
2
2
  include KuberKit::Import[
3
- "core.service_store",
4
- "service_deployer.service_reader",
5
3
  "shell.local_shell",
6
- "ui"
4
+ "ui",
5
+ service_reader: "service_reader.action_handler",
7
6
  ]
8
7
 
9
8
  Contract Symbol, Hash => Any
10
9
  def call(service_name, options)
11
- service = service_store.get_service(service_name)
12
-
13
- result = service_reader.read(local_shell, service)
10
+ result = service_reader.call(local_shell, service_name)
14
11
 
15
12
  ui.print_info(service_name.to_s, result)
13
+
14
+ true
15
+ rescue KuberKit::Error => e
16
+ ui.print_error("Error", e.message)
17
+
18
+ false
16
19
  end
17
20
  end
@@ -13,5 +13,10 @@ class KuberKit::Actions::TemplateReader
13
13
  result = reader.read(local_shell, template)
14
14
 
15
15
  ui.print_info(template_name.to_s, result)
16
+
17
+ true
18
+ rescue KuberKit::Error => e
19
+ ui.print_error("Error", e.message)
20
+ false
16
21
  end
17
22
  end
@@ -15,12 +15,18 @@ class KuberKit::CLI < Thor
15
15
  image_names = image_names_str.split(",").map(&:strip).map(&:to_sym)
16
16
 
17
17
  KuberKit::Container['actions.configuration_loader'].call(options)
18
- KuberKit::Container['actions.image_compiler'].call(image_names, options)
19
-
20
- logger = KuberKit::Container['tools.logger']
21
- logger.info("---------------------------")
22
- logger.info("Image compilation finished!")
23
- logger.info("---------------------------")
18
+ result = KuberKit::Container['actions.image_compiler'].call(image_names, options)
19
+
20
+ if result
21
+ logger = KuberKit::Container['tools.logger']
22
+ logger.info("---------------------------")
23
+ logger.info("Image compilation finished!")
24
+ logger.info("---------------------------")
25
+ else
26
+ logger.info("-------------------------".red)
27
+ logger.info("Image compilation failed!".red)
28
+ logger.info("-------------------------".red)
29
+ end
24
30
  end
25
31
 
26
32
  desc "env ENV_FILE_NAME", "Return content of Env File ENV_FILE_NAME"
@@ -14,33 +14,35 @@ class KuberKit::Configs
14
14
  'tmp',
15
15
  'logs'
16
16
  ]
17
- KUBER_KIT_DIRNAME = "kuber_kit".freeze
18
- IMAGES_DIRNAME = "images".freeze
19
- SERVICES_DIRNAME = "services".freeze
20
- INFRA_DIRNAME = "infrastructure".freeze
21
- CONFIGURATIONS_DIRNAME = "configurations".freeze
22
- ARTIFACT_CLONE_DIR = "/tmp/kuber_kit/artifacts"
23
- SERVICE_CONFIG_DIR = "/tmp/kuber_kit/services"
24
- DEPLOY_STRATEGY = :kubernetes
17
+ KUBER_KIT_DIRNAME = "kuber_kit".freeze
18
+ IMAGES_DIRNAME = "images".freeze
19
+ SERVICES_DIRNAME = "services".freeze
20
+ INFRA_DIRNAME = "infrastructure".freeze
21
+ CONFIGURATIONS_DIRNAME = "configurations".freeze
22
+ ARTIFACT_CLONE_DIR = "/tmp/kuber_kit/artifacts"
23
+ SERVICE_CONFIG_DIR = "/tmp/kuber_kit/services"
24
+ DEPLOY_STRATEGY = :kubernetes
25
+ COMPILE_SIMULTANEOUS_LIMIT = 5
25
26
 
26
27
  attr_accessor :image_dockerfile_name, :image_build_context_dir, :image_tag,
27
28
  :docker_ignore_list, :image_compile_dir,
28
29
  :kuber_kit_dirname, :images_dirname, :services_dirname, :infra_dirname, :configurations_dirname,
29
- :artifact_clone_dir, :service_config_dir, :deploy_strategy
30
+ :artifact_clone_dir, :service_config_dir, :deploy_strategy, :compile_simultaneous_limit
30
31
 
31
32
  def initialize
32
- @image_dockerfile_name = IMAGE_DOCKERFILE_NAME
33
- @image_build_context_dir = IMAGE_BUILD_CONTEXT_DIR
34
- @image_tag = IMAGE_TAG
35
- @image_compile_dir = IMAGE_COMPILE_DIR
36
- @docker_ignore_list = DOCKER_IGNORE_LIST
37
- @kuber_kit_dirname = KUBER_KIT_DIRNAME
38
- @images_dirname = IMAGES_DIRNAME
39
- @services_dirname = SERVICES_DIRNAME
40
- @infra_dirname = INFRA_DIRNAME
41
- @configurations_dirname = CONFIGURATIONS_DIRNAME
42
- @artifact_clone_dir = ARTIFACT_CLONE_DIR
43
- @service_config_dir = SERVICE_CONFIG_DIR
44
- @deploy_strategy = DEPLOY_STRATEGY
33
+ @image_dockerfile_name = IMAGE_DOCKERFILE_NAME
34
+ @image_build_context_dir = IMAGE_BUILD_CONTEXT_DIR
35
+ @image_tag = IMAGE_TAG
36
+ @image_compile_dir = IMAGE_COMPILE_DIR
37
+ @docker_ignore_list = DOCKER_IGNORE_LIST
38
+ @kuber_kit_dirname = KUBER_KIT_DIRNAME
39
+ @images_dirname = IMAGES_DIRNAME
40
+ @services_dirname = SERVICES_DIRNAME
41
+ @infra_dirname = INFRA_DIRNAME
42
+ @configurations_dirname = CONFIGURATIONS_DIRNAME
43
+ @artifact_clone_dir = ARTIFACT_CLONE_DIR
44
+ @service_config_dir = SERVICE_CONFIG_DIR
45
+ @deploy_strategy = DEPLOY_STRATEGY
46
+ @compile_simultaneous_limit = COMPILE_SIMULTANEOUS_LIMIT
45
47
  end
46
48
  end
@@ -69,18 +69,22 @@ class KuberKit::Container
69
69
  KuberKit::Core::ConfigurationStore.new
70
70
  end
71
71
 
72
- register "core.registry_store" do
73
- KuberKit::Core::Registries::RegistryStore.new
74
- end
75
-
76
72
  register "core.artifact_store" do
77
73
  KuberKit::Core::Artifacts::ArtifactStore.new
78
74
  end
79
75
 
76
+ register "core.build_server_store" do
77
+ KuberKit::Core::BuildServers::BuildServerStore.new
78
+ end
79
+
80
80
  register "core.env_file_store" do
81
81
  KuberKit::Core::EnvFiles::EnvFileStore.new
82
82
  end
83
83
 
84
+ register "core.registry_store" do
85
+ KuberKit::Core::Registries::RegistryStore.new
86
+ end
87
+
84
88
  register "core.template_store" do
85
89
  KuberKit::Core::Templates::TemplateStore.new
86
90
  end
@@ -102,23 +106,23 @@ class KuberKit::Container
102
106
  end
103
107
 
104
108
  register "shell.bash_commands" do
105
- KuberKit::Shell::BashCommands.new
109
+ KuberKit::Shell::Commands::BashCommands.new
106
110
  end
107
111
 
108
112
  register "shell.docker_commands" do
109
- KuberKit::Shell::DockerCommands.new
113
+ KuberKit::Shell::Commands::DockerCommands.new
110
114
  end
111
115
 
112
116
  register "shell.git_commands" do
113
- KuberKit::Shell::GitCommands.new
117
+ KuberKit::Shell::Commands::GitCommands.new
114
118
  end
115
119
 
116
120
  register "shell.rsync_commands" do
117
- KuberKit::Shell::RsyncCommands.new
121
+ KuberKit::Shell::Commands::RsyncCommands.new
118
122
  end
119
123
 
120
124
  register "shell.kubectl_commands" do
121
- KuberKit::Shell::KubectlCommands.new
125
+ KuberKit::Shell::Commands::KubectlCommands.new
122
126
  end
123
127
 
124
128
  register "shell.local_shell" do
@@ -137,8 +141,12 @@ class KuberKit::Container
137
141
  KuberKit::Preprocessing::FilePreprocessor.new
138
142
  end
139
143
 
140
- register "preprocessing.dir_preprocessor" do
141
- KuberKit::Preprocessing::DirPreprocessor.new
144
+ register "image_compiler.action_handler" do
145
+ KuberKit::ImageCompiler::ActionHandler.new
146
+ end
147
+
148
+ register "image_compiler.build_server_pool_factory" do
149
+ KuberKit::ImageCompiler::BuildServerPoolFactory.new
142
150
  end
143
151
 
144
152
  register "image_compiler.compiler" do
@@ -173,12 +181,16 @@ class KuberKit::Container
173
181
  KuberKit::ArtifactsSync::NullArtifactResolver.new
174
182
  end
175
183
 
184
+ register "env_file_reader.action_handler" do
185
+ KuberKit::EnvFileReader::ActionHandler.new
186
+ end
187
+
176
188
  register "env_file_reader.reader" do
177
189
  KuberKit::EnvFileReader::Reader.new
178
190
  end
179
191
 
180
- register "env_file_reader.artifact_file_reader" do
181
- KuberKit::EnvFileReader::ArtifactFileReader.new
192
+ register "env_file_reader.strategies.artifact_file" do
193
+ KuberKit::EnvFileReader::Strategies::ArtifactFile.new
182
194
  end
183
195
 
184
196
  register "template_reader.reader" do
@@ -189,16 +201,16 @@ class KuberKit::Container
189
201
  KuberKit::TemplateReader::ArtifactFileReader.new
190
202
  end
191
203
 
192
- register "service_deployer.deployer" do
193
- KuberKit::ServiceDeployer::Deployer.new
204
+ register "service_deployer.action_handler" do
205
+ KuberKit::ServiceDeployer::ActionHandler.new
194
206
  end
195
207
 
196
- register "service_deployer.service_restarter" do
197
- KuberKit::ServiceDeployer::ServiceRestarter.new
208
+ register "service_deployer.strategy_detector" do
209
+ KuberKit::ServiceDeployer::StrategyDetector.new
198
210
  end
199
211
 
200
- register "service_deployer.service_reader" do
201
- KuberKit::ServiceDeployer::ServiceReader.new
212
+ register "service_deployer.deployer" do
213
+ KuberKit::ServiceDeployer::Deployer.new
202
214
  end
203
215
 
204
216
  register "service_deployer.service_list_resolver" do
@@ -209,6 +221,14 @@ class KuberKit::Container
209
221
  KuberKit::ServiceDeployer::Strategies::Kubernetes.new
210
222
  end
211
223
 
224
+ register "service_reader.action_handler" do
225
+ KuberKit::ServiceReader::ActionHandler.new
226
+ end
227
+
228
+ register "service_reader.reader" do
229
+ KuberKit::ServiceReader::Reader.new
230
+ end
231
+
212
232
  register "ui" do
213
233
  if KuberKit.debug_mode?
214
234
  KuberKit::UI::Simple.new
@@ -1,19 +1,6 @@
1
1
  class KuberKit::Core::Artifacts::ArtifactStore
2
- NotFoundError = Class.new(KuberKit::NotFoundError)
3
- AlreadyAddedError = Class.new(KuberKit::Error)
4
-
5
2
  def add(artifact)
6
- @@artifacts ||= {}
7
-
8
- if !artifact.is_a?(KuberKit::Core::Artifacts::AbstractArtifact)
9
- raise ArgumentError.new("should be an instance of KuberKit::Core::Artifacts::AbstractArtifact, got: #{artifact.inspect}")
10
- end
11
-
12
- unless @@artifacts[artifact.name].nil?
13
- raise AlreadyAddedError, "artifact #{artifact.name} was already added"
14
- end
15
-
16
- @@artifacts[artifact.name] = artifact
3
+ store.add(artifact.name, artifact)
17
4
  end
18
5
 
19
6
  def get(artifact_name)
@@ -24,14 +11,7 @@ class KuberKit::Core::Artifacts::ArtifactStore
24
11
  end
25
12
 
26
13
  def get_global(artifact_name)
27
- @@artifacts ||= {}
28
- artifact = @@artifacts[artifact_name]
29
-
30
- if artifact.nil?
31
- raise NotFoundError, "artifact '#{artifact_name}' not found"
32
- end
33
-
34
- artifact
14
+ store.get(artifact_name)
35
15
  end
36
16
 
37
17
  def get_from_configuration(artifact_name)
@@ -40,6 +20,15 @@ class KuberKit::Core::Artifacts::ArtifactStore
40
20
  end
41
21
 
42
22
  def reset!
43
- @@artifacts = {}
23
+ store.reset!
24
+ end
25
+
26
+ def exists?(artifact_name)
27
+ store.exists?(artifact_name)
44
28
  end
29
+
30
+ private
31
+ def store
32
+ @@store ||= KuberKit::Core::Store.new(KuberKit::Core::Artifacts::AbstractArtifact)
33
+ end
45
34
  end
@@ -0,0 +1,21 @@
1
+ class KuberKit::Core::BuildServers::AbstractBuildServer
2
+ include KuberKit::Extensions::Inspectable
3
+
4
+ attr_reader :name
5
+
6
+ def initialize(build_server_name)
7
+ @name = build_server_name
8
+ end
9
+
10
+ def host
11
+ raise KuberKit::NotImplementedError, "must be implemented"
12
+ end
13
+
14
+ def user
15
+ raise KuberKit::NotImplementedError, "must be implemented"
16
+ end
17
+
18
+ def port
19
+ raise KuberKit::NotImplementedError, "must be implemented"
20
+ end
21
+ end
@@ -0,0 +1,24 @@
1
+ class KuberKit::Core::BuildServers::BuildServer < KuberKit::Core::BuildServers::AbstractBuildServer
2
+ def setup(host:, user:, port:)
3
+ @host = host
4
+ @user = user
5
+ @port = port
6
+
7
+ self
8
+ end
9
+
10
+ def host
11
+ raise ArgumentError, "host is not set, please use #setup method" if @host.nil?
12
+ @host
13
+ end
14
+
15
+ def user
16
+ raise ArgumentError, "user is not set, please use #setup method" if @user.nil?
17
+ @user
18
+ end
19
+
20
+ def port
21
+ raise ArgumentError, "port is not set, please use #setup method" if @port.nil?
22
+ @port
23
+ end
24
+ end
@@ -0,0 +1,18 @@
1
+ class KuberKit::Core::BuildServers::BuildServerStore
2
+ def add(build_server)
3
+ store.add(build_server.name, build_server)
4
+ end
5
+
6
+ def get(build_server_name)
7
+ store.get(build_server_name)
8
+ end
9
+
10
+ def reset!
11
+ store.reset!
12
+ end
13
+
14
+ private
15
+ def store
16
+ @@store ||= KuberKit::Core::Store.new(KuberKit::Core::BuildServers::AbstractBuildServer)
17
+ end
18
+ end
@@ -1,5 +1,6 @@
1
1
  class KuberKit::Core::Configuration
2
- attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path, :deploy_strategy
2
+ attr_reader :name, :artifacts, :registries, :env_files, :templates, :kubeconfig_path,
3
+ :deploy_strategy, :services_attributes, :build_servers
3
4
 
4
5
  Contract KeywordArgs[
5
6
  name: Symbol,
@@ -7,10 +8,13 @@ class KuberKit::Core::Configuration
7
8
  registries: Hash,
8
9
  env_files: Hash,
9
10
  templates: Hash,
10
- kubeconfig_path: Maybe[String],
11
- deploy_strategy: Symbol
11
+ kubeconfig_path: Maybe[String],
12
+ deploy_strategy: Symbol,
13
+ services_attributes: HashOf[Symbol => Hash],
14
+ build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer]
12
15
  ] => Any
13
- def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, deploy_strategy:)
16
+ def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:,
17
+ deploy_strategy:, services_attributes:, build_servers:)
14
18
  @name = name
15
19
  @artifacts = artifacts
16
20
  @registries = registries
@@ -18,5 +22,11 @@ class KuberKit::Core::Configuration
18
22
  @templates = templates
19
23
  @kubeconfig_path = kubeconfig_path
20
24
  @deploy_strategy = deploy_strategy
25
+ @services_attributes = services_attributes
26
+ @build_servers = build_servers
27
+ end
28
+
29
+ def service_attributes(service_name)
30
+ services_attributes[service_name.to_sym] || {}
21
31
  end
22
32
  end
@@ -10,6 +10,9 @@ class KuberKit::Core::ConfigurationDefinition
10
10
  @registries = {}
11
11
  @env_files = {}
12
12
  @templates = {}
13
+ @build_servers = []
14
+ @enabled_services = []
15
+ @services_attributes = {}
13
16
  end
14
17
 
15
18
  def to_attrs
@@ -20,7 +23,10 @@ class KuberKit::Core::ConfigurationDefinition
20
23
  env_files: @env_files,
21
24
  templates: @templates,
22
25
  kubeconfig_path: @kubeconfig_path,
23
- deploy_strategy: @deploy_strategy
26
+ deploy_strategy: @deploy_strategy,
27
+ enabled_services: @enabled_services,
28
+ build_servers: @build_servers,
29
+ services_attributes: @services_attributes
24
30
  )
25
31
  end
26
32
 
@@ -60,6 +66,14 @@ class KuberKit::Core::ConfigurationDefinition
60
66
  self
61
67
  end
62
68
 
69
+ def use_build_server(build_server_name)
70
+ unless @build_servers.include?(build_server_name)
71
+ @build_servers.push(build_server_name)
72
+ end
73
+
74
+ self
75
+ end
76
+
63
77
  def kubeconfig_path(path)
64
78
  @kubeconfig_path = path
65
79
 
@@ -71,4 +85,11 @@ class KuberKit::Core::ConfigurationDefinition
71
85
 
72
86
  self
73
87
  end
88
+
89
+ def enabled_services(services_hash)
90
+ @enabled_services += services_hash.keys.map(&:to_sym)
91
+ @services_attributes = @services_attributes.merge(services_hash)
92
+
93
+ self
94
+ end
74
95
  end