dapp 0.23.1 → 0.23.2

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
- SHA1:
3
- metadata.gz: f2398cf5c147d22ffee085269b97c5bb71c604a3
4
- data.tar.gz: e7c60b8f1c96ce3ea0b2118e6693f7b1465b0a67
2
+ SHA256:
3
+ metadata.gz: b824d82111173d42881d595fa087ea22e0f631c4cfd41f679779dd54dd08e5eb
4
+ data.tar.gz: 65b7d687aed97303a38a64bba5941a97014306fb9cda93e05ca823d40b2ac1bc
5
5
  SHA512:
6
- metadata.gz: 5a197929f2545c01c003d529324590bcfe547bb26f3ecf66298356011d8ce382536cf94491152d9447f230e52dea63da587035b00b2fb9bdc3cda9f9f0062726
7
- data.tar.gz: 166ccc636ab5edb115d5f0d85712be10ddd7dace4db0c4105eb6626ea35cefdc4eca6d594ba6699f6ced0ce2c5147bad2d5d34d69524f1c0111836fa0931d4a6
6
+ metadata.gz: 738498c3f2f7cbea60cbe147069c7e834b8ea60fa63051afd82899c330f075b5b7b9cead2b219e4eec2be4d38bc085b9f5538f36e18841bd482f66176114a77a
7
+ data.tar.gz: 05dc719a00c3203e62b03aeac743e0c0bbaa2e7db90c59c38f5cebda1d638f1747ae72606cde6f3c376f725823e1086133e0ab594d674b3341911bbfca26d62f
data/bin/dapp CHANGED
@@ -5,6 +5,8 @@
5
5
  require 'rubygems'
6
6
  require 'dapp'
7
7
 
8
+ Thread.abort_on_exception = true
9
+
8
10
  begin
9
11
  begin
10
12
  begin
@@ -134,6 +134,7 @@ en:
134
134
  config_context_not_found: "Context `%{context_name}` is not found in config %{config_path}"
135
135
  server_connection_refused: "Kube server `%{url}` connection refused: %{error}"
136
136
  server_error: "Kube respond with server error code %{response_http_status}, request parameters: `%{request_parameters}`, response: `%{response_raw_body}`"
137
+ container_stuck: "Pod's `%{pod_name}` container `%{container_name}` stuck in %{state} state: %{state_reason}: %{state_message}"
137
138
  secret:
138
139
  bad_data: "Data `%{data}` can't be decrypted: check encryption key and data!"
139
140
  key_length_too_short: "Encryption key isn't valid (required size %{required_size} bytes)!"
data/lib/dapp.rb CHANGED
@@ -108,6 +108,7 @@ require 'dapp/kube/cli/command/kube/minikube_setup'
108
108
  require 'dapp/kube/cli/command/kube/chart_create'
109
109
  require 'dapp/kube/cli/command/kube/render'
110
110
  require 'dapp/kube/cli/command/kube/lint'
111
+ require 'dapp/kube/cli/command/kube/value_get'
111
112
  require 'dapp/kube/cli/cli'
112
113
  require 'dapp/kube/dapp/command/common'
113
114
  require 'dapp/kube/dapp/command/deploy'
@@ -121,6 +122,7 @@ require 'dapp/kube/dapp/command/minikube_setup'
121
122
  require 'dapp/kube/dapp/command/chart_create'
122
123
  require 'dapp/kube/dapp/command/render'
123
124
  require 'dapp/kube/dapp/command/lint'
125
+ require 'dapp/kube/dapp/command/value_get'
124
126
  require 'dapp/kube/dapp/dapp'
125
127
  require 'dapp/dimg'
126
128
  require 'dapp/dimg/builder'
@@ -81,7 +81,7 @@ module Dapp
81
81
  message = success_message
82
82
  start = Time.now
83
83
  with_log_indent { yield }
84
- rescue Error::Default, SignalException, StandardError => _e
84
+ rescue Error::Base, SignalException, StandardError => _e
85
85
  message = failed_message
86
86
  raise
87
87
  ensure
@@ -46,10 +46,24 @@ module Dapp
46
46
  shellout! "ssh-add #{ssh_key_path}", env: { SSH_AUTH_SOCK: ssh_auth_sock(force_run_agent: true) }
47
47
  end
48
48
 
49
+ def ssh_agent_exist?
50
+ ENV['SSH_AUTH_SOCK'] && File.exist?(ENV['SSH_AUTH_SOCK'])
51
+ end
52
+
53
+ def default_ssh_keys
54
+ @default_ssh_keys ||= begin
55
+ %w(id_rsa id_dsa).map do |path|
56
+ File.join(ENV["HOME"], ".ssh", path)
57
+ end.select do |path|
58
+ File.exist? path
59
+ end
60
+ end
61
+ end
62
+
49
63
  def ssh_auth_sock(force_run_agent: false)
