dapp 0.7.36 → 0.8.0

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/config/en/common.yml +1 -3
  3. data/config/en/net_status.yml +7 -9
  4. data/lib/dapp.rb +3 -1
  5. data/lib/dapp/artifact.rb +7 -2
  6. data/lib/dapp/build/stage/after_setup_artifact.rb +1 -1
  7. data/lib/dapp/build/stage/artifact_base.rb +1 -1
  8. data/lib/dapp/build/stage/artifact_default.rb +24 -43
  9. data/lib/dapp/build/stage/base.rb +35 -31
  10. data/lib/dapp/build/stage/build_artifact.rb +1 -1
  11. data/lib/dapp/build/stage/from.rb +1 -1
  12. data/lib/dapp/build/stage/ga_archive_dependencies.rb +10 -1
  13. data/lib/dapp/build/stage/ga_artifact_patch.rb +2 -2
  14. data/lib/dapp/build/stage/ga_base.rb +18 -5
  15. data/lib/dapp/build/stage/ga_dependencies_base.rb +1 -1
  16. data/lib/dapp/build/stage/ga_latest_patch.rb +10 -2
  17. data/lib/dapp/build/stage/import_artifact.rb +1 -1
  18. data/lib/dapp/build/stage/install/ga_pre_install_patch_dependencies.rb +0 -4
  19. data/lib/dapp/build/stage/install/install.rb +1 -1
  20. data/lib/dapp/build/stage/mod/logging.rb +2 -2
  21. data/lib/dapp/build/stage/setup/ga_post_setup_patch.rb +0 -4
  22. data/lib/dapp/build/stage/setup/ga_post_setup_patch_dependencies.rb +2 -2
  23. data/lib/dapp/build/stage/setup/ga_pre_setup_patch.rb +0 -4
  24. data/lib/dapp/build/stage/setup/setup.rb +1 -1
  25. data/lib/dapp/builder/base.rb +0 -7
  26. data/lib/dapp/builder/chef.rb +67 -408
  27. data/lib/dapp/builder/chef/berksfile.rb +78 -69
  28. data/lib/dapp/builder/chef/cookbook.rb +257 -0
  29. data/lib/dapp/builder/chef/cookbook_metadata.rb +54 -52
  30. data/lib/dapp/builder/none.rb +0 -6
  31. data/lib/dapp/cli/build.rb +8 -1
  32. data/lib/dapp/cli/stage_image.rb +1 -1
  33. data/lib/dapp/config/directive/base.rb +1 -3
  34. data/lib/dapp/config/directive/git_artifact_remote.rb +3 -6
  35. data/lib/dapp/dimg.rb +13 -14
  36. data/lib/dapp/dimg/path.rb +1 -9
  37. data/lib/dapp/error/tar_writer.rb +6 -0
  38. data/lib/dapp/git_artifact.rb +136 -37
  39. data/lib/dapp/git_repo/base.rb +44 -28
  40. data/lib/dapp/git_repo/own.rb +11 -7
  41. data/lib/dapp/git_repo/remote.rb +8 -45
  42. data/lib/dapp/image/docker.rb +9 -11
  43. data/lib/dapp/image/stage.rb +1 -1
  44. data/lib/dapp/project/chef.rb +2 -7
  45. data/lib/dapp/project/command/stages/cleanup_local.rb +1 -2
  46. data/lib/dapp/project/command/stages/cleanup_repo.rb +1 -2
  47. data/lib/dapp/version.rb +2 -2
  48. metadata +4 -3
  49. data/lib/dapp/build/stage/setup/chef_cookbooks.rb +0 -36
@@ -21,7 +21,15 @@ module Dapp
21
21
  end
22
22
 
23
23
  def dependencies
24
- [commit_list]
24
+ [].tap do |dependencies|
25
+ dependencies << commit_list
26
+ dependencies << dimg.local_git_artifacts.map { |git_artifact| git_artifact.dev_patch_hash(self) } if dimg.project.dev_mode?
27
+ end
28
+ end
29
+
30
+ def prepare_local_git_artifacts_command
31
+ return super unless dimg.project.dev_mode?
32
+ dimg.local_git_artifacts.each { |git_artifact| image.add_command git_artifact.apply_dev_patch_command(self) }
25
33
  end
26
34
 
27
35
  def layer_commit(git_artifact)
@@ -31,7 +39,7 @@ module Dapp
31
39
  end
32
40
 
33
41
  def empty?
