kuber_kit 1.2.0 → 1.2.1

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: 41f8c55add7e426b80fa74ec7f39b2af312e9d8bc94ffc412d6046d228af1bcf
4
- data.tar.gz: 55f2921894f99cd9aa68a868c87c0059e59e2405355154015571cc5d8676575c
3
+ metadata.gz: f0a62cde1e86bf987531722246cf273df2b4aeea6cad29e5de11ea768d725ecc
4
+ data.tar.gz: 8d6563f57469cf82bddf0cc4fc8c916317c353145e6a321eca8dc6f5d10a6af2
5
5
  SHA512:
6
- metadata.gz: 13312d069ddfbddbd5972b2fbdc3e87970e366dfb2bb12caa94ac76979ecf511c92887c17567c521846648cf10a6e2c725d20baa0d2739ee5288d2497fbd6817
7
- data.tar.gz: f9d35c210a01f77f3083a6ac2a92c9452ce3d26703d941fac175b78d4838fc0dca6d63eb5fe1de0b3bae1135a8ed1276601044193ce814677191747712f1fead
6
+ metadata.gz: 828accbdd1ce45d263a3a835d4ff5b7431e535f4ea214f4b2ae31765d2092e0825d8b317c887919a0974b6a2cdd0636fc36086e3cf578088029d191ac3598811
7
+ data.tar.gz: 9b33cacce0e6afa653270bb944999fdc43e41ef296a7ed03371024304367604741f8142fe9440a115056118c4094bbf4e45d69db1f99367f76b40f071d2bbc78
data/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ **1.2.1**
2
+ - Update shell commands so that STDERR stream won't be merged for commands using the command result.
3
+ - kit sh would also set current default configuration
4
+ - kit get supports "api" ui
5
+ - show sync description (git/local) for artifact sync
6
+
1
7
  **1.2.0**
2
8
  - Change minimal ruby version to 3
3
9
 
@@ -109,9 +109,9 @@ class KuberKit::Actions::ConfigurationLoader
109
109
 
110
110
  artifact_task_group = ui.create_task_group
111
111
  not_local_artifacts.each do |artifact|
112
- artifact_task_group.add("Updating #{artifact.name.to_s.yellow}") do |task|
112
+ artifact_task_group.add("Updating #{artifact.name.to_s.yellow} [#{artifact.sync_description.cyan}]") do |task|
113
113
  artifact_updater.update(local_shell, artifact)
114
- task.update_title("Updated #{artifact.name.to_s.green}")
114
+ task.update_title("Updating #{artifact.name.to_s.green} [#{artifact.sync_description.cyan}]")
115
115
  end
116
116
  end
117
117
  artifact_task_group.wait
@@ -6,7 +6,7 @@ class KuberKit::Actions::KubectlGet
6
6
  "ui"
7
7
  ]
8
8
 
9
- Contract Maybe[String], Hash => Any
9
+ Contract Maybe[String], Hash => Array
10
10
  def call(resource_name, options)
11
11
  kubeconfig_path = KuberKit.current_configuration.kubeconfig_path
12
12
  deployer_namespace = KuberKit.current_configuration.deployer_namespace
@@ -23,10 +23,10 @@ class KuberKit::Actions::KubectlGet
23
23
 
24
24
  ui.print_info("Pods", resources.join("\n"))
25
25
 
26
- true
26
+ resources
27
27
  rescue KuberKit::Error => e
28
28
  ui.print_error("Error", e.message)
29
29
 
30
- false
30
+ []
31
31
  end
32
32
  end
data/lib/kuber_kit/cli.rb CHANGED
@@ -177,7 +177,11 @@ class KuberKit::CLI < Thor
177
177
  setup(options)
178
178
 
179
179
  if KuberKit::Container['actions.configuration_loader'].call(options.merge(load_inventory: false))
