dapp 0.13.19 → 0.13.20

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
  SHA1:
3
- metadata.gz: 38c5fab04c8e1983a3f844993553bfb70e17fbd8
4
- data.tar.gz: f842b2277f5d980d7142c8a7cc634e02e0ab9c7e
3
+ metadata.gz: 76cb1be7940f4087220a9b04e6d8352cfecae333
4
+ data.tar.gz: 2a0af558bbf26b660f8bd53524bf8c1cfde2692d
5
5
  SHA512:
6
- metadata.gz: f66a88d08eb638b1fa6182756ba003db7170846b960d8bebd0cb679ed27cf0b09f3379d3f57ae587c16567332f46ba98aea305e4decf206586858454a1b7cb7a
7
- data.tar.gz: fd392a3aff576ce4ba99336a7eea0bc37d6d2188a75175676ad6756af4327bfd03c2725a6370ed1730ea90d790fbdc272f531ec4133157243520fbe8c8beea72
6
+ metadata.gz: 59003aea36976ff49f4687fdca7052a32643617c21aa0bb6dfba445a865c1f66b46421bc1b8a3ef7fc1d68225a41f529ddf068d8a6a0c2ae7dd14952b2da886a
7
+ data.tar.gz: 1249d96364c8bddee9d369513c146c0e20710f0efa20d00942ce846ac502841043b94634c704fc7947fc3aebcc594080e40089a17bea75a6a546ba76541060c2
@@ -9,6 +9,10 @@ module Dapp
9
9
  !!@_dev_mode
10
10
  end
11
11
 
12
+ def after_parsing!
13
+ do_all!('_after_parsing!')
14
+ end
15
+
12
16
  def validate!
13
17
  do_all!('_validate!')
14
18
  end
@@ -48,21 +48,22 @@ module Dapp
48
48
 
49
49
  def pass_to(obj, clone_method = :clone)
50
50
  passed_directives.each do |directive|
51
- next if (variable = instance_variable_get(directive)).nil?
52
-
53
- obj.instance_variable_set(directive, begin
54
- case variable
55
- when Base then variable.public_send(clone_method)
56
- when String, Symbol, Integer, TrueClass, FalseClass then variable
57
- when Array, Hash then marshal_clone(variable)
58
- else
59
- raise
60
- end
61
- end)
51
+ obj.instance_variable_set(directive, clone_variable(instance_variable_get(directive), clone_method))
62
52
  end
63
53
  obj
64
54
  end
65
55
 
56
+ def clone_variable(var, clone_method = :clone)
57
+ case var
58
+ when Base then var.public_send(clone_method)
59
+ when String, Symbol, Integer, TrueClass, FalseClass then var
60
+ when Array, Hash then marshal_clone(var)
61
+ when NilClass then nil
62
+ else
63
+ raise
64
+ end
65
+ end
66
+
66
67
  def passed_directives
67
68
  []
68
69
  end
@@ -78,10 +79,7 @@ module Dapp
78
79
  end
79
80
 
80
81
  def marshal_load(variable_values)
81
- variable_values.each do |variable, value|
82
- instance_variable_set(variable, value)
83
- end
84
-
82
+ variable_values.each { |variable, value| instance_variable_set(variable, clone_variable(value)) }
85
83
  self
86
84
  end
87
85
 
@@ -33,6 +33,7 @@ module Dapp
33
33
  ::Dapp::Config::Config.new(dapp: self).tap do |config|
34
34
  begin
35
35
  config.instance_eval File.read(dappfile_path), dappfile_path
36
+ config.after_parsing!
36
37
  config.validate!
37
38
  rescue SyntaxError, StandardError => e
38
39
  backtrace = e.backtrace.find { |line| line.start_with?(dappfile_path) }
@@ -17,10 +17,10 @@ module Dapp
17
17
  group = artifact[:options][:group]
18
18
  to = artifact[:options][:to]
19
19
 