34
- dependencies_empty?
42
+ dependencies_empty? || dimg.git_artifacts.all? { |git_artifact| !git_artifact.any_changes?(prev_g_a_stage.layer_commit(git_artifact)) }
35
43
  end
36
44
 
37
45
  private
@@ -8,7 +8,7 @@ module Dapp
8
8
  end
9
9
 
10
10
  def signature
11
- hashsum [*dependencies.flatten, change_options]
11
+ @signature ||= hashsum [*dependencies.flatten, change_options]
12
12
  end
13
13
 
14
14
  def image
@@ -14,10 +14,6 @@ module Dapp
14
14
  def dependencies
15
15
  next_stage.next_stage.context # Install
16
16
  end
17
-
18
- def empty?
19
- super || dependencies_empty?
20
- end
21
17
  end # GAPreInstallPatchDependencies
22
18
  end
23
19
  end # Stage
@@ -31,7 +31,7 @@ module Dapp
31
31
  private
32
32
 
33
33
  def install_dependencies_files_checksum
34
- @install_dependencies_files_checksum ||= dependencies_files_checksum(dimg.config._install_dependencies)
34
+ dependencies_files_checksum(dimg.config._install_dependencies)
35
35
  end
36
36
  end # Install
37
37
  end
@@ -7,7 +7,7 @@ module Dapp
7
7
  module Logging
8
8
  def log_image_build(&image_build)
9
9
  if empty? then log_state(:empty)
10
- elsif image.tagged? then log_state(:using_cache)
10
+ elsif image.built? then log_state(:using_cache)
11
11
  elsif should_be_not_present? then log_state(:not_present)
12
12
  elsif dimg.project.dry_run? then log_state(:build, styles: { status: :success })
13
13
  else log_image_build_process(&image_build)
@@ -91,7 +91,7 @@ module Dapp
91
91
  end
92
92
 
93
93
  def should_be_introspected?
94
- dimg.project.cli_options[:introspect_stage] == name && !dimg.project.dry_run? && !dimg.artifact?
94
+ dimg.stage_should_be_introspected?(name) && !dimg.project.dry_run?
95
95
  end
96
96
 
97
97
  def should_be_quiet?
@@ -11,10 +11,6 @@ module Dapp
11
11
  super
12
12
  end
13
13
 
14
- def prev_g_a_stage
15
- super.prev_stage # GAPreSetupPatch
16
- end
17
-
18
14
  def next_g_a_stage
19
15
  next_stage.next_stage
20
16
  end
@@ -9,7 +9,7 @@ module Dapp
9
9
  MAX_PATCH_SIZE = 1024 * 1024
10
10
 
11
11
  def initialize(dimg, next_stage)
12
- @prev_stage = ChefCookbooks.new(dimg, self)
12
+ @prev_stage = Setup.new(dimg, self)
13
13
  super
14
14
  end
15
15
 
@@ -21,7 +21,7 @@ module Dapp
21
21
 
22
22
  def changes_size_since_g_a_pre_setup_patch
23
23
  dimg.git_artifacts.map do |git_artifact|
24
- git_artifact.patch_size(prev_stage.prev_stage.prev_stage.layer_commit(git_artifact), git_artifact.latest_commit)
24
+ git_artifact.patch_size(prev_stage.prev_stage.layer_commit(git_artifact), git_artifact.latest_commit)
25
25
  end.reduce(0, :+)
26
26
  end
27
27
  end # GAPostSetupPatchDependencies
@@ -14,10 +14,6 @@ module Dapp
14
14
  def prev_g_a_stage
15
15
  super.prev_stage.prev_stage # GAPostInstallPatch
16
16
  end
17
-
18
- def next_g_a_stage
19
- super.next_stage # GAPostSetupPatch || GAArtifactPatch
20
- end
21
17
  end # GAPrePatch
22
18
  end
23
19
  end # Stage
@@ -31,7 +31,7 @@ module Dapp
31
31
  private
32
32
 
33
33
  def setup_dependencies_files_checksum
34
- @setup_files_checksum ||= dependencies_files_checksum(dimg.config._setup_dependencies)
34
+ dependencies_files_checksum(dimg.config._setup_dependencies)
35
35
  end
36
36
  end # Setup
37
37
  end
@@ -73,13 +73,6 @@ module Dapp
73
73
  def build_artifact_checksum
74
74
  raise
75
75
  end
76
-
77
- def chef_cookbooks(_image)
78
- end
79
-
80
- def chef_cookbooks_checksum
81
- []
82
- end
83
76
  end # Base
84
77
  end # Builder
85
78
  end # Dapp
