kuber_kit 0.3.6 → 0.3.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1a2b626e99cbab815d586f4ca2c05796f367f25058502ab7f7b801a0d5191c70
4
- data.tar.gz: 281a2179e9e15d017c65d76c95e1ee863e370fa405ac80571747c2bebaca8e2c
3
+ metadata.gz: 4a8482307f03712fa9621bd81744aa15292d0378a24316c907050ddb1c379981
4
+ data.tar.gz: 28c6b0a83c41d0e221a62e0c45d034a6ecd28722ecb3e98a65471bcaf206372e
5
5
  SHA512:
6
- metadata.gz: c755057ec72e897bce215977d2fef6e2b5bd2e72ae6b7bf6bd58774605bed91d22a73dda41a68783ea36e4c1a375eff432db6764ff1295baae243a0a2ca8a7e4
7
- data.tar.gz: fbb4da6342592b1f5506911787f763f567804aa71fc975a76650e7b8e04137f10be5062e1bafa7ef89ec8bc1c0d86d53d73b9771cb2a90edc6debd7666c1212d
6
+ metadata.gz: 9034b084c1eb1db7dd70ad33f067a19e093bdaaf040aa3b65473d5e823570e35480b0915d1b0274a40ffda74c218e7aaa24ee919935bc1424d579e7c7cbf3ec5
7
+ data.tar.gz: 39bab8853fed26799be1b3b7e1f708be89c82e9082e70c05d5746fd99e11ab52f45a822bfcba572317c6a6128e7fbc823a7b9d9313379a93bc288bf9d7c80ba2
@@ -0,0 +1,35 @@
1
+ # This workflow uses actions that are not certified by GitHub.
2
+ # They are provided by a third-party and are governed by
3
+ # separate terms of service, privacy policy, and support
4
+ # documentation.
5
+ # This workflow will download a prebuilt Ruby version, install dependencies and run tests with Rake
6
+ # For more information see: https://github.com/marketplace/actions/setup-ruby-jruby-and-truffleruby
7
+
8
+ name: Rspec
9
+
10
+ on:
11
+ push:
12
+ branches: [ main ]
13
+ pull_request:
14
+ branches: [ main ]
15
+
16
+ jobs:
17
+ test:
18
+
19
+ runs-on: ubuntu-latest
20
+ strategy:
21
+ matrix:
22
+ ruby-version: ['2.5', '2.7']
23
+
24
+ steps:
25
+ - uses: actions/checkout@v2
26
+ - name: Set up Ruby
27
+ # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
28
+ # change this to (see https://github.com/ruby/setup-ruby#versioning):
29
+ # uses: ruby/setup-ruby@v1
30
+ uses: ruby/setup-ruby@473e4d8fe5dd94ee328fdfca9f8c9c7afc9dae5e
31
+ with:
32
+ ruby-version: ${{ matrix.ruby-version }}
33
+ bundler-cache: true # runs 'bundle install' and caches installed gems automatically
34
+ - name: Run tests
35
+ run: bundle exec rspec spec/
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- kuber_kit (0.3.6)
4
+ kuber_kit (0.3.11)
5
5
  cli-ui
6
6
  contracts-lite
7
7
  dry-auto_inject
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # KuberKit
2
2
 