50
64
  @ssh_auth_sock ||= begin
51
65
  system_ssh_auth_sock = nil
52
- system_ssh_auth_sock = File.expand_path(ENV['SSH_AUTH_SOCK']) if ENV['SSH_AUTH_SOCK'] && File.exist?(ENV['SSH_AUTH_SOCK'])
66
+ system_ssh_auth_sock = File.expand_path(ENV['SSH_AUTH_SOCK']) if ssh_agent_exist?
53
67
 
54
68
  if force_run_agent
55
69
  run_ssh_agent.tap { |ssh_auth_sock| ENV['SSH_AUTH_SOCK'] = ssh_auth_sock }
@@ -60,13 +74,17 @@ module Dapp
60
74
  end
61
75
 
62
76
  def setup_ssh_agent
63
- return unless options[:ssh_key]
64
-
65
- options[:ssh_key].each do |ssh_key|
66
- raise Error::Dapp, code: :ssh_key_not_found, data: { path: ssh_key } unless File.exist? ssh_key
77
+ if options[:ssh_key]
78
+ options[:ssh_key].each do |ssh_key|
79
+ raise Error::Dapp, code: :ssh_key_not_found, data: { path: ssh_key } unless File.exist? ssh_key
67
80
 
68
- File.chmod 0o600, ssh_key
69
- add_ssh_key ssh_key
81
+ File.chmod 0o600, ssh_key
82
+ add_ssh_key ssh_key
83
+ end
84
+ elsif (not ssh_agent_exist?) and default_ssh_keys.any?
85
+ default_ssh_keys.each do |ssh_key|
86
+ add_ssh_key ssh_key
87
+ end
70
88
  end
71
89
  end
72
90
  end # SshAgent
@@ -1,7 +1,7 @@
1
1
  module Dapp::Kube::CLI
2
2
  module Command
3
3
  class Kube < ::Dapp::CLI
4
- SUBCOMMANDS = ['secret generate', 'secret key generate', 'secret regenerate', 'deploy', 'dismiss', 'secret extract', 'secret edit', 'minikube setup', 'chart create', 'render', 'lint'].freeze
4
+ SUBCOMMANDS = ['secret generate', 'secret key generate', 'secret regenerate', 'deploy', 'dismiss', 'secret extract', 'secret edit', 'minikube setup', 'chart create', 'render', 'lint', 'value get'].freeze
5
5
 
6
6
  banner <<BANNER.freeze
7
7
  Usage: dapp kube subcommand [subcommand options]
@@ -19,6 +19,7 @@ Available subcommands: (for details, dapp kube SUB-COMMAND --help)
19
19
  dapp kube chart create [options]
20
20
  dapp kube render [options] [REPO]
21
21
  dapp kube lint [options] [REPO]
22
+ dapp kube value get VALUE_KEY
22
23
 
23
24
  Options:
24
25
  BANNER
@@ -45,6 +45,12 @@ BANNER
45
45
  option :registry_password,
46
46
  long: '--registry-password PASSWORD'
47
47
 
48
+ option :without_registry,
49
+ long: "--without-registry",
50
+ default: false,
51
+ boolean: true,
52
+ description: "Do not connect to docker registry to obtain docker image ids of dimgs being deployed."
53
+
48
54
  def run(argv = ARGV)
49
55
  self.class.parse_options(self, argv)
50
56
  run_dapp_command(nil, options: cli_options, log_running_time: false) do |dapp|
@@ -0,0 +1,48 @@
1
+ module Dapp::Kube::CLI::Command
2
+ class Kube < ::Dapp::CLI
3
+ class ValueGet < Base
4
+ banner <<BANNER.freeze
5
+ Usage:
6
+
7
+ dapp kube value get [options] VALUE_KEY [REPO]
8
+
9
+ Options:
10
+ BANNER
11
+ extend ::Dapp::CLI::Command::Options::Tag
12
+
13
+ option :namespace,
14
+ long: '--namespace NAME',
15
+ default: nil
16
+
17
+ option :registry_username,
18
+ long: '--registry-username USERNAME'
19
+
20
+ option :registry_password,
21
+ long: '--registry-password PASSWORD'
22
+
23
+ option :without_registry,
24
+ long: "--without-registry",
25
+ default: false,
26
+ boolean: true,
27
+ description: "Do not connect to docker registry to obtain docker image ids of dimgs being deployed."
28
+
29
+ def run(argv = ARGV)
30
+ self.class.parse_options(self, argv)
31
+
32
+ run_dapp_command(nil, options: cli_options, log_running_time: false) do |dapp|
33
+ repo = if not cli_arguments[1].nil?
34
+ self.class.required_argument(self, "repo")
35
+ else
36
+ dapp.name
37
+ end
38
+ dapp.options[:repo] = repo
39
+
40
+ value_key = self.class.required_argument(self, "VALUE_KEY")
41
+
42
+ dapp.public_send(run_method, value_key)
43
+ end
44
+ end
45
+
46
+ end
47
+ end
48
+ end
@@ -6,7 +6,6 @@ module Dapp
6
6
  def kube_deploy
7
7
  helm_release do |release|
8
8
  do_deploy = proc do
9
- kube_flush_hooks_jobs(release)
10
9
  kube_run_deploy(release)
11
10
  end
12
11
 
@@ -23,7 +22,7 @@ module Dapp
23
22
  .reject { |job| ['0', 'false'].include? job.annotations["dapp/recreate"].to_s }
24
23
  .select { |job| kube_job_list.include? job.name }
25
24
  .each do |job|
26
- log_process("Delete hooks job `#{job.name}` for release #{release.name}", short: true) do
25
+ log_process("Delete hooks job `#{job.name}`", short: true) do
27
26
  kube_delete_job!(job.name) unless dry_run?
28
27
  end
29
28
  end
@@ -43,6 +42,8 @@ module Dapp
43
42
 
44
43
  def kube_run_deploy(release)
45
44
  log_process("Deploy release #{release.name}") do
45
+ kube_flush_hooks_jobs(release)
46
+
46
47
  release_exists = shellout("helm status #{release.name}").status.success?
47
48
 
48
49
  watch_hooks_by_type = release.jobs.values
@@ -69,18 +70,49 @@ module Dapp
69
70
  end
70
71
 
71
72
  watch_hooks_thr = nil
72
- unless dry_run?
73
+ watch_hooks_condition_mutex = ::Mutex.new
74
+ watch_hooks_condition = ::ConditionVariable.new
75
+ deploy_has_began = false
76
+ unless dry_run? and watch_hooks.any?
73
77
  watch_hooks_thr = Thread.new do
74
- watch_hooks.each {|job| Kubernetes::Manager::Job.new(self, job.name).watch_till_done!}
75
- end
76
- end
78
+ watch_hooks_condition_mutex.synchronize do
79
+ while not deploy_has_began do
80
+ watch_hooks_condition.wait(watch_hooks_condition_mutex)
81
+ end
82
+ end
83
+
84
+ begin
85
+ watch_hooks.each do |job|
86
+ Kubernetes::Manager::Job.new(self, job.name).watch_till_done!
87
+ end # watch_hooks.each
88
+ rescue Kubernetes::Error::Default => e
89
+ # Default-ошибка -- это ошибка для пользователя которую перехватывает и
90
+ # показывает bin/dapp, а затем dapp выходит с ошибкой.
91
+ # Нельзя убивать родительский поток по Default-ошибке
92
+ # из-за того, что в этот момент в нем вероятно работает helm,
93
+ # а процесс деплоя в helm прерывать не стоит.
94
+ # Поэтому перехватываем и просто отображаем произошедшую
95
+ # ошибку для информации пользователю без завершения работы dapp.
96
+ $stderr.puts(::Dapp::Dapp.paint_string(::Dapp::Helper::NetStatus.message(e), :warning))
97
+ end
98
+
99
+ end # Thread
100
+ end # unless
77
101
 
78
102
  deployment_managers = release.deployments.values
79
103
  .map {|deployment| Kubernetes::Manager::Deployment.new(self, deployment.name)}
80
104
 
81
105
  deployment_managers.each(&:before_deploy)
82
106
 
83
- release.deploy!
107
+ log_process("Run helm") do
108
+ watch_hooks_condition_mutex.synchronize do
109
+ deploy_has_began = true
110
+ # Фактически гарантируется лишь вывод сообщения log_process перед выводом из потока watch_thr
111
+ watch_hooks_condition.signal
112
+ end
113
+
114
+ release.deploy!
115
+ end
84
116
 
85
117
  deployment_managers.each(&:after_deploy)
86
118
 
@@ -0,0 +1,32 @@
1
+ module Dapp
2
+ module Kube
3
+ module Dapp
4
+ module Command
5
+ module ValueGet
6
+ def kube_value_get(value_key)
7
+ service_values = Helm::Values.service_values_hash(
8
+ self, option_repo, kube_namespace, option_tags.first,
9
+ without_registry: self.options[:without_registry],
10
+ disable_warnings: true
11
+ )
12
+
13
+ res = service_values
14
+ value_key.split(".").each do |value_key_part|
15
+ if res.is_a?(Hash) && res.key?(value_key_part)
16
+ res = res[value_key_part]
17
+ else
18
+ exit(1)
19
+ end
20
+ end
21
+
22
+ if res.is_a? Hash
23
+ puts YAML.dump(res)
24
+ else
25
+ puts JSON.dump(res)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -15,6 +15,7 @@ module Dapp
15
15
  include Command::ChartCreate
16
16
  include Command::Render
17
17
  include Command::Lint
18
+ include Command::ValueGet
18
19
  include Command::Common
19
20
  end
20
21
  end
@@ -8,7 +8,7 @@ module Dapp
8
8
  self.new(service_values_hash(*a, &b))
9
9
  end
10
10
 
11
- def service_values_hash(dapp, repo, namespace, docker_tag, fake: false, without_registry: false)
11
+ def service_values_hash(dapp, repo, namespace, docker_tag, fake: false, without_registry: false, disable_warnings: false)
12
12
  res = {
13
13
  "global" => {
14
14
  "namespace" => namespace,
@@ -86,7 +86,9 @@ module Dapp
86
86
  dimg_labels = dapp.dimg_registry(repo).image_labels(docker_tag, dimg.config._name)
87
87
  docker_image_id = dapp.dimg_registry(repo).image_id(docker_tag, dimg.config._name)
88
88
  rescue ::Dapp::Dimg::Error::Registry => err
89
- dapp.log_warning "Registry `#{err.net_status[:data][:registry]}` is not availabble: cannot determine <dimg>.docker_image_id and <dimg>.git.<ga>.commit_id helm values of dimg#{dimg.config._name ? " `#{dimg.config._name}`" : nil}"
89
+ unless disable_warnings
90
+ dapp.log_warning "Registry `#{err.net_status[:data][:registry]}` is not availabble: cannot determine <dimg>.docker_image_id and <dimg>.git.<ga>.commit_id helm values of dimg#{dimg.config._name ? " `#{dimg.config._name}`" : nil}"
91
+ end
90
92
  end
91
93
  end
92
94
 
@@ -28,6 +28,21 @@ module Dapp
28
28
  pod = Kubernetes::Client::Resource::Pod.new(dapp.kubernetes.pod(pod_manager.name))
29
29
  container_state, container_state_data = pod.container_state(name)
30
30
 
31
+ if container_state == "waiting"
32
+ if container_state_data["reason"] == "RunContainerError"
33
+ raise Kubernetes::Error::Default, code: :container_stuck, data: {
34
+ state_reason: container_state_data["reason"],
35
+ state_message: container_state_data["message"],
36
+ state: container_state,
37
+ pod_name: pod_manager.name,
38
+ container_name: name
39
+ }
40
+ else
41
+ sleep 0.1
42
+ next
43
+ end
44
+ end
45
+
31
46
  chunk_lines_by_time = {}
32
47
  begin
33
48
  chunk_lines_by_time = dapp.kubernetes.pod_log(pod_manager.name, container: name, timestamps: true, sinceTime: @processed_log_till_time)
data/lib/dapp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = '0.23.1'.freeze
2
+ VERSION = '0.23.2'.freeze
3
3
  BUILD_CACHE_VERSION = 26
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.23.1
4
+ version: 0.23.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-09 00:00:00.000000000 Z
11
+ date: 2018-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout
@@ -663,6 +663,7 @@ files:
663
663
  - lib/dapp/kube/cli/command/kube/secret_generate.rb
664
664
  - lib/dapp/kube/cli/command/kube/secret_key_generate.rb
665
665
  - lib/dapp/kube/cli/command/kube/secret_regenerate.rb
666
+ - lib/dapp/kube/cli/command/kube/value_get.rb
666
667
  - lib/dapp/kube/dapp/command/chart_create.rb
667
668
  - lib/dapp/kube/dapp/command/common.rb
668
669
  - lib/dapp/kube/dapp/command/deploy.rb
@@ -675,6 +676,7 @@ files:
675
676
  - lib/dapp/kube/dapp/command/secret_generate.rb
676
677
  - lib/dapp/kube/dapp/command/secret_key_generate.rb
677
678
  - lib/dapp/kube/dapp/command/secret_regenerate.rb
679
+ - lib/dapp/kube/dapp/command/value_get.rb
678
680
  - lib/dapp/kube/dapp/dapp.rb
679
681
  - lib/dapp/kube/error/default.rb
680
682
  - lib/dapp/kube/error/kubernetes.rb
@@ -719,7 +721,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
719
721
  version: 2.5.0
720
722
  requirements: []
721
723
  rubyforge_project:
722
- rubygems_version: 2.5.1
724
+ rubygems_version: 2.7.4
723
725
  signing_key:
724
726
  specification_version: 4
725
727
  summary: Build docker packaged apps using chef or shell