@@ -1,25 +1,17 @@
1
1
  module Dapp
2
2
  module Builder
3
- # Chef
4
3
  class Chef < Base
5
- LOCAL_COOKBOOK_CHECKSUM_PATTERNS = %w(
6
- attributes/**/*
7
- recipes/**/*
8
- files/**/*
9
- templates/**/*
10
- ).freeze
11
-
12
4
  DEFAULT_CHEFDK_IMAGE = 'dappdeps/chefdk:0.17.3-1'.freeze # TODO: config, DSL, DEFAULT_CHEFDK_IMAGE
13
5
 
14
6
  %i(before_install install before_setup setup build_artifact).each do |stage|
7
+ define_method("#{stage}?") {!stage_empty?(stage)}
8
+
15
9
  define_method("#{stage}_checksum") do
16
10
  dimg.hashsum [stage_cookbooks_checksum(stage),
17
11
  stage_attributes_raw(stage),
18
12
  *stage_cookbooks_runlist(stage)]
19
13
  end
20
14
 
21
- define_method("#{stage}?") { !stage_empty?(stage) }
22
-
23
15
  define_method(stage.to_s) do |image|
24
16
  unless stage_empty?(stage)
25
17
  image.add_volumes_from(chefdk_container)
@@ -33,188 +25,25 @@ module Dapp
33
25
  end
34
26
  end
35
27
 
36
- def chef_cookbooks_checksum
37
- stage_cookbooks_checksum(:chef_cookbooks)
38
- end
39
-
40
- def chef_cookbooks(image)
41
- image.add_volume "#{cookbooks_vendor_path(chef_cookbooks_stage: true)}:#{dimg.container_dapp_path('chef_cookbooks')}"
42
- image.add_command(
43
- "#{dimg.project.mkdir_bin} -p /usr/share/dapp/chef_repo",
44
- ["#{dimg.project.cp_bin} -a #{dimg.container_dapp_path('chef_cookbooks')} ",
45
- '/usr/share/dapp/chef_repo/cookbooks'].join
46
- )
47
- end
48
-
49
28
  def before_dimg_should_be_built_check
50
29
  super
51
30
 
52
- %i(before_install install before_setup setup chef_cookbooks).each do |stage|
31
+ %i(before_install install before_setup setup).each do |stage|
53
32
  unless stage_empty?(stage) || stage_cookbooks_checksum_path(stage).exist?
54
33
  raise ::Dapp::Error::Dimg, code: :chef_stage_checksum_not_calculated,
55
- data: { stage: stage }
34
+ data: {stage: stage}
56
35
  end
57
36
  end
58
37
  end
59
38
 
60
39
  def before_build_check
61
40
  %i(before_install install before_setup setup build_artifact).tap do |stages|
62
- (enabled_recipes - stages.map { |stage| stage_enabled_recipes(stage) }.flatten.uniq).each do |recipe|
63
- dimg.project.log_warning(desc: { code: :recipe_does_not_used, data: { recipe: recipe } })
41
+ (builder_cookbook.enabled_recipes - stages.map {|stage| builder_cookbook.stage_enabled_recipes(stage)}.flatten.uniq).each do |recipe|
42
+ dimg.project.log_warning(desc: {code: :recipe_does_not_used, data: {recipe: recipe}})
64
43
  end
65
44
  end
66
45
  end
67
46
 
68
- private
69
-
70
- def stage_enabled_modules(stage)
71
- @stage_enabled_modules ||= {}
72
- @stage_enabled_modules[stage] ||= enabled_modules.select { |cookbook| stage_entry_exist?(stage, cookbook, stage) }
73
- end
74
-
75
- def stage_enabled_recipes(stage)
76
- @stage_enabled_recipes ||= {}
77
- @stage_enabled_recipes[stage] ||= enabled_recipes.select { |recipe| stage_entry_exist?(stage, project_name, recipe) }
78
- end
79
-
80
- def enabled_modules
81
- dimg.config._chef._dimod
82
- end
83
-
84
- def enabled_recipes
85
- dimg.config._chef._recipe
86
- end
87
-
88
- def stage_attributes(stage)
89
- dimg.config._chef.send("__#{stage}_attributes")
90
- end
91
-
92
- def stage_attributes_raw(stage)
93
- JSON.dump stage_attributes(stage)
94
- end
95
-
96
- def project_name
97
- cookbook_metadata.name
98
- end
99
-
100
- def local_cookbook_path(*path)
101
- dimg.local_cookbook_path.tap do |local_cookbook_path|
102
- unless local_cookbook_path.exist?
103
- raise Error, code: :local_cookbook_path_not_found,
104
- data: { path: local_cookbook_path }
105
- end
106
- end.join(*path)
107
- end
108
-
109
- def berksfile_path
110
- local_cookbook_path('Berksfile')
111
- end
112
-
113
- def berksfile_lock_path
114
- local_cookbook_path('Berksfile.lock')
115
- end
116
-
117
- def berksfile
118
- @berksfile ||= begin
119
- unless berksfile_path.exist?
120
- raise Error, code: :cookbook_berksfile_not_found,
121
- data: { path: berksfile_path.to_s }
122
- end
123
-
124
- Berksfile.new(local_cookbook_path, berksfile_path).tap do |berksfile|
125
- unless berksfile.local_cookbook? project_name
126
- raise Error, code: :cookbook_not_specified_in_berksfile,
127
- data: { name: project_name, path: berksfile_path.to_s }
128
- end
129
- end
130
- end
131
- end
132
-
133
- def cookbook_metadata_path
134
- local_cookbook_path('metadata.rb')
135
- end
136
-
137
- def check_cookbook_metadata_path_exist!
138
- unless cookbook_metadata_path.exist?
139
- raise Error, code: :cookbook_metadata_not_found,
140
- data: { path: cookbook_metadata_path }
141
- end
142
- end
143
-
144
- def cookbook_metadata
145
- @cookbook_metadata ||= begin
146
- check_cookbook_metadata_path_exist!
147
-
148
- CookbookMetadata.new(cookbook_metadata_path).tap do |metadata|
149
- metadata.depends.each do |dependency|
150
- if dependency.start_with? 'mdapp-'
151
- raise Error, code: :mdapp_dependency_in_metadata_forbidden,
152
- data: { dependency: dependency }
153
- end
154
- end
155
- end
156
- end
157
- end
158
-
159
- def berksfile_lock_checksum
160
- dimg.hashsum(berksfile_lock_path.read) if berksfile_lock_path.exist?
161
- end
162
-
163
- def stage_cookbooks_checksum_path(stage)
164
- dimg.build_path.join("#{cookbooks_checksum}.#{stage}.checksum")
165
- end
166
-
167
- def stage_cookbooks_checksum(stage)
168
- if stage_cookbooks_checksum_path(stage).exist?
169
- stage_cookbooks_checksum_path(stage).read.strip
170
- else
171
- checksum = if stage == :chef_cookbooks
172
- paths = Dir[cookbooks_vendor_path('**/*', chef_cookbooks_stage: true)].map(&Pathname.method(:new))
173
-
174
- dimg.hashsum [
175
- dimg.paths_content_hashsum(paths),
176
- *paths.map { |p| p.relative_path_from(cookbooks_vendor_path(chef_cookbooks_stage: true)).to_s }.sort
177
- ]
178
- else
179
- paths = Dir[stage_cookbooks_path(stage, '**/*')].map(&Pathname.method(:new))
180
-
181
- dimg.hashsum [
182
- dimg.paths_content_hashsum(paths),
183
- *paths.map { |p| p.relative_path_from(stage_cookbooks_path(stage)).to_s }.sort,
184
- stage == :before_install ? chefdk_image : nil
185
- ].compact
186
- end
187
-
188
- stage_cookbooks_checksum_path(stage).tap do |path|
189
- path.parent.mkpath
190
- path.write "#{checksum}\n"
191
- end
192
-
193
- checksum
194
- end
195
- end
196
-
197
- def cookbooks_checksum
198
- @cookbooks_checksum ||= begin
199
- paths = berksfile
200
- .local_cookbooks
201
- .values
202
- .map { |cookbook| cookbook[:path] }
203
- .product(LOCAL_COOKBOOK_CHECKSUM_PATTERNS)
204
- .map { |cb, dir| Dir[cb.join(dir)] }
205
- .flatten
206
- .map(&Pathname.method(:new))
207
-
208
- dimg.hashsum [
209
- dimg.paths_content_hashsum(paths),
210
- *paths.map { |p| p.relative_path_from(berksfile.home_path).to_s }.sort,
211
- (berksfile_lock_checksum unless dimg.project.dev_mode?),
212
- *enabled_recipes,
213
- *enabled_modules
214
- ].compact
215
- end
216
- end
217
-
218
47
  def chefdk_image
219
48
  DEFAULT_CHEFDK_IMAGE # TODO: config, DSL, DEFAULT_CHEFDK_IMAGE
220
49
  end
@@ -239,218 +68,62 @@ module Dapp
239
68
  end
240
69
  end
241
70
 
242
- def _update_berksfile_lock_cmd
243
- vendor_tmp = SecureRandom.uuid
244
-
245
- ["berks vendor -b #{berksfile_path} /tmp/#{vendor_tmp}",
246
- "rm -rf /tmp/#{vendor_tmp}"].join(' && ')
247
- end
71
+ def builder_cookbook
72
+ @builder_cookbook ||= begin
73
+ unless dimg.project.builder_cookbook_path.exist?
74
+ raise Error, code: :builder_cookbook_not_found,
75
+ data: {path: dimg.project.builder_cookbook_path.to_s}
76
+ end
248
77
 
249
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
250
- def install_cookbooks(dest_path, chef_cookbooks_stage: false)
251
- check_cookbook_metadata_path_exist!
252
-
253
- volumes_from = [dimg.project.base_container, chefdk_container]
254
- process_code = [
255
- 'process',
256
- chef_cookbooks_stage ? 'chef_cookbooks_stage_berks_vendor' : 'berks_vendor'
257
- ].compact.join('.')
258
-
259
- dimg.project.log_secondary_process(dimg.project.t(code: process_code)) do
260
- before_vendor_commands = [].tap do |commands|
261
- unless dimg.project.dev_mode? || chef_cookbooks_stage
262
- commands.push(
263
- ['if [ ! -f Berksfile.lock ] ; then ',
264
- "echo \"Berksfile.lock not found, to create run '#{_update_berksfile_lock_cmd}'\" 1>&2 ; ",
265
- 'exit 1 ; ',
266
- 'fi'].join
267
- )
268
- end
78
+ unless dimg.project.builder_cookbook_path.join('Berksfile').exist?
79
+ raise Error, code: :builder_cookbook_berksfile_not_found,
80
+ data: {path: dimg.project.builder_cookbook_path.join('Berksfile').to_s}
269
81
  end
270
82
 
271
- after_vendor_commands = [].tap do |commands|
272
- if dimg.project.dev_mode?
273
- commands.push(
274
- ["#{dimg.project.install_bin} -o #{Process.uid} -g #{Process.gid} ",
275
- "--mode $(#{dimg.project.stat_bin} -c %a Berksfile.lock) ",
276
- "Berksfile.lock #{berksfile_lock_path}"].join
277
- )
278
- elsif !chef_cookbooks_stage
279
- commands.push(
280
- "export LOCKDIFF=$(#{dimg.project.diff_bin} -u1 #{berksfile_lock_path} Berksfile.lock)",
281
- ['if [ "$LOCKDIFF" != "" ] ; then ',
282
- "echo -e \"",
283
- "Bad Berksfile.lock, run '#{_update_berksfile_lock_cmd}' ",
284
- "or manually apply change:\\n$LOCKDIFF\" 1>&2 ; ",
285
- 'exit 1 ; ',
286
- 'fi'].join
287
- )
288
- end
83
+ unless dimg.project.builder_cookbook_path.join('metadata.rb').exist?
84
+ raise Error, code: :builder_cookbook_metadata_not_found,
85
+ data: {path: dimg.project.builder_cookbook_path.join('metadata.rb').to_s}
289
86
  end
290
87
 