3
- [![Codeship Status for ArtStation/kuber_kit](https://app.codeship.com/projects/1286f0a6-3f90-4c1b-b426-721ed8a6571b/status?branch=master)](https://app.codeship.com/projects/417264)
3
+ [![Rspec](https://github.com/ArtStation/kuber_kit/workflows/Rspec/badge.svg)](https://github.com/ArtStation/kuber_kit/actions?query=workflow%3ARspec)
4
4
 
5
5
  Solution for building & deploying applications on Kubernetes, written in Ruby.
6
6
 
data/TODO.md CHANGED
@@ -5,4 +5,5 @@
5
5
  - allow deploying only services enabled for specific configuration
6
6
  - find a way to always deploy some service, e.g. for migrations and env_files
7
7
  - template should be able to set default attributes
8
- - template should be able to depend on image?
8
+ - template should be able to depend on image?
9
+ - cleanup image builds older than some date
@@ -1,6 +1,4 @@
1
1
  class KuberKit::Actions::ConfigurationLoader
2
- APP_CONFIG_FILENAME = "config.rb".freeze
3
-
4
2
  include KuberKit::Import[
5
3
  "core.registry_store",
6
4
  "core.image_store",
@@ -16,13 +14,6 @@ class KuberKit::Actions::ConfigurationLoader
16
14
  Contract Hash => Any
17
15
  def call(options)
18
16
  root_path = options[:path] || File.join(Dir.pwd, configs.kuber_kit_dirname)
19
-
20
- # require config file first, in case if other dirs are overriden in config
21
- config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
22
- if File.exists?(config_file_path)
23
- require config_file_path
24
- end
25
-
26
17
  images_path = options[:images_path] || File.join(root_path, configs.images_dirname)
27
18
  services_path = options[:services_path] || File.join(root_path, configs.services_dirname)
28
19
  infra_path = options[:infra_path] || File.join(root_path, configs.infra_dirname)
@@ -37,6 +28,8 @@ class KuberKit::Actions::ConfigurationLoader
37
28
  logger.info " Configurations path: #{configurations_path.to_s.yellow}"
38
29
  logger.info " Configuration name: #{configuration_name.to_s.yellow}"
39
30
 
31
+ ui.print_info("Logs", "See logs at: #{configs.log_file_path}")
32
+
40
33
  unless File.exists?(root_path)
41
34
  ui.print_warning "WARNING", "KuberKit root path #{root_path} doesn't exist. You may want to pass it --path parameter."
42
35
  end
@@ -16,7 +16,7 @@ class KuberKit::Actions::KubectlLogs
16
16
  pod_name = ui.prompt("Please select deployment to attach", deploy_options)
17
17
  end
18
18
 
19
- args = ""
19
+ args = nil
20
20
  if options[:follow]
21
21
  args = "-f"
22
22
  end
@@ -1,6 +1,8 @@
1
1
  require 'thor'
2
2
 
3
3
  class KuberKit::CLI < Thor
4
+ APP_CONFIG_FILENAME = "config.rb".freeze
5
+
4
6
  class_option :path, :type => :string
5
7
  class_option :images_path, :type => :string
6
8
  class_option :infra_path, :type => :string
@@ -10,7 +12,7 @@ class KuberKit::CLI < Thor
10
12
 
11
13
  desc "compile IMAGE_NAMES", "Compile image with IMAGE_NAMES (comma-separated)"
12
14
  def compile(image_names_str)
13
- KuberKit.set_debug_mode(options[:debug])
15
+ setup(options)
14
16
 
15
17
  image_names = image_names_str.split(",").map(&:strip).map(&:to_sym)
16
18
 
@@ -35,7 +37,7 @@ class KuberKit::CLI < Thor
35
37
  method_option :tags, :type => :array, aliases: ["-t"]
36
38
  method_option :skip_compile, :type => :boolean, aliases: ["-B"]
37
39
  def deploy
38
- KuberKit.set_debug_mode(options[:debug])
40
+ setup(options)
39
41
 
40
42
  if KuberKit::Container['actions.configuration_loader'].call(options)
41
43
  result = KuberKit::Container['actions.service_deployer'].call(
@@ -59,7 +61,7 @@ class KuberKit::CLI < Thor
59
61
 
60
62
  desc "env ENV_FILE_NAME", "Return content of Env File ENV_FILE_NAME"
61
63
  def env(env_file_name)
62
- KuberKit.set_debug_mode(options[:debug])
64
+ setup(options)
63
65
 
64
66
  if KuberKit::Container['actions.configuration_loader'].call(options)
65
67
  KuberKit::Container['actions.env_file_reader'].call(env_file_name.to_sym, options)
@@ -68,7 +70,7 @@ class KuberKit::CLI < Thor
68
70
 
69
71
  desc "template TEMPLATE_NAME", "Return content of Template TEMPLATE_NAME"
70
72
  def template(template_name)
71
- KuberKit.set_debug_mode(options[:debug])
73
+ setup(options)
72
74
 
73
75
  if KuberKit::Container['actions.configuration_loader'].call(options)
74
76
  KuberKit::Container['actions.template_reader'].call(template_name.to_sym, options)
@@ -77,7 +79,7 @@ class KuberKit::CLI < Thor
77
79
 
78
80
  desc "service SERVICE_NAME", "Return content of Service SERVICE_NAME"
79
81
  def service(service_name)
80
- KuberKit.set_debug_mode(options[:debug])
82
+ setup(options)
81
83
 
82
84
  if KuberKit::Container['actions.configuration_loader'].call(options)
83
85
  KuberKit::Container['actions.service_reader'].call(service_name.to_sym, options)
@@ -86,7 +88,7 @@ class KuberKit::CLI < Thor
86
88
 
87
89
  desc "apply FILE_PATH", "Apply FILE_PATH with kubectl"
88
90
  def apply(file_path)
89
- KuberKit.set_debug_mode(options[:debug])
91
+ setup(options)
90
92
 
91
93
  if KuberKit::Container['actions.configuration_loader'].call(options)
92
94
  KuberKit::Container['actions.kubectl_applier'].call(File.expand_path(file_path), options)
@@ -95,26 +97,26 @@ class KuberKit::CLI < Thor
95
97
 
96
98
  desc "attach POD_NAME", "Attach to POD_NAME using kubectl"
97
99
  def attach(pod_name = nil)
98
- KuberKit.set_debug_mode(options[:debug])
100
+ setup(options)
99
101
 
100
102
  if KuberKit::Container['actions.configuration_loader'].call(options)
101
103
  KuberKit::Container['actions.kubectl_attacher'].call(pod_name, options)
102
104
  end
103
105
  end
104
106
 
105
- desc "launch console in POD_NAME", "Attach to POD_NAME using kubectl & launch bin/console"
107
+ desc "console POD_NAME", "Attach to POD_NAME using kubectl & launch bin/console"
106
108
  def console(pod_name = nil)
107
- KuberKit.set_debug_mode(options[:debug])
109
+ setup(options)
108
110
 
109
111
  if KuberKit::Container['actions.configuration_loader'].call(options)
110
112
  KuberKit::Container['actions.kubectl_console'].call(pod_name, options)
111
113
  end
112
114
  end
113
115
 
114
- desc "show logs for POD_NAME", "Show logs for POD_NAME using kubectl"
116
+ desc "logs POD_NAME", "Show logs for POD_NAME using kubectl"
115
117
  method_option :follow, :type => :boolean, aliases: ["-f"]
116
118
  def logs(pod_name = nil)
117
- KuberKit.set_debug_mode(options[:debug])
119
+ setup(options)
118
120
 
119
121
  if KuberKit::Container['actions.configuration_loader'].call(options)
120
122
  KuberKit::Container['actions.kubectl_logs'].call(pod_name, options)
@@ -129,4 +131,16 @@ class KuberKit::CLI < Thor
129
131
  def self.exit_on_failure?
130
132
  true
131
133
  end
134
+
135
+ private
136
+ def setup(options)
137
+ KuberKit.set_debug_mode(options[:debug])
138
+
139
+ # We should load config before loading any bean, to make sure that bean won't be built with default config
140
+ root_path = options[:path] || File.join(Dir.pwd, KuberKit::Container['configs'].kuber_kit_dirname)
141
+ config_file_path = File.join(root_path, APP_CONFIG_FILENAME)
142
+ if File.exists?(config_file_path)
143
+ require config_file_path
144
+ end
145
+ end
132
146
  end
@@ -5,7 +5,7 @@ class KuberKit::Configs
5
5
  :image_dockerfile_name, :image_build_context_dir, :image_tag, :docker_ignore_list, :image_compile_dir,
6
6
  :kuber_kit_dirname, :kuber_kit_min_version, :images_dirname, :services_dirname, :infra_dirname, :configurations_dirname,
7
7
  :artifact_clone_dir, :service_config_dir, :deployer_strategy, :compile_simultaneous_limit,
8
- :additional_images_paths, :deprecation_warnings_disabled
8
+ :additional_images_paths, :deprecation_warnings_disabled, :log_file_path
9
9
  ]
10
10
  DOCKER_IGNORE_LIST = [
11
11
  'Dockerfile',
@@ -51,6 +51,7 @@ class KuberKit::Configs
51
51
  set :compile_simultaneous_limit, 5
52
52
  set :additional_images_paths, []
53
53
  set :deprecation_warnings_disabled, false
54
+ set :log_file_path, "/tmp/kuber_kit.log"
54
55
  end
55
56
 
56
57
  def items
@@ -114,7 +114,7 @@ class KuberKit::Container
114
114
  end
115
115
 
116
116
  register "tools.logger" do
117
- KuberKit::Container["tools.logger_factory"].create("/tmp/kuber_kit.log")
117
+ KuberKit::Container["tools.logger_factory"].create()
118
118
  end
119
119
 
120
120
  register "shell.bash_commands" do
@@ -4,11 +4,11 @@ class KuberKit::Core::Service
4
4
  attr_reader :name, :template_name, :tags, :images, :attributes, :deployer_strategy
5
5
 
6
6
  Contract KeywordArgs[
7
- name: Symbol,
8
- template_name: Symbol,
9
- tags: ArrayOf[Symbol],
10
- images: ArrayOf[Symbol],
11
- attributes: HashOf[Symbol => Any],
7
+ name: Symbol,
8
+ template_name: Maybe[Symbol],
9
+ tags: ArrayOf[Symbol],
10
+ images: ArrayOf[Symbol],
11
+ attributes: HashOf[Symbol => Any],
12
12
  deployer_strategy: Maybe[Symbol]
13
13
  ] => Any
14
14
  def initialize(name:, template_name:, tags:, images:, attributes:, deployer_strategy:)
@@ -1,13 +1,7 @@
1
1
  class KuberKit::Core::ServiceFactory
2
- AttributeNotSetError = Class.new(KuberKit::Error)
3
-
4
2
  def create(definition)
5
3
  service_attrs = definition.to_service_attrs
6
4
 
7
- if service_attrs.template_name.nil?
8
- raise AttributeNotSetError, "Please set template for service using #template method"
9
- end
10
-
11
5
  configuration_attributes = KuberKit.current_configuration.service_attributes(service_attrs.name)
12
6
  attributes = (service_attrs.attributes || {}).merge(configuration_attributes)
13
7
 
@@ -8,8 +8,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
8
8
  STRATEGY_OPTIONS = [
9
9
  :container_name,
10
10
  :image_name,
11
- :docker_run_args,
12
- :docker_run_command,
11
+ :detached,
12
+ :command_name,
13
+ :command_args,
13
14
  :delete_if_exists
14
15
  ]
15
16
 
@@ -21,9 +22,9 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
21
22
  raise KuberKit::Error, "Unknow options for deploy strategy: #{unknown_options}. Available options: #{STRATEGY_OPTIONS}"
22
23
  end
23
24
 
24
- container_name = strategy_options.fetch(:container_name, service.uri)
25
- docker_run_args = strategy_options.fetch(:docker_run_args, nil)
26
- docker_run_command = strategy_options.fetch(:docker_run_command, nil)
25
+ container_name = strategy_options.fetch(:container_name, service.uri)
26
+ command_name = strategy_options.fetch(:command_name, "bash")
27
+ command_args = strategy_options.fetch(:command_args, nil)
27
28
 
28
29
  image_name = strategy_options.fetch(:image_name, nil)
29
30
  if image_name.nil?
@@ -36,6 +37,16 @@ class KuberKit::ServiceDeployer::Strategies::Docker < KuberKit::ServiceDeployer:
36
37
  docker_commands.delete_container(shell, container_name)
37
38
  end
38
39
 
39
- docker_commands.run(shell, image.remote_registry_url, run_args: docker_run_args, run_command: docker_run_command)
40
+ command_args = Array(command_args)
41
+ if container_name
42
+ command_args << "--name #{container_name}"
43
+ end
44
+
45
+ docker_commands.run(
46
+ shell, image.remote_registry_url,
47
+ command: command_name,
48
+ args: command_args,
49
+ detached: !!strategy_options[:detached]
50
+ )
40
51
  end
41
52
  end
@@ -7,7 +7,9 @@ class KuberKit::ServiceDeployer::Strategies::DockerCompose < KuberKit::ServiceDe
7
7
 
8
8
  STRATEGY_OPTIONS = [
9
9
  :service_name,
10
- :command_name
10
+ :command_name,
11
+ :command_args,
12
+ :detached
11
13
  ]
12
14
 
13
15
  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
@@ -24,10 +26,13 @@ class KuberKit::ServiceDeployer::Strategies::DockerCompose < KuberKit::ServiceDe
24
26
 
25
27
  service_name = strategy_options.fetch(:service_name, service.name.to_s)
26
28
  command_name = strategy_options.fetch(:command_name, "bash")
29
+ command_args = strategy_options.fetch(:command_args, nil)
27
30
 
28
31
  docker_compose_commands.run(shell, config_path,
29
- service: service_name,
30
- command: command_name,
32
+ service: service_name,
33
+ command: command_name,
34
+ args: command_args,
35
+ detached: !!strategy_options[:detached]
31
36
  )
32
37
  end
33
38
  end
@@ -6,8 +6,14 @@ class KuberKit::ServiceReader::Reader
6
6
  "preprocessing.text_preprocessor"
7
7
  ]
8
8
 
9
+ AttributeNotSetError = Class.new(KuberKit::Error)
10
+
9
11
  Contract KuberKit::Shell::AbstractShell, KuberKit::Core::Service => Any
10
12
  def read(shell, service)
13
+ if service.template_name.nil?
14
+ raise AttributeNotSetError, "Please set template for service using #template method"
15
+ end
16
+
11
17
  template = template_store.get(service.template_name)
12
18
 
13
19
  context_helper = context_helper_factory.build_service_context(shell, service)
@@ -14,14 +14,19 @@ class KuberKit::Shell::Commands::DockerCommands
14
14
  shell.exec!(%Q{docker push #{tag_name}})
15
15
  end
16
16
 
17
- def run(shell, image_name, run_args: nil, run_command: nil)
17
+ def run(shell, image_name, args: nil, command: nil, detached: false, interactive: false)
18
18
  command_parts = []
19
19
  command_parts << "docker run"
20
- command_parts << run_args if run_args
20
+ command_parts << "-d" if detached
21
+ command_parts << Array(args).join(" ") if args
21
22
  command_parts << image_name
22
- command_parts << run_command if run_command
23
+ command_parts << command if command
23
24
 
24
- shell.exec!(command_parts.join(" "))
25
+ if interactive
26
+ shell.interactive!(command_parts.join(" "))
27
+ else
28
+ shell.exec!(command_parts.join(" "))
29
+ end
25
30
  end
26
31
 
27
32
  def container_exists?(shell, container_name)
@@ -1,13 +1,17 @@
1
1
  class KuberKit::Shell::Commands::DockerComposeCommands
2
- def run(shell, path, service:, command:, interactive: false)
2
+ def run(shell, path, service:, args: nil, command: nil, detached: false, interactive: false)
3
3
  command_parts = [
4
4
  "docker-compose",
5
5
  "-f #{path}",
6
6
  "run",
7
- service,
8
- command
9
7
  ]
10
8
 
9
+
10
+ command_parts << "-d" if detached
11
+ command_parts << Array(args).join(" ") if args
12
+ command_parts << service
13
+ command_parts << command if command
14
+
11
15
  if interactive
12
16
  shell.interactive!(command_parts.join(" "))
13
17
  else
@@ -76,7 +76,7 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
76
76
 
77
77
  def recursive_list_files(path, name: nil)
78
78
  command = %Q{find -L #{path} -type f}
79
- command += " -name #{name}" if name
79
+ command += " -name '#{name}'" if name
80
80
  exec!(command).split(/[\r\n]+/)
81
81
  rescue => e
82
82
  if e.message.include?("No such file or directory")
@@ -9,8 +9,12 @@ class KuberKit::Tools::LoggerFactory
9
9
  Logger::FATAL => String::Colors::PURPLE,
10
10
  }
11
11
 
12
- def create(stdout, level = nil)
13
- logger = Logger.new(stdout)
12
+ include KuberKit::Import[
13
+ "configs",
14
+ ]
15
+
16
+ def create(stdout = nil, level = nil)
17
+ logger = Logger.new(stdout || configs.log_file_path)
14
18
 
15
19
  logger.level = level || Logger::DEBUG
16
20
 
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "0.3.6"
2
+ VERSION = "0.3.11"
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.3.6
4
+ version: 0.3.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Iskander Khaziev
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-01-07 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts-lite
@@ -145,6 +145,7 @@ executables:
145
145
  extensions: []
146
146
  extra_rdoc_files: []
147
147
  files:
148
+ - ".github/workflows/rspec.yml"
148
149
  - ".gitignore"
149
150
  - ".rspec"
150
151
  - ".ruby-gemset"
@@ -293,7 +294,7 @@ homepage: https://github.com/ArtStation/kuber_kit
293
294
  licenses:
294
295
  - MIT
295
296
  metadata: {}
296
- post_install_message:
297
+ post_install_message:
297
298
  rdoc_options: []
298
299
  require_paths:
299
300
  - lib
@@ -308,8 +309,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
308
309
  - !ruby/object:Gem::Version
309
310
  version: '0'
310
311
  requirements: []
311
- rubygems_version: 3.0.9
312
- signing_key:
312
+ rubygems_version: 3.0.8
313
+ signing_key:
313
314
  specification_version: 4
314
315
  summary: Docker Containers Build & Deployment
315
316
  test_files: []