dapp 0.5.0 → 0.5.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
  SHA1:
3
- metadata.gz: 344169cb4810496ce7bdffabb39b0e0d67d922be
4
- data.tar.gz: 80300942c9abcfd25956099e7680d06c980deba1
3
+ metadata.gz: 179056218ee2a02f2ffdfde2690975b9488688ab
4
+ data.tar.gz: 3d11dfb1d6681698baf231ca52977fffeea3f89b
5
5
  SHA512:
6
- metadata.gz: 6c9f6344686884f6be5132acad1e4be8a433dbdc7362b07a0e9cdede2d45aeebf699536d4860e7b82d69c060ffee7c52c796488181cd0c2fba140817ed3ae592
7
- data.tar.gz: d7ec6ba5e7adcaa342c64cb5258e1cb74a6a4579d522e13c863dee0e24a0c9fdb4df04fcc80cbd463ad5a7c6a0c54206017da8e8421775a5d2ba402a1cd952a9
6
+ metadata.gz: 45d2a40d9f64aed890272df4ec5c1e3a488f8b3d58cfa4018272a03ce33f012a81a80c8ac4dc60967cc3933aabb3d0b1058ea519fc504b8b2e5f533e5b6e75c4
7
+ data.tar.gz: 824abefb9e41019be8fb285a2b6350d05803382c4d1003ac4e6938149cbd50c1a2fe955801678ef0c3dc80a0b596f9e51cc5d8684b845d273aab1f9a0695b331
@@ -82,22 +82,6 @@ module Dapp
82
82
  application.hashsum berksfile_lock_path.read if berksfile_lock_path.exist?
83
83
  end
84
84
 
85
- def local_cookbook_paths_for_checksum
86
- @local_cookbook_paths_for_checksum ||= berksfile
87
- .local_cookbooks
88
- .values
89
- .map { |cookbook| cookbook[:path] }
90
- .product(LOCAL_COOKBOOK_CHECKSUM_PATTERNS)
91
- .map { |cb, dir| Dir[cb.join(dir)] }
92
- .flatten
93
- .map(&Pathname.method(:new))
94
- end
95
-
96
- def stage_cookbooks_paths_for_checksum(stage)
97
- install_stage_cookbooks(stage)
98
- Dir[stage_cookbooks_path(stage, '**/*')].map(&Pathname.method(:new))
99
- end
100
-
101
85
  def stage_cookbooks_checksum_path(stage)
102
86
  application.build_path("#{cookbooks_checksum}.#{stage}.checksum")
103
87
  end
@@ -109,8 +93,11 @@ module Dapp
109
93
  checksum = if stage == :chef_cookbooks
110
94
  cookbooks_checksum
111
95
  else
96
+ paths = Dir[stage_cookbooks_path(stage, '**/*')].map(&Pathname.method(:new))
97
+
112
98
  application.hashsum [
113
- _paths_checksum(stage_cookbooks_paths_for_checksum(stage)),
99
+ application.paths_content_hashsum(paths),
100
+ *paths.map { |p| p.relative_path_from(stage_cookbooks_path(stage)).to_s }.sort,
114
101
  *enabled_modules,
115
102
  stage == :infra_install ? chefdk_image : nil
116
103
  ].compact
@@ -122,11 +109,23 @@ module Dapp
122
109
  end
123
110
 
124
111
  def cookbooks_checksum
125
- @cookbooks_checksum ||= application.hashsum [
126
- berksfile_lock_checksum,
127
- _paths_checksum(local_cookbook_paths_for_checksum),
128
- *enabled_modules
129
- ]
112
+ @cookbooks_checksum ||= begin
113
+ paths = berksfile
114
+ .local_cookbooks
115
+ .values
116
+ .map { |cookbook| cookbook[:path] }
117
+ .product(LOCAL_COOKBOOK_CHECKSUM_PATTERNS)
118
+ .map { |cb, dir| Dir[cb.join(dir)] }
119
+ .flatten
120
+ .map(&Pathname.method(:new))
121
+
122
+ application.hashsum [
123
+ application.paths_content_hashsum(paths),
124
+ *paths.map { |p| p.relative_path_from(berksfile.home_path).to_s }.sort,
125
+ berksfile_lock_checksum,
126
+ *enabled_modules
127
+ ]
128
+ end
130
129
  end
131
130
 
132
131
  def chefdk_image
@@ -193,8 +192,6 @@ module Dapp
193
192
  "dappdeps/berksdeps:0.1.0 bash -ec '#{application.shellout_pack(vendor_commands.join(' && '))}'"].compact.join(' '),
194
193
  log_verbose: application.log_verbose?
195
194
  )
196
-
197
- true
198
195
  end
199
196
  end
200
197
  # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
@@ -211,80 +208,77 @@ module Dapp
211
208
 
212
209
  # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
213
210
  def install_stage_cookbooks(stage)