291
- vendor_commands = [
292
- "#{dimg.project.mkdir_bin} -p ~/.ssh",
293
- "echo \"Host *\" >> ~/.ssh/config",
294
- "echo \" StrictHostKeyChecking no\" >> ~/.ssh/config",
295
- *berksfile
296
- .local_cookbooks
297
- .values
298
- .map {|cookbook|
299
- ["#{dimg.project.rsync_bin} --archive",
300
- #*cookbook[:chefignore].map {|path| "--exclude #{path}"}, # FIXME
301
- "--relative #{cookbook[:path]} /tmp/local_cookbooks",
302
- ].join(' ')
303
- },
304
- "cd /tmp/local_cookbooks/#{berksfile_path.parent}",
305
- *before_vendor_commands,
306
- '/.dapp/deps/chefdk/bin/berks vendor /tmp/cookbooks',
307
- *after_vendor_commands,
308
- ["#{dimg.project.find_bin} /tmp/cookbooks -type d -exec #{dimg.project.bash_bin} -ec '",
309
- "#{dimg.project.install_bin} -o #{Process.uid} -g #{Process.gid} --mode $(#{dimg.project.stat_bin} -c %a {}) -d ",
310
- "#{dest_path}/$(echo {} | #{dimg.project.sed_bin} -e \"s/^\\/tmp\\/cookbooks//\")' \\;"].join,
311
- ["#{dimg.project.find_bin} /tmp/cookbooks -type f -exec #{dimg.project.bash_bin} -ec '",
312
- "#{dimg.project.install_bin} -o #{Process.uid} -g #{Process.gid} --mode $(#{dimg.project.stat_bin} -c %a {}) {} ",
313
- "#{dest_path}/$(echo {} | #{dimg.project.sed_bin} -e \"s/\\/tmp\\/cookbooks//\")' \\;"].join,
314
- "#{dimg.project.install_bin} -o #{Process.uid} -g #{Process.gid} --mode 0644 <(#{dimg.project.date_bin} +%s.%N) #{dest_path.join('.created_at')}"
315
- ]
316
-
317
- dimg.project.shellout!(
318
- ['docker run --rm',
319
- volumes_from.map { |container| "--volumes-from #{container}" }.join(' '),
320
- *berksfile
321
- .local_cookbooks
322
- .values
323
- .map { |desc| "--volume #{desc[:path]}:#{desc[:path]}" },
324
- ("--volume #{dimg.project.ssh_auth_sock}:/tmp/dapp-ssh-agent" if dimg.project.ssh_auth_sock),
325
- "--volume #{dest_path.tap(&:mkpath)}:#{dest_path}",
326
- ('--env SSH_AUTH_SOCK=/tmp/dapp-ssh-agent' if dimg.project.ssh_auth_sock),
327
- ('--env DAPP_CHEF_COOKBOOKS_VENDORING=1' if chef_cookbooks_stage),
328
- "dappdeps/berksdeps:0.1.0 #{dimg.project.bash_bin} -ec '#{dimg.project.shellout_pack(vendor_commands.join(' && '))}'"].compact.join(' '),
329
- log_verbose: dimg.project.log_verbose?
88
+ berksfile = Berksfile.from_file(dimg.project.builder_cookbook_path, dimg.project.builder_cookbook_path.join('Berksfile'))
89
+ metadata = CookbookMetadata.from_file(dimg.project.builder_cookbook_path.join('metadata.rb'))
90
+
91
+ Cookbook.new(self,
92
+ path: dimg.project.builder_cookbook_path,
93
+ berksfile: berksfile,
94
+ metadata: metadata,
95
+ enabled_recipes: dimg.config._chef._recipe,
96
+ enabled_modules: dimg.config._chef._dimod,
330
97
  )
331
98
  end
332
99
  end
333
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
334
100
 
335
- def _cookbooks_vendor_path(chef_cookbooks_stage: false)
336
- dimg.build_path.join(
337
- ['cookbooks', chef_cookbooks_stage ? 'chef_cookbooks_stage' : nil].compact.join('.'),
338
- cookbooks_checksum
339
- )
101
+ def stage_attributes(stage)
102
+ dimg.config._chef.send("__#{stage}_attributes")
340
103
  end
341
104
 
342
- def cookbooks_vendor_path(*path, chef_cookbooks_stage: false)
343
- _cookbooks_vendor_path(chef_cookbooks_stage: chef_cookbooks_stage).tap do |_cookbooks_path|
344
- lock_name = [
345
- dimg.project.name,
346
- 'cookbooks',
347
- chef_cookbooks_stage ? 'chef_cookbooks_stage' : nil,
348
- cookbooks_checksum
349
- ].compact.join('.')
350
-
351
- dimg.project.lock(lock_name, default_timeout: 120) do
352
- @install_cookbooks ||= {}
353
- @install_cookbooks[chef_cookbooks_stage] ||= begin
354
- install_cookbooks(_cookbooks_path, chef_cookbooks_stage: chef_cookbooks_stage) unless _cookbooks_path.join('.created_at').exist? && !dimg.project.dev_mode?
355
- true
356
- end
357
- end
358
- end.join(*path)
105
+ def stage_attributes_raw(stage)
106
+ JSON.dump stage_attributes(stage)
359
107
  end
360
108
 
361
- # rubocop:disable Metrics/MethodLength, Metrics/AbcSize
362
- def install_stage_cookbooks(stage)
363
- select_existing_paths = proc do |cookbook_path, paths|
364
- paths.select { |from, _| cookbook_path.join(from).exist? }
365
- end
109
+ def stage_cookbooks_checksum_path(stage)
110
+ dimg.build_path.join("#{builder_cookbook.checksum}.#{stage}.checksum")
111
+ end
366
112
 
367
- common_paths = [['metadata.json', 'metadata.json']]
368
-
369
- install_paths = Dir[cookbooks_vendor_path('*')]
370
- .map(&Pathname.method(:new))
371
- .map do |cookbook_path|
372
- cookbook_name = File.basename cookbook_path
373
- is_project = (cookbook_name == project_name)
374
- is_mdapp = cookbook_name.start_with? 'mdapp-'
375
- mdapp_enabled = is_mdapp && enabled_modules.include?(cookbook_name)
376
-
377
- paths = if is_project
378
- common_dapp_paths = select_existing_paths.call(cookbook_path, [
379
- *common_paths,
380
- ["files/#{stage}/common", 'files/default'],
381
- ["templates/#{stage}/common", 'templates/default'],
382
- *enabled_recipes.flat_map do |recipe|
383
- [["files/#{stage}/#{recipe}", 'files/default'],
384
- ["templates/#{stage}/#{recipe}", 'templates/default']]
385
- end
386
- ])
387
-
388
- recipe_paths = enabled_recipes.map { |recipe| ["recipes/#{stage}/#{recipe}.rb", "recipes/#{recipe}.rb"] }
389
- .select { |from, _| cookbook_path.join(from).exist? }
390
- if recipe_paths.any?
391
- [*recipe_paths, *common_dapp_paths]
392
- else
393
- [nil, *common_dapp_paths]
394
- end
395
- elsif is_mdapp && mdapp_enabled
396
- common_mdapp_paths = select_existing_paths.call(cookbook_path, [
397
- *common_paths,
398
- ["files/#{stage}", 'files/default'],
399
- ['files/common', 'files/default'],
400
- ["templates/#{stage}", 'templates/default'],
401
- ['templates/common', 'templates/default'],
402
- ["attributes/#{stage}.rb", "attributes/#{stage}.rb"],
403
- ['attributes/common.rb', 'attributes/common.rb']
404
- ])
405
-
406
- recipe_path = "recipes/#{stage}.rb"
407
- if cookbook_path.join(recipe_path).exist?
408
- [[recipe_path, recipe_path], *common_mdapp_paths]
409
- else
410
- [nil, *common_mdapp_paths]
411
- end
412
- elsif !is_mdapp
413
- [['.', '.']]
414
- end
415
-
416
- [cookbook_path, paths] if paths && paths.any?
417
- end.compact
418
-
419
- _stage_cookbooks_path(stage).mkpath
420
- install_paths.each do |cookbook_path, paths|
421
- cookbook = cookbook_path.basename.to_s
422
-
423
- paths.each do |from, to|
424
- if from.nil?
425
- to_path = _stage_cookbooks_path(stage).join(cookbook, 'recipes/void.rb')
426
- to_path.parent.mkpath
427
- FileUtils.touch to_path
428
- else
429
- from_path = cookbook_path.join(from)
430
- to_path = _stage_cookbooks_path(stage).join(cookbook, to)
431
- if from_path.directory? && to_path.exist?
432
- Dir[from_path.join('**/*')]
433
- .map(&Pathname.method(:new))
434
- .each do |from_subpath|
435
- to_subpath = to_path.join(from_subpath.relative_path_from(from_path))
436
- raise Error, code: :stage_path_overlap,
437
- data: { stage: stage,
438
- cookbook: cookbook,
439
- from: from_subpath.relative_path_from(cookbook_path),
440
- to: to_subpath.relative_path_from(_stage_cookbooks_path(stage).join(cookbook)) } if to_subpath.exist?
441
-
442
- to_subpath.parent.mkpath
443
- FileUtils.cp_r from_subpath, to_subpath
444
- end
445
- else
446
- to_path.parent.mkpath
447
- FileUtils.cp_r from_path, to_path
448
- end
449
- end
113
+ def stage_cookbooks_checksum(stage)
114
+ if stage_cookbooks_checksum_path(stage).exist?
115
+ stage_cookbooks_checksum_path(stage).read.strip
116
+ else
117
+ checksum = builder_cookbook.stage_checksum(stage)
118
+
119
+ stage_cookbooks_checksum_path(stage).tap do |path|
120
+ path.parent.mkpath
121
+ path.write "#{checksum}\n"
450
122
  end
123
+
124
+ checksum
451
125
  end
452
126
  end
453
- # rubocop:enable Metrics/MethodLength, Metrics/AbcSize
454
127
 
455
128
  # rubocop:disable Metrics/AbcSize
456
129
  def stage_cookbooks_runlist(stage)
@@ -463,24 +136,25 @@ module Dapp
463
136
  "#{cookbook}::#{entrypoint}"
464
137
  end
465
138
 
466
- enabled_modules.map do |cookbook|
467
- if stage_enabled_modules(stage).include? cookbook
139
+ builder_cookbook.enabled_modules.map do |cookbook|
140
+ if builder_cookbook.stage_enabled_modules(stage).include? cookbook
468
141
  [cookbook, stage]
469
142
  else
470
143
  [cookbook, nil]
471
144
  end
472
- end.tap { |entries| res.concat entries }
145
+ end.tap {|entries| res.concat entries}
473
146
 
474
- stage_enabled_recipes(stage).map { |recipe| [project_name, recipe] }
475
- .tap do |entries|
147
+ builder_cookbook.stage_enabled_recipes(stage)
148
+ .map {|recipe| [builder_cookbook.name, recipe]}
149
+ .tap do |entries|
476
150
  if entries.any?
477
151
  res.concat entries
478
152
  else
479
- res << [project_name, nil]
153
+ res << [builder_cookbook.name, nil]
480
154
  end
481
155
  end
482
156
 
483
- if res.all? { |_, entrypoint| entrypoint.nil? }
157
+ if res.all? {|_, entrypoint| entrypoint.nil?}
484
158
  []
485
159
  else
486
160
  res.map(&format_entry)
@@ -493,55 +167,40 @@ module Dapp
493
167
  stage_cookbooks_runlist(stage).empty?
494
168
  end
495
169
 
496
- def stage_entry_exist?(stage, cookbook, entrypoint)
497
- stage_cookbooks_path(stage, cookbook, 'recipes', "#{entrypoint}.rb").exist?
498
- end
499
-
500
- def _stage_cookbooks_path(stage)
501
- stage_build_path(stage, 'cookbooks')
502
- end
503
-
504
- def stage_cookbooks_path(stage, *path)
505
- _stage_cookbooks_path(stage).tap do |_cookbooks_path|
506
- @install_stage_cookbooks ||= {}
507
- @install_stage_cookbooks[stage] ||= true.tap { install_stage_cookbooks(stage) }
508
- end.join(*path)
509
- end
510
-
511
170
  def install_chef_solo_stage_config(stage)
512
171
  @install_chef_solo_stage_config ||= {}
513
172
  @install_chef_solo_stage_config[stage] ||= true.tap do
514
- stage_build_path(stage, 'config.rb').write [
173
+ stage_build_path(stage).join('config.rb').write [
515
174
  "file_cache_path \"/.dapp/chef/cache\"\n",
516
- "cookbook_path \"#{container_stage_build_path(stage, 'cookbooks')}\"\n"
175
+ "cookbook_path \"#{container_stage_build_path(stage).join('cookbooks')}\"\n"
517
176
  ].join
518
177
  end
519
178
  end
520
179
 
521
- def container_stage_config_path(stage, *path)
180
+ def container_stage_config_path(stage)
522
181
  install_chef_solo_stage_config(stage)
523
- container_stage_build_path(stage, 'config.rb', *path)
182
+ container_stage_build_path(stage).join('config.rb')
524
183
  end
525
184
 
526
185
  def install_json_attributes(stage)
527
186
  @install_json_attributes ||= {}
528
187
  @install_json_attributes[stage] ||= true.tap do
529
- stage_build_path(stage, 'attributes.json').write "#{stage_attributes_raw(stage)}\n"
188
+ stage_build_path(stage).join('attributes.json').write "#{stage_attributes_raw(stage)}\n"
530
189
  end
531
190
  end
532
191
 
533
- def container_stage_json_attributes_path(stage, *path)
192
+ def container_stage_json_attributes_path(stage)
534
193
  install_json_attributes(stage)
535
- container_stage_build_path(stage, 'attributes.json', *path)
194
+ container_stage_build_path(stage).join('attributes.json')
536
195
  end
537
196
 
538
- def stage_build_path(stage, *path)
539
- dimg.tmp_path(dimg.config._name, stage).join(*path)
197
+ def stage_build_path(stage)
198
+ dimg.tmp_path(dimg.config._name).join(stage.to_s)
540
199
  end
541
200
 
542
- def container_stage_build_path(_stage, *path)
543
- path.compact.map(&:to_s).inject(Pathname.new('/.dapp/chef/build'), &:+)
201
+ def container_stage_build_path(_stage)
202
+ Pathname.new('/.dapp/chef/build')
544
203
  end
545
- end
546
- end
547
- end
204
+ end # Chef
205
+ end # Builder
206
+ end # Dapp