20
- command = safe_cp(cwd, artifact_dimg.container_tmp_path(artifact_name).to_s, nil, nil, include_paths, exclude_paths)
20
+ command = safe_cp(cwd, artifact_dimg.container_tmp_path(artifact_name, 'data').to_s, nil, nil, include_paths, exclude_paths)
21
21
  run_artifact_dimg(artifact_dimg, artifact_name, command)
22
22
 
23
- command = safe_cp(dimg.container_tmp_path('artifact', artifact_name).to_s, to, owner, group, include_paths, exclude_paths)
23
+ command = safe_cp(dimg.container_tmp_path('artifact', artifact_name, 'data').to_s, to, owner, group, include_paths, exclude_paths)
24
24
  image.add_command command
25
25
  image.add_volume "#{dimg.tmp_path('artifact', artifact_name)}:#{dimg.container_tmp_path('artifact', artifact_name)}:ro"
26
26
  end
@@ -71,7 +71,7 @@ module Dapp
71
71
 
72
72
  # Слэш после from — это инструкция rsync'у для копирования
73
73
  # содержимого директории from, а не самой директории.
74
- cmd << " #{from}/ #{to}"
74
+ cmd << " $(if [ -d #{from} ] ; then echo #{from}/ ; else echo #{from} ; fi) #{to}"
75
75
  end
76
76
  end
77
77
  # rubocop:enable Metrics/ParameterLists
@@ -8,6 +8,10 @@ module Dapp
8
8
 
9
9
  protected
10
10
 
11
+ def dimg_after_parsing!
12
+ _dimg.each(&:artifacts_after_parsing!)
13
+ end
14
+
11
15
  def dimg_config_validate!
12
16
  raise Error::Config, code: :dimg_name_required if _dimg.any? { |dimg| dimg._name.nil? } && _dimg.size > 1
13
17
  _dimg.each(&:validate!)
@@ -130,6 +130,10 @@ module Dapp
130
130
  end
131
131
  end
132
132
 
133
+ def artifacts_after_parsing!
134
+ _artifacts_auto_excluding!
135
+ end
136
+
133
137
  protected
134
138
 
135
139
  def builder(type)
@@ -140,6 +144,42 @@ module Dapp
140
144
  def passed_directives
141
145
  [:@_chef, :@_shell, :@_docker, :@_git_artifact, :@_mount, :@_artifact_groups, :@_builder]
142
146
  end
147
+
148
+ def _artifacts_auto_excluding!
149
+ path_to_relative = proc { |path| path.reverse.chomp('/').reverse }
150
+
151
+ all_artifacts.reduce({}) do |hash, artifact|
152
+ unless artifact._to.nil?
153
+ to_common = artifact._to[/^\/[^\/]*/]
154
+ hash[to_common] ||= []
155
+ hash[to_common] << artifact
156
+ end
157
+ hash
158
+ end.each do |to_common, artifacts|
159
+ include_paths_common = artifacts.reduce([]) do |arr, artifact|
160
+ arr << artifact._to.sub(to_common, '')
161
+ arr.concat(artifact._include_paths.map { |path| File.join(artifact._to.sub(to_common, ''), path) } )
162
+ arr
163
+ end.map(&path_to_relative).uniq
164
+
165
+ artifacts.each do |artifact|
166
+ artifact_include_shift = path_to_relative.call(artifact._to.sub(to_common, ''))
167
+
168
+ include_paths_common.each do |path|
169
+ next if artifact_include_shift.start_with? path
170
+
171
+ path = path_to_relative.call(path.sub(artifact_include_shift, ''))
172
+ unless artifact._exclude_paths.any? { |epath| path.start_with? epath }
173
+ artifact._exclude_paths << path
174
+ end
175
+ end
176
+ end
177
+ end
178
+ end
179
+
180
+ def all_artifacts
181
+ _artifact + _git_artifact._local + _git_artifact._remote
182
+ end
143
183
  end # InstanceMethods