214
- @install_stage_cookbooks ||= {}
215
- @install_stage_cookbooks[stage] ||= true.tap do
216
- common_paths = proc do |cookbook_path|
217
- [['metadata.json', 'metadata.json'],
218
- ['attributes/common', 'attributes'],
219
- ["attributes/#{stage}", 'attributes'],
220
- ["files/#{stage}", 'files/default'],
221
- ["templates/#{stage}", 'templates/default']].select { |from, _| cookbook_path.join(from).exist? }
222
- end
211
+ common_paths = proc do |cookbook_path|
212
+ [['metadata.json', 'metadata.json'],
213
+ ['attributes/common', 'attributes'],
214
+ ["attributes/#{stage}", 'attributes'],
215
+ ["files/#{stage}", 'files/default'],
216
+ ["templates/#{stage}", 'templates/default']].select { |from, _| cookbook_path.join(from).exist? }
217
+ end
223
218
 
224
- install_paths = Dir[cookbooks_vendor_path('*')]
225
- .map(&Pathname.method(:new))
226
- .map do |cookbook_path|
227
- cookbook_name = File.basename cookbook_path
228
- is_project = (cookbook_name == project_name)
229
- is_mdapp = cookbook_name.start_with? 'mdapp-'
230
- mdapp_name = (is_mdapp ? cookbook_name.split('mdapp-')[1] : nil)
231
- mdapp_enabled = is_mdapp && enabled_modules.include?(mdapp_name)
232
-
233
- paths = if is_project
234
- recipe_paths = enabled_recipes
235
- .map { |recipe| ["recipes/#{stage}/#{recipe}.rb", "recipes/#{recipe}.rb"] }
236
- .select { |from, _| cookbook_path.join(from).exist? }
237
-
238
- if recipe_paths.any?
239
- [*recipe_paths, *common_paths[cookbook_path]]
240
- else
241
- [nil, *common_paths[cookbook_path]]
242
- end
243
- elsif is_mdapp && mdapp_enabled
244
- recipe_path = "recipes/#{stage}.rb"
245
-
246
- if cookbook_path.join(recipe_path).exist?
247
- [[recipe_path, recipe_path], *common_paths[cookbook_path]]
248
- else
249
- [nil, *common_paths[cookbook_path]]
250
- end
219
+ install_paths = Dir[cookbooks_vendor_path('*')]
220
+ .map(&Pathname.method(:new))
221
+ .map do |cookbook_path|
222
+ cookbook_name = File.basename cookbook_path
223
+ is_project = (cookbook_name == project_name)
224
+ is_mdapp = cookbook_name.start_with? 'mdapp-'
225
+ mdapp_name = (is_mdapp ? cookbook_name.split('mdapp-')[1] : nil)
226
+ mdapp_enabled = is_mdapp && enabled_modules.include?(mdapp_name)
227
+
228
+ paths = if is_project
229
+ recipe_paths = enabled_recipes
230
+ .map { |recipe| ["recipes/#{stage}/#{recipe}.rb", "recipes/#{recipe}.rb"] }
231
+ .select { |from, _| cookbook_path.join(from).exist? }
232
+
233
+ if recipe_paths.any?
234
+ [*recipe_paths, *common_paths[cookbook_path]]
251
235
  else
252
- [['.', '.']]
236
+ [nil, *common_paths[cookbook_path]]
253
237
  end
238
+ elsif is_mdapp && mdapp_enabled
239
+ recipe_path = "recipes/#{stage}.rb"
254
240
 
255
- [cookbook_path, paths] if paths && paths.any?
256
- end.compact
257
-
258
- stage_cookbooks_path(stage).mkpath
259
- install_paths.each do |cookbook_path, paths|
260
- cookbook = cookbook_path.basename
261
-
262
- paths.each do |from, to|
263
- if from.nil?
264
- to_path = stage_cookbooks_path(stage, cookbook, 'recipes/void.rb')
265
- to_path.parent.mkpath
266
- FileUtils.touch to_path
267
- else
268
- from_path = cookbook_path.join(from)
269
- to_path = stage_cookbooks_path(stage, cookbook, to)
270
- if from_path.directory? && to_path.exist?
271
- Dir[from_path.join('**/*')]
272
- .map(&Pathname.method(:new))
273
- .each do |from_subpath|
274
- to_subpath = to_path.join(from_subpath.relative_path_from(from_path))
275
- raise Error, code: :stage_path_overlap,
276
- data: { stage: stage,
277
- cookbook: cookbook,
278
- from: from_subpath.relative_path_from(cookbook_path),
279
- to: to_subpath.relative_path_from(stage_cookbooks_path(stage, cookbook)) } if to_subpath.exist?
280
-
281
- to_subpath.parent.mkpath
282
- FileUtils.cp_r from_subpath, to_subpath
241
+ if cookbook_path.join(recipe_path).exist?
242
+ [[recipe_path, recipe_path], *common_paths[cookbook_path]]
243
+ else
244
+ [nil, *common_paths[cookbook_path]]
283
245
  end