180
- KuberKit::Container['actions.kubectl_get'].call(pod_name, options)
180
+ pods = KuberKit::Container['actions.kubectl_get'].call(pod_name, options)
181
+
182
+ print_result("Fetched list of pods", result: {
183
+ pods: pods
184
+ })
181
185
  end
182
186
  end
183
187
 
@@ -5,7 +5,7 @@ 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
8
+ :additional_images_paths, :deprecation_warnings_disabled, :log_file_path, :env_file_compile_dir, :shell_launcher_strategy, :shell_launcher_sets_configration
9
9
  ]
10
10
  DOCKER_IGNORE_LIST = [
11
11
  'Dockerfile',
@@ -59,6 +59,7 @@ class KuberKit::Configs
59
59
  set :deprecation_warnings_disabled, false
60
60
  set :log_file_path, File.join(absolute_kuber_kit_path, "deploy.log")
61
61
  set :env_file_compile_dir, File.join(absolute_kuber_kit_path, "env_files")
62
+ set :shell_launcher_sets_configration, true
62
63
  end
63
64
 
64
65
  def items
@@ -10,4 +10,8 @@ class KuberKit::Core::Artifacts::AbstractArtifact
10
10
  def namespace
11
11
  raise KuberKit::NotImplementedError, "must be implemented"
12
12
  end
13
+
14
+ def sync_description
15
+ raise KuberKit::NotImplementedError, "must be implemented"
16
+ end
13
17
  end
@@ -19,4 +19,8 @@ class KuberKit::Core::Artifacts::Git < KuberKit::Core::Artifacts::AbstractArtifa
19
19
  configs = KuberKit::Container['configs']
20
20
  "#{configs.artifact_clone_dir}/#{name}"
21
21
  end
22
+
23
+ def sync_description
24
+ "#{remote_url}:#{branch}"
25
+ end
22
26
  end
@@ -11,4 +11,8 @@ class KuberKit::Core::Artifacts::Local < KuberKit::Core::Artifacts::AbstractArti
11
11
  def cloned_path
12
12
  root_path
13
13
  end
14
+
15
+ def sync_description
16
+ "local"
17
+ end
14
18
  end
@@ -1,27 +1,27 @@
1
1
  require 'time'
2
2
  class KuberKit::Shell::Commands::BashCommands
3
3
  def rm(shell, path)
4
- shell.exec!(%Q{rm "#{path}"})
4
+ shell.exec!(%Q{rm "#{path}"}, merge_stderr: true)
5
5
  end
6
6
 
7
7
  def rm_rf(shell, path)
8
- shell.exec!(%Q{rm -rf "#{path}"})
8
+ shell.exec!(%Q{rm -rf "#{path}"}, merge_stderr: true)
9
9
  end
10
10
 
11
11
  def cp(shell, source_path, dest_path)
12
- shell.exec!(%Q{cp "#{source_path}" "#{dest_path}"})
12
+ shell.exec!(%Q{cp "#{source_path}" "#{dest_path}"}, merge_stderr: true)
13
13
  end
14
14
 
15
15
  def cp_r(shell, source_path, dest_path)
16
- shell.exec!(%Q{cp -r "#{source_path}" "#{dest_path}"})
16
+ shell.exec!(%Q{cp -r "#{source_path}" "#{dest_path}"}, merge_stderr: true)
17
17
  end
18
18
 
19
19
  def mkdir(shell, path)
20
- shell.exec!(%Q{mkdir "#{path}"})
20
+ shell.exec!(%Q{mkdir "#{path}"}, merge_stderr: true)
21
21
  end
22
22
 
23
23
  def mkdir_p(shell, path)
24
- shell.exec!(%Q{mkdir -p "#{path}"})
24
+ shell.exec!(%Q{mkdir -p "#{path}"}, merge_stderr: true)
25
25
  end
26
26
 
27
27
  def ctime(shell, path)
@@ -3,15 +3,15 @@ class KuberKit::Shell::Commands::DockerCommands
3
3
  default_args = ["--rm=true"]
4
4
  args_list = (default_args + args).join(" ")
5
5
 
6
- shell.exec!(%Q{docker image build #{build_dir} #{args_list}})
6
+ shell.exec!(%Q{docker image build #{build_dir} #{args_list}}, merge_stderr: true)
7
7
  end
8
8
 
9
9
  def tag(shell, image_name, tag_name)
10
- shell.exec!(%Q{docker tag #{image_name} #{tag_name}})
10
+ shell.exec!(%Q{docker tag #{image_name} #{tag_name}}, merge_stderr: true)
11
11
  end
12
12
 
13
13
  def push(shell, tag_name)
14
- shell.exec!(%Q{docker push #{tag_name}})
14
+ shell.exec!(%Q{docker push #{tag_name}}, merge_stderr: true)
15
15
  end
16
16
 
17
17
  def run(shell, image_name, args: nil, command: nil, detached: false, interactive: false)
@@ -25,7 +25,7 @@ class KuberKit::Shell::Commands::DockerCommands
25
25
  if interactive
26
26
  shell.interactive!(command_parts.join(" "))
27
27
  else
28
- shell.exec!(command_parts.join(" "))
28
+ shell.exec!(command_parts.join(" "), merge_stderr: true)
29
29
  end
30
30
  end
31
31
 
@@ -44,7 +44,7 @@ class KuberKit::Shell::Commands::DockerCommands
44
44
  if status
45
45
  command_parts << "--filter=\"status=#{status}\""
46
46
  end
47
- command_parts << "--filter=\"name=#{container_name}\""
47
+ command_parts << "--filter=\"name=^/#{container_name}$\""
48
48
 
49
49
  shell.exec!(command_parts.join(" "))
50
50
  end
@@ -15,7 +15,7 @@ class KuberKit::Shell::Commands::DockerComposeCommands
15
15
  if interactive
16
16
  shell.interactive!(command_parts.join(" "))
17
17
  else
18
- shell.exec!(command_parts.join(" "))
18
+ shell.exec!(command_parts.join(" "), merge_stderr: true)
19
19
  end
20
20
  end
21
21
  end
@@ -1,36 +1,36 @@
1
1
  class KuberKit::Shell::Commands::GitCommands
2
2
  def get_remote_url(shell, git_repo_path, remote_name: "origin")
3
- shell.exec! [
3
+ shell.exec!([
4
4
  "cd #{git_repo_path}",
5
5
  "git config --get remote.#{remote_name}.url",
6
- ].join(" && ")
6
+ ].join(" && "), merge_stderr: true)
7
7
  rescue KuberKit::Shell::AbstractShell::ShellError
8
8
  return nil
9
9
  end
10
10
 
11
11
  def get_version_hash(shell, git_repo_path)
12
- shell.exec! [
12
+ shell.exec!([
13
13
  "cd #{git_repo_path}",
14
14
  "git rev-parse --short HEAD",
15
- ].join(" && ")
15
+ ].join(" && "), merge_stderr: true)
16
16
  end
17
17
 
18
18
  def download_repo(shell, remote_url:, path:, branch:)
19
- shell.exec! [
19
+ shell.exec!([
20
20
  "rm -rf #{path}",
21
21
  "mkdir -p #{path}",
22
22
  "git clone -b #{branch} --depth 1 #{remote_url} #{path}",
23
- ].join(" && ")
23
+ ].join(" && "), merge_stderr: true)
24
24
  end
25
25
 
26
26
  def force_pull_repo(shell, path:, branch:)
27
- shell.exec! [
27
+ shell.exec!([
28
28
  "cd #{path}",
29
29
  "git add .",
30
30
  "git reset HEAD --hard",
31
31
  "git checkout #{branch}",
32
32
  "git reset --hard '@{u}'",
33
33
  "git pull --force",
34
- ].join(" && ")
34
+ ].join(" && "), merge_stderr: true)
35
35
  end
36
36
  end
@@ -10,8 +10,8 @@ class KuberKit::Shell::Commands::KubectlCommands
10
10
  kubeconfig_path: Maybe[Or[
11
11
  String, KuberKit::Core::ArtifactPath
12
12
  ]],
13
- namespace: Maybe[Or[Symbol, String]],
14
- interactive: Optional[Bool],
13
+ namespace: Maybe[Or[Symbol, String]],
14
+ interactive: Optional[Bool],
15
15
  ] => Any
16
16
  def kubectl_run(shell, command_list, kubeconfig_path: nil, namespace: nil, interactive: false)
17
17
  command_parts = []
@@ -22,7 +22,7 @@ class KuberKit::Shell::Commands::RsyncCommands
22
22
  args << "--delete"
23
23
  end
24
24
 
25
- shell.exec!(%Q{rsync -a #{args.join(' ')}})
25
+ shell.exec!(%Q{rsync -a #{args.join(' ')}}, merge_stderr: true)
26
26
  end
27
27
 
28
28
  private
@@ -2,7 +2,7 @@ class KuberKit::Shell::Commands::SystemCommands
2
2
  def kill_process(shell, pid)
3
3
  # we need to use kill command directly sometimes,
4
4
  # because Process.kill doesn't kill processes created by system() call
5
- shell.exec!("kill -9 #{pid}")
5
+ shell.exec!("kill -9 #{pid}", merge_stderr: true)
6
6
  true
7
7
  rescue
8
8
  false
@@ -9,7 +9,9 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
9
9
  "ui",
10
10
  ]
11
11
 
12
- def exec!(command, log_command: true)
12
+ # @merge_stderr: Merge STDERR to the resulting stream. Could be helpful, if we don't want it printed to STDERR.
13
+ # Should be false, if we want to read & use the result of the command.
14
+ def exec!(command, log_command: true, merge_stderr: false)
13
15
  command_number = command_counter.get_number.to_s.rjust(2, "0")
14
16
 
15
17
  if log_command
@@ -17,7 +19,9 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
17
19
  end
18
20
 
19
21
  result = nil
20
- IO.popen(wrap_command_with_pid(command), err: [:child, :out]) do |io|
22
+
23
+ options = merge_stderr ? {err: [:child, :out]} : {}
24
+ IO.popen(wrap_command_with_pid(command), **options) do |io|
21
25
  result = io.read.chomp.strip
22
26
  end
23
27
 
@@ -88,21 +92,21 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
88
92
  end
89
93
 
90
94
  def delete(file_path)
91
- exec!("rm #{file_path}")
95
+ exec!("rm #{file_path}", merge_stderr: true)
92
96
  end
93
97
 
94
98
  def file_exists?(file_path)
95
- exec!("test -f #{file_path} && echo 'true' || echo 'false'", log_command: false) == 'true'
99
+ exec!("test -f #{file_path} && echo 'true' || echo 'false'", log_command: false, merge_stderr: true) == 'true'
96
100
  end
97
101
 
98
102
  def dir_exists?(dir_path)
99
- exec!("test -d #{dir_path} && echo 'true' || echo 'false'", log_command: false) == 'true'
103
+ exec!("test -d #{dir_path} && echo 'true' || echo 'false'", log_command: false, merge_stderr: true) == 'true'
100
104
  end
101
105
 
102
106
  def recursive_list_files(path, name: nil)
103
107
  command = %Q{find -L #{path} -type f}
104
108
  command += " -name '#{name}'" if name
105
- exec!(command).split(/[\r\n]+/)
109
+ exec!(command, merge_stderr: true).split(/[\r\n]+/)
106
110
  rescue => e
107
111
  if e.message.include?("No such file or directory")
108
112
  raise DirNotFoundError.new("Dir not found: #{path}")
@@ -113,7 +117,7 @@ class KuberKit::Shell::LocalShell < KuberKit::Shell::AbstractShell
113
117
 
114
118
  def list_dirs(path)
115
119
  command = %Q{find -L #{path} -maxdepth 0 -type d}
116
- exec!(command).split(/[\r\n]+/)
120
+ exec!(command, merge_stderr: true).split(/[\r\n]+/)
117
121
  rescue => e
118
122
  if e.message.include?("No such file or directory")
119
123
  raise DirNotFoundError.new("Dir not found: #{path}")
@@ -22,7 +22,7 @@ class KuberKit::Shell::SshSession
22
22
  @session = nil
23
23
  end
24
24
 
25
- def exec!(command)
25
+ def exec!(command, merge_stderr: false)
26
26
  stdout_data = ''
27
27
  stderr_data = ''
28
28
  exit_code = nil
@@ -38,6 +38,10 @@ class KuberKit::Shell::SshSession
38
38
 
39
39
  channel.on_extended_data do |ch,type,data|
40
40
  stderr_data += data
41
+
42
+ if merge_stderr
43
+ stdout_data += data
44
+ end
41
45
  end
42
46
 
43
47
  channel.on_request('exit-status') do |ch,data|
@@ -20,14 +20,14 @@ class KuberKit::Shell::SshShell < KuberKit::Shell::LocalShell
20
20
  @ssh_session.disconnect if @ssh_session
21
21
  end
22
22
 
23
- def exec!(command, log_command: true)
23
+ def exec!(command, log_command: true, merge_stderr: false)
24
24
  command_number = command_counter.get_number.to_s.rjust(2, "0")
25
25
 
26
26
  if log_command
27
27
  ui.print_debug("SshShell", "#{ssh_session.host.green} > Execute: [#{command_number}]: #{command.to_s.cyan}")
28
28
  end
29
29
 
30
- result = ssh_session.exec!(wrap_command_with_pid(command))
30
+ result = ssh_session.exec!(wrap_command_with_pid(command), merge_stderr: merge_stderr)
31
31
 
32
32
  if result && result != "" && log_command
33
33
  ui.print_debug("SshShell", "#{ssh_session.host.green} > Finished [#{command_number}] with result: \n#{result.grey}")
@@ -17,6 +17,15 @@ class KuberKit::ShellLauncher::Strategies::Kubernetes < KuberKit::ShellLauncher:
17
17
  kubectl_commands.set_namespace(shell, deployer_namespace, kubeconfig_path: kubeconfig_path)
18
18
  end
19
19
 
20
+ env_vars = [
21
+ "KUBECONFIG=#{kubeconfig_path}",
22
+ "KUBER_KIT_SHELL_CONFIGURATION=#{KuberKit.current_configuration.name}"
23
+ ]
24
+
25
+ if configs.shell_launcher_sets_configration
26
+ env_vars << "KUBER_KIT_CONFIGURATION=#{KuberKit.current_configuration.name}"
27
+ end
28
+
20
29
  shell.replace!(env: ["KUBECONFIG=#{kubeconfig_path}", "KUBER_KIT_SHELL_CONFIGURATION=#{KuberKit.current_configuration.name}"])
21
30
  end
22
31
  end
@@ -1,3 +1,3 @@
1
1
  module KuberKit
2
- VERSION = "1.2.0"
2
+ VERSION = "1.2.1"
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: 1.2.0
4
+ version: 1.2.1
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: 2022-10-18 00:00:00.000000000 Z
11
+ date: 2023-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: contracts
@@ -382,7 +382,7 @@ homepage: https://github.com/ArtStation/kuber_kit
382
382
  licenses:
383
383
  - MIT
384
384
  metadata: {}
385
- post_install_message:
385
+ post_install_message:
386
386
  rdoc_options: []
387
387
  require_paths:
388
388
  - lib
@@ -398,7 +398,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
398
398
  version: '0'
399
399
  requirements: []
400
400
  rubygems_version: 3.3.7
401
- signing_key:
401
+ signing_key:
402
402
  specification_version: 4
403
403
  summary: Docker Containers Build & Deployment
404
404
  test_files: []