144
184
  # rubocop:enable Metrics/ModuleLength
145
185
  end # Dimg
@@ -67,7 +67,7 @@ module Dapp
67
67
  end
68
68
 
69
69
  def validate_artifacts!
70
- artifacts = validate_artifact_format(validated_artifacts)
70
+ artifacts = validate_artifact_format(all_artifacts)
71
71
  loop do
72
72
  break if artifacts.empty?
73
73
  verifiable_artifact = artifacts.shift
@@ -133,10 +133,6 @@ module Dapp
133
133
  !(art._before.nil? && art._after.nil?)
134
134
  end
135
135
  end
136
-
137
- def validated_artifacts
138
- _artifact + _git_artifact._local + _git_artifact._remote
139
- end
140
136
  end # Validation
141
137
  # rubocop:enable Metrics/ModuleLength
142
138
  end # Dimg
@@ -106,13 +106,16 @@ module Dapp
106
106
  rescue Excon::Error::Timeout
107
107
  raise Error::Timeout
108
108
  rescue Error::Base => err
109
- if err.net_status[:code] == :bad_request and
110
- err.net_status[:data][:response_body] and
111
- err.net_status[:data][:response_body]['message'].end_with? 'ContainerCreating'
112
- raise Error::Pod::ContainerCreating, data: err.net_status[:data]
113
- else
114
- raise
109
+ if err.net_status[:code] == :bad_request and err.net_status[:data][:response_body]
110
+ msg = err.net_status[:data][:response_body]['message']
111
+ if msg.end_with? 'ContainerCreating'
112
+ raise Error::Pod::ContainerCreating, data: err.net_status[:data]
113
+ elsif msg.end_with? 'PodInitializing'
114
+ raise Error::Pod::PodInitializing, data: err.net_status[:data]
115
+ end
115
116
  end
117
+
118
+ raise
116
119
  end
117
120
 
118
121
  def event_list(**query_parameters)
@@ -19,11 +19,18 @@ module Dapp
19
19
 
20
20
  module Pod
21
21
  class NotFound < Kubernetes::Client::Error::NotFound ; end
22
+
22
23
  class ContainerCreating < Kubernetes::Client::Error::Base
23
24
  def initialize(**net_status)
24
25
  super({code: :container_creating}.merge(net_status))
25
26
  end
26
27
  end
28
+
29
+ class PodInitializing < Kubernetes::Client::Error::Base
30
+ def initialize(**net_status)
31
+ super({code: :pod_initializing}.merge(net_status))
32
+ end
33
+ end
27
34
  end # Pod
28
35
  end # Kubernetes::Client::Error
29
36
  end # Kube
@@ -38,7 +38,7 @@ module Dapp
38
38
  [timestamp, data]
39
39
  end
40
40
  .reject {|timestamp, _| @processed_log_timestamps.include? timestamp}
41
- rescue Kubernetes::Client::Error::Pod::ContainerCreating
41
+ rescue Kubernetes::Client::Error::Pod::ContainerCreating, Kubernetes::Client::Error::Pod::PodInitializing
42
42
  sleep 0.1
43
43
  next
44
44
  end
@@ -129,7 +129,7 @@ module Dapp
129
129
  [timestamp, data]
130
130
  end
131
131
  }.compact
132
- rescue Kubernetes::Client::Error::Pod::ContainerCreating
132
+ rescue Kubernetes::Client::Error::Pod::ContainerCreating, Kubernetes::Client::Error::Pod::PodInitializing
133
133
  next
134
134
  end
135
135
 
data/lib/dapp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = '0.13.19'.freeze
3
- BUILD_CACHE_VERSION = 15
2
+ VERSION = '0.13.20'.freeze
3
+ BUILD_CACHE_VERSION = 16
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.13.19
4
+ version: 0.13.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-08-08 00:00:00.000000000 Z
11
+ date: 2017-08-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout