kuber_kit 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +3 -1
  3. data/README.md +16 -3
  4. data/TODO.md +1 -3
  5. data/example/configurations/review.rb +2 -1
  6. data/example/images/app_sources/Dockerfile +1 -1
  7. data/example/images/ruby_app/image.rb +4 -4
  8. data/example/infrastructure/build_servers.rb +8 -0
  9. data/kuber_kit.gemspec +1 -0
  10. data/lib/kuber_kit.rb +36 -19
  11. data/lib/kuber_kit/actions/configuration_loader.rb +3 -0
  12. data/lib/kuber_kit/actions/env_file_reader.rb +3 -0
  13. data/lib/kuber_kit/actions/image_compiler.rb +14 -10
  14. data/lib/kuber_kit/actions/kubectl_applier.rb +4 -1
  15. data/lib/kuber_kit/actions/service_deployer.rb +4 -0
  16. data/lib/kuber_kit/actions/service_reader.rb +4 -0
  17. data/lib/kuber_kit/actions/template_reader.rb +3 -0
  18. data/lib/kuber_kit/cli.rb +12 -6
  19. data/lib/kuber_kit/configs.rb +24 -22
  20. data/lib/kuber_kit/container.rb +17 -13
  21. data/lib/kuber_kit/core/artifacts/artifact_store.rb +9 -28
  22. data/lib/kuber_kit/core/build_servers/abstract_build_server.rb +21 -0
  23. data/lib/kuber_kit/core/build_servers/build_server.rb +24 -0
  24. data/lib/kuber_kit/core/build_servers/build_server_store.rb +18 -0
  25. data/lib/kuber_kit/core/configuration.rb +7 -3
  26. data/lib/kuber_kit/core/configuration_definition.rb +10 -0
  27. data/lib/kuber_kit/core/configuration_factory.rb +10 -1
  28. data/lib/kuber_kit/core/configuration_store.rb +14 -24
  29. data/lib/kuber_kit/core/env_files/env_file_store.rb +8 -23
  30. data/lib/kuber_kit/core/image_store.rb +8 -18
  31. data/lib/kuber_kit/core/registries/registry_store.rb +8 -23
  32. data/lib/kuber_kit/core/service_store.rb +13 -23
  33. data/lib/kuber_kit/core/store.rb +48 -0
  34. data/lib/kuber_kit/core/templates/template_store.rb +9 -28
  35. data/lib/kuber_kit/image_compiler/build_server_pool.rb +30 -0
  36. data/lib/kuber_kit/image_compiler/build_server_pool_factory.rb +13 -0
  37. data/lib/kuber_kit/image_compiler/image_build_dir_creator.rb +13 -7
  38. data/lib/kuber_kit/image_compiler/image_dependency_resolver.rb +25 -5
  39. data/lib/kuber_kit/preprocessing/file_preprocessor.rb +5 -4
  40. data/lib/kuber_kit/shell/abstract_shell.rb +4 -0
  41. data/lib/kuber_kit/shell/{bash_commands.rb → commands/bash_commands.rb} +1 -1
  42. data/lib/kuber_kit/shell/{docker_commands.rb → commands/docker_commands.rb} +1 -1
  43. data/lib/kuber_kit/shell/{git_commands.rb → commands/git_commands.rb} +1 -1
  44. data/lib/kuber_kit/shell/{kubectl_commands.rb → commands/kubectl_commands.rb} +1 -1
  45. data/lib/kuber_kit/shell/{rsync_commands.rb → commands/rsync_commands.rb} +9 -3
  46. data/lib/kuber_kit/shell/local_shell.rb +24 -5
  47. data/lib/kuber_kit/shell/ssh_session.rb +60 -0
  48. data/lib/kuber_kit/shell/ssh_shell.rb +77 -0
  49. data/lib/kuber_kit/tools/file_presence_checker.rb +6 -2
  50. data/lib/kuber_kit/version.rb +1 -1
  51. metadata +30 -9
  52. data/lib/kuber_kit/preprocessing/dir_preprocessor.rb +0 -19
  53. data/lib/kuber_kit/tools/files_sync.rb +0 -10
@@ -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,14 +20,15 @@ class KuberKit::Core::Artifacts::ArtifactStore
40
20
  end
41
21
 
42
22
  def reset!
43
- @@artifacts = {}
44
- end
45
-
46
- def all_definitions
47
- @@artifacts ||= {}
23
+ store.reset!
48
24
  end
49
25
 
50
26
  def exists?(artifact_name)
51
- !all_definitions[artifact_name].nil?
27
+ store.exists?(artifact_name)
52
28
  end
29
+
30
+ private
31
+ def store
32
+ @@store ||= KuberKit::Core::Store.new(KuberKit::Core::Artifacts::AbstractArtifact)
33
+ end
53
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, :services_attributes
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,
@@ -9,9 +10,11 @@ class KuberKit::Core::Configuration
9
10
  templates: Hash,
10
11
  kubeconfig_path: Maybe[String],
11
12
  deploy_strategy: Symbol,
12
- services_attributes: HashOf[Symbol => Hash]
13
+ services_attributes: HashOf[Symbol => Hash],
14
+ build_servers: ArrayOf[KuberKit::Core::BuildServers::AbstractBuildServer]
13
15
  ] => Any
14
- def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:, deploy_strategy:, services_attributes:)
16
+ def initialize(name:, artifacts:, registries:, env_files:, templates:, kubeconfig_path:,
17
+ deploy_strategy:, services_attributes:, build_servers:)
15
18
  @name = name
16
19
  @artifacts = artifacts
17
20
  @registries = registries
@@ -20,6 +23,7 @@ class KuberKit::Core::Configuration
20
23
  @kubeconfig_path = kubeconfig_path
21
24
  @deploy_strategy = deploy_strategy
22
25
  @services_attributes = services_attributes
26
+ @build_servers = build_servers
23
27
  end
24
28
 
25
29
  def service_attributes(service_name)
@@ -10,6 +10,7 @@ class KuberKit::Core::ConfigurationDefinition
10
10
  @registries = {}
11
11
  @env_files = {}
12
12
  @templates = {}
13
+ @build_servers = []
13
14
  @enabled_services = []
14
15
  @services_attributes = {}
15
16
  end
@@ -24,6 +25,7 @@ class KuberKit::Core::ConfigurationDefinition
24
25
  kubeconfig_path: @kubeconfig_path,
25
26
  deploy_strategy: @deploy_strategy,
26
27
  enabled_services: @enabled_services,
28
+ build_servers: @build_servers,
27
29
  services_attributes: @services_attributes
28
30
  )
29
31
  end
@@ -64,6 +66,14 @@ class KuberKit::Core::ConfigurationDefinition
64
66
  self
65
67
  end
66
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
+
67
77
  def kubeconfig_path(path)
68
78
  @kubeconfig_path = path
69
79
 
@@ -6,6 +6,7 @@ class KuberKit::Core::ConfigurationFactory
6
6
  "core.artifact_store",
7
7
  "core.env_file_store",
8
8
  "core.template_store",
9
+ "core.build_server_store",
9
10
  "configs"
10
11
  ]
11
12
 
@@ -16,6 +17,7 @@ class KuberKit::Core::ConfigurationFactory
16
17
  registries = fetch_registries(configuration_attrs.registries)
17
18
  env_files = fetch_env_files(configuration_attrs.env_files)
18
19
  templates = fetch_templates(configuration_attrs.templates)
20
+ build_servers = fetch_build_servers(configuration_attrs.build_servers)
19
21
 
20
22
  KuberKit::Core::Configuration.new(
21
23
  name: configuration_attrs.name,
@@ -25,7 +27,8 @@ class KuberKit::Core::ConfigurationFactory
25
27
  templates: templates,
26
28
  kubeconfig_path: configuration_attrs.kubeconfig_path,
27
29
  deploy_strategy: configuration_attrs.deploy_strategy || configs.deploy_strategy,
28
- services_attributes: configuration_attrs.services_attributes
30
+ services_attributes: configuration_attrs.services_attributes,
31
+ build_servers: build_servers
29
32
  )
30
33
  end
31
34
 
@@ -61,4 +64,10 @@ class KuberKit::Core::ConfigurationFactory
61
64
  end
62
65
  result
63
66
  end
67
+
68
+ def fetch_build_servers(build_servers)
69
+ build_servers.map do |build_server_name|
70
+ build_server_store.get(build_server_name)
71
+ end
72
+ end
64
73
  end
@@ -1,7 +1,4 @@
1
1
  class KuberKit::Core::ConfigurationStore
2
- NotFoundError = Class.new(KuberKit::NotFoundError)
3
- AlreadyAddedError = Class.new(KuberKit::Error)
4
-
5
2
  include KuberKit::Import[
6
3
  "core.configuration_factory",
7
4
  "core.configuration_definition_factory",
@@ -16,24 +13,12 @@ class KuberKit::Core::ConfigurationStore
16
13
  end
17
14
 
18
15
  def add_definition(configuration_definition)
19
- @@configuration_definitions ||= {}
20
-
21
- unless @@configuration_definitions[configuration_definition.configuration_name].nil?
22
- raise AlreadyAddedError, "image #{configuration_definition.configuration_name} was already added"
23
- end
24
-
25
- @@configuration_definitions[configuration_definition.configuration_name] = configuration_definition
16
+ definitions_store.add(configuration_definition.configuration_name, configuration_definition)
26
17
  end
27
18
 
28
19
  Contract Symbol => Any
29
20
  def get_definition(configuration_name)
30
- @@configuration_definitions ||= {}
31
-
32
- if @@configuration_definitions[configuration_name].nil?
33
- raise NotFoundError, "configuration #{configuration_name} not found"
34
- end
35
-
36
- @@configuration_definitions[configuration_name]
21
+ definitions_store.get(configuration_name)
37
22
  end
38
23
 
39
24
  Contract Symbol => Any
@@ -57,18 +42,23 @@ class KuberKit::Core::ConfigurationStore
57
42
  end
58
43
 
59
44
  def reset!
60
- @@configuration_definitions = {}
61
- end
62
-
63
- def all_definitions
64
- @@configuration_definitions ||= {}
45
+ definitions_store.reset!
65
46
  end
66
47
 
67
48
  def count
68
- all_definitions.count
49
+ definitions_store.size
69
50
  end
70
51
 
71
52
  def exists?(configuration_name)
72
- !all_definitions[configuration_name].nil?
53
+ definitions_store.exists?(configuration_name)
73
54
  end
55
+
56
+ def all_definitions
57
+ definitions_store.items
58
+ end
59
+
60
+ private
61
+ def definitions_store
62
+ @@definitions_store ||= KuberKit::Core::Store.new(KuberKit::Core::ConfigurationDefinition)
63
+ end
74
64
  end
@@ -1,19 +1,6 @@
1
1
  class KuberKit::Core::EnvFiles::EnvFileStore
2
- NotFoundError = Class.new(KuberKit::NotFoundError)
3
- AlreadyAddedError = Class.new(KuberKit::Error)
4
-
5
2
  def add(env_file)
6
- @@env_files ||= {}
7
-
8
- if !env_file.is_a?(KuberKit::Core::EnvFiles::AbstractEnvFile)
9
- raise ArgumentError.new("should be an instance of KuberKit::Core::EnvFiles::AbstractEnvFile, got: #{env_file.inspect}")
10
- end
11
-
12
- unless @@env_files[env_file.name].nil?
13
- raise AlreadyAddedError, "env_file #{env_file.name} was already added"
14
- end
15
-
16
- @@env_files[env_file.name] = env_file
3
+ store.add(env_file.name, env_file)
17
4
  end
18
5
 
19
6
  def get(env_file_name)
@@ -24,14 +11,7 @@ class KuberKit::Core::EnvFiles::EnvFileStore
24
11
  end
25
12
 
26
13
  def get_global(env_file_name)
27
- @@env_files ||= {}
28
- env_file = @@env_files[env_file_name]
29
-
30
- if env_file.nil?
31
- raise NotFoundError, "env_file '#{env_file_name}' not found"
32
- end
33
-
34
- env_file
14
+ store.get(env_file_name)
35
15
  end
36
16
 
37
17
  def get_from_configuration(env_file_name)
@@ -40,6 +20,11 @@ class KuberKit::Core::EnvFiles::EnvFileStore
40
20
  end
41
21
 
42
22
  def reset!
43
- @@env_files = {}
23
+ store.reset!
44
24
  end
25
+
26
+ private
27
+ def store
28
+ @@store ||= KuberKit::Core::Store.new(KuberKit::Core::EnvFiles::AbstractEnvFile)
29
+ end
45
30
  end
@@ -1,7 +1,4 @@
1
1
  class KuberKit::Core::ImageStore
2
- NotFoundError = Class.new(KuberKit::Error)
3
- AlreadyAddedError = Class.new(KuberKit::Error)
4
-
5
2
  include KuberKit::Import[
6
3
  "core.image_factory",
7
4
  "core.image_definition_factory",
@@ -16,24 +13,12 @@ class KuberKit::Core::ImageStore
16
13
  end
17
14
 
18
15
  def add_definition(image_definition)
19
- @@image_definitions ||= {}
20
-
21
- unless @@image_definitions[image_definition.image_name].nil?
22
- raise AlreadyAddedError, "image #{image_definition.image_name} was already added"
23
- end
24
-
25
- @@image_definitions[image_definition.image_name] = image_definition
16
+ definitions_store.add(image_definition.image_name, image_definition)
26
17
  end
27
18
 
28
19
  Contract Symbol => Any
29
20
  def get_definition(image_name)
30
- @@image_definitions ||= {}
31
-
32
- if @@image_definitions[image_name].nil?
33
- raise NotFoundError, "image #{image_name} not found"
34
- end
35
-
36
- @@image_definitions[image_name]
21
+ definitions_store.get(image_name)
37
22
  end
38
23
 
39
24
  Contract Symbol => Any
@@ -57,6 +42,11 @@ class KuberKit::Core::ImageStore
57
42
  end
58
43
 
59
44
  def reset!
60
- @@image_definitions = {}
45
+ definitions_store.reset!
61
46
  end
47
+
48
+ private
49
+ def definitions_store
50
+ @@definitions_store ||= KuberKit::Core::Store.new(KuberKit::Core::ImageDefinition)
51
+ end
62
52
  end
@@ -1,19 +1,6 @@
1
1
  class KuberKit::Core::Registries::RegistryStore
2
- NotFoundError = Class.new(KuberKit::NotFoundError)
3
- AlreadyAddedError = Class.new(KuberKit::Error)
4
-
5
2
  def add(registry)
6
- @@registries ||= {}
7
-
8
- if !registry.is_a?(KuberKit::Core::Registries::AbstractRegistry)
9
- raise ArgumentError.new("should be an instance of KuberKit::Core::Registries::AbstractRegistry, got: #{registry.inspect}")
10
- end
11
-
12
- unless @@registries[registry.name].nil?
13
- raise AlreadyAddedError, "registry #{registry.name} was already added"
14
- end
15
-
16
- @@registries[registry.name] = registry
3
+ store.add(registry.name, registry)
17
4
  end
18
5
 
19
6
  def get(registry_name)
@@ -24,14 +11,7 @@ class KuberKit::Core::Registries::RegistryStore
24
11
  end
25
12
 
26
13
  def get_global(registry_name)
27
- @@registries ||= {}
28
- registry = @@registries[registry_name]
29
-
30
- if registry.nil?
31
- raise NotFoundError, "registry '#{registry_name}' not found"
32
- end
33
-
34
- registry
14
+ store.get(registry_name)
35
15
  end
36
16
 
37
17
  def get_from_configuration(registry_name)
@@ -44,6 +24,11 @@ class KuberKit::Core::Registries::RegistryStore
44
24
  end
45
25
 
46
26
  def reset!
47
- @@registries = {}
27
+ store.reset!
48
28
  end
29
+
30
+ private
31
+ def store
32
+ @@store ||= KuberKit::Core::Store.new(KuberKit::Core::Registries::AbstractRegistry)
33
+ end
49
34
  end
@@ -1,7 +1,4 @@
1
1
  class KuberKit::Core::ServiceStore
2
- NotFoundError = Class.new(KuberKit::Error)
3
- AlreadyAddedError = Class.new(KuberKit::Error)
4
-
5
2
  include KuberKit::Import[
6
3
  "core.service_factory",
7
4
  "core.service_definition_factory",
@@ -16,24 +13,12 @@ class KuberKit::Core::ServiceStore
16
13
  end
17
14
 
18
15
  def add_definition(service_definition)
19
- @@service_definitions ||= {}
20
-
21
- unless @@service_definitions[service_definition.service_name].nil?
22
- raise AlreadyAddedError, "service #{service_definition.service_name} was already added"
23
- end
24
-
25
- @@service_definitions[service_definition.service_name] = service_definition
16
+ definitions_store.add(service_definition.service_name, service_definition)
26
17
  end
27
18
 
28
19
  Contract Symbol => Any
29
20
  def get_definition(service_name)
30
- @@service_definitions ||= {}
31
-
32
- if @@service_definitions[service_name].nil?
33
- raise NotFoundError, "service '#{service_name}' not found"
34
- end
35
-
36
- @@service_definitions[service_name]
21
+ definitions_store.get(service_name)
37
22
  end
38
23
 
39
24
  Contract Symbol => Any
@@ -57,18 +42,23 @@ class KuberKit::Core::ServiceStore
57
42
  end
58
43
 
59
44
  def reset!
60
- @@service_definitions = {}
45
+ definitions_store.reset!
61
46
  end
62
47
 
63
- def all_definitions
64
- @@service_definitions ||= {}
48
+ def count
49
+ definitions_store.size
65
50
  end
66
51
 
67
- def count
68
- all_definitions.count
52
+ def all_definitions
53
+ definitions_store.items
69
54
  end
70
55
 
71
56
  def exists?(service_name)
72
- !all_definitions[service_name].nil?
57
+ definitions_store.exists?(service_name)
73
58
  end
59
+
60
+ private
61
+ def definitions_store
62
+ @@definitions_store ||= KuberKit::Core::Store.new(KuberKit::Core::ServiceDefinition)
63
+ end
74
64
  end