284
- else
285
- to_path.parent.mkpath
286
- FileUtils.cp_r from_path, to_path
287
- end
246
+ else
247
+ [['.', '.']]
248
+ end
249
+
250
+ [cookbook_path, paths] if paths && paths.any?
251
+ end.compact
252
+
253
+ _stage_cookbooks_path(stage).mkpath
254
+ install_paths.each do |cookbook_path, paths|
255
+ cookbook = cookbook_path.basename
256
+
257
+ paths.each do |from, to|
258
+ if from.nil?
259
+ to_path = _stage_cookbooks_path(stage).join(cookbook, 'recipes/void.rb')
260
+ to_path.parent.mkpath
261
+ FileUtils.touch to_path
262
+ else
263
+ from_path = cookbook_path.join(from)
264
+ to_path = _stage_cookbooks_path(stage).join(cookbook, to)
265
+ if from_path.directory? && to_path.exist?
266
+ Dir[from_path.join('**/*')]
267
+ .map(&Pathname.method(:new))
268
+ .each do |from_subpath|
269
+ to_subpath = to_path.join(from_subpath.relative_path_from(from_path))
270
+ raise Error, code: :stage_path_overlap,
271
+ data: { stage: stage,
272
+ cookbook: cookbook,
273
+ from: from_subpath.relative_path_from(cookbook_path),
274
+ to: to_subpath.relative_path_from(_stage_cookbooks_path(stage).join(cookbook)) } if to_subpath.exist?
275
+
276
+ to_subpath.parent.mkpath
277
+ FileUtils.cp_r from_subpath, to_subpath
278
+ end
279
+ else
280
+ to_path.parent.mkpath
281
+ FileUtils.cp_r from_path, to_path
288
282
  end
289
283
  end
290
284
  end
@@ -294,8 +288,6 @@ module Dapp
294
288
 
295
289
  # rubocop:disable Metrics/AbcSize
296
290
  def stage_cookbooks_runlist(stage)
297
- install_stage_cookbooks(stage)
298
-
299
291
  @stage_cookbooks_runlist ||= {}
300
292
  @stage_cookbooks_runlist[stage] ||= begin
301
293
  res = []
@@ -344,8 +336,15 @@ module Dapp
344
336
  stage_cookbooks_runlist(stage).empty?
345
337
  end
346
338
 
339
+ def _stage_cookbooks_path(stage)
340
+ stage_build_path(stage, 'cookbooks')
341
+ end
342
+
347
343
  def stage_cookbooks_path(stage, *path)
348
- stage_build_path(stage, 'cookbooks', *path)
344
+ _stage_cookbooks_path(stage).tap do |cookbooks_path|
345
+ @install_stage_cookbooks ||= {}
346
+ @install_stage_cookbooks[stage] ||= true.tap { install_stage_cookbooks(stage) }
347
+ end.join(*path)
349
348
  end
350
349
 
351
350
  def install_chef_solo_stage_config(stage)
@@ -370,15 +369,6 @@ module Dapp
370
369
  def container_stage_build_path(_stage, *path)
371
370
  path.compact.map(&:to_s).inject(Pathname.new('/.dapp/chef/build'), &:+)
372
371
  end
373
-
374
- def _paths_checksum(paths)
375
- application.hashsum [
376
- *paths.map(&:to_s).sort,
377
- *paths.reject(&:directory?)
378
- .sort
379
- .reduce(nil) { |a, e| application.hashsum [a, e.read].compact }
380
- ]
381
- end
382
372
  end
383
373
  end
384
374
  end
@@ -26,6 +26,7 @@ module Dapp
26
26
  end
27
27
  end # Parser
28
28
 
29
+ attr_reader :home_path
29
30
  attr_reader :path
30
31
  attr_reader :local_cookbooks
31
32
 
@@ -39,7 +40,7 @@ module Dapp
39
40
  def add_local_cookbook_path(name, path)
40
41
  @local_cookbooks[name] = {
41
42
  name: name,
42
- path: @home_path.join(path)
43
+ path: home_path.join(path)
43
44
  }
44
45
  end
45
46
 
@@ -6,6 +6,13 @@ module Dapp
6
6
  sha256(arg)
7
7
  end
8
8
 
9
+ def paths_content_hashsum(paths)
10
+ paths.map(&:to_s)
11
+ .reject { |path| File.directory?(path) }
12
+ .sort
13
+ .reduce(nil) { |hash, path| hashsum [hash, File.read(path)].compact }
14
+ end
15
+
9
16
  def sha256(arg)
10
17
  Digest::SHA256.hexdigest Array(arg).compact.map(&:to_s).join(':::')
11
18
  end
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  module Dapp
3
- VERSION = '0.5.0'.freeze
3
+ VERSION = '0.5.1'.freeze
4
4
  BUILD_CACHE_VERSION = 2
5
5
  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.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-11 00:00:00.000000000 Z
11
+ date: 2016-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout