dapp 0.4.8 → 0.5.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 (48) hide show
  1. checksums.yaml +4 -4
  2. data/config/en/common.yml +1 -0
  3. data/config/en/net_status.yml +2 -2
  4. data/lib/dapp.rb +9 -2
  5. data/lib/dapp/application.rb +2 -5
  6. data/lib/dapp/application/path.rb +3 -3
  7. data/lib/dapp/build/stage/artifact.rb +35 -0
  8. data/lib/dapp/build/stage/base.rb +42 -20
  9. data/lib/dapp/build/stage/chef_cookbooks.rb +12 -2
  10. data/lib/dapp/build/stage/docker_instructions.rb +31 -0
  11. data/lib/dapp/build/stage/from.rb +5 -4
  12. data/lib/dapp/build/stage/infra_install.rb +6 -2
  13. data/lib/dapp/build/stage/infra_setup.rb +8 -0
  14. data/lib/dapp/build/stage/install.rb +8 -0
  15. data/lib/dapp/build/stage/mod/artifact.rb +16 -21
  16. data/lib/dapp/build/stage/mod/logging.rb +8 -2
  17. data/lib/dapp/build/stage/setup.rb +8 -0
  18. data/lib/dapp/build/stage/source_1.rb +4 -14
  19. data/lib/dapp/build/stage/source_1_archive.rb +2 -2
  20. data/lib/dapp/build/stage/source_1_archive_dependencies.rb +13 -0
  21. data/lib/dapp/build/stage/source_1_dependencies.rb +27 -0
  22. data/lib/dapp/build/stage/source_2.rb +3 -6
  23. data/lib/dapp/build/stage/source_2_dependencies.rb +17 -0
  24. data/lib/dapp/build/stage/source_3.rb +3 -13
  25. data/lib/dapp/build/stage/source_3_dependencies.rb +23 -0
  26. data/lib/dapp/build/stage/source_4.rb +2 -16
  27. data/lib/dapp/build/stage/source_4_dependencies.rb +27 -0
  28. data/lib/dapp/build/stage/source_5.rb +17 -16
  29. data/lib/dapp/build/stage/source_base.rb +17 -39
  30. data/lib/dapp/build/stage/source_dependencies_base.rb +28 -0
  31. data/lib/dapp/builder/base.rb +16 -0
  32. data/lib/dapp/builder/chef.rb +49 -29
  33. data/lib/dapp/builder/shell.rb +13 -4
  34. data/lib/dapp/cli.rb +1 -2
  35. data/lib/dapp/cli/build.rb +5 -5
  36. data/lib/dapp/cli/push.rb +0 -4
  37. data/lib/dapp/cli/run.rb +0 -3
  38. data/lib/dapp/config/artifact.rb +0 -23
  39. data/lib/dapp/controller.rb +9 -9
  40. data/lib/dapp/error/dappfile.rb +6 -0
  41. data/lib/dapp/git_artifact.rb +2 -2
  42. data/lib/dapp/image/argument.rb +2 -4
  43. data/lib/dapp/image/docker.rb +5 -0
  44. data/lib/dapp/image/stage.rb +4 -0
  45. data/lib/dapp/version.rb +2 -2
  46. metadata +10 -3
  47. data/lib/dapp/cli/metadata.rb +0 -18
  48. data/lib/dapp/cli/metadata/flush.rb +0 -22
@@ -8,6 +8,10 @@ module Dapp
8
8
  @application = application
9
9
  end
10
10
 
11
+ def infra_install?
12
+ false
13
+ end
14
+
11
15
  def infra_install(_image)
12
16
  raise
13
17
  end
@@ -16,6 +20,10 @@ module Dapp
16
20
  raise
17
21
  end
18
22
 
23
+ def infra_setup?
24
+ false
25
+ end
26
+
19
27
  def infra_setup(_image)
20
28
  raise
21
29
  end
@@ -24,6 +32,10 @@ module Dapp
24
32
  raise
25
33
  end
26
34
 
35
+ def install?
36
+ false
37
+ end
38
+
27
39
  def install(_image)
28
40
  raise
29
41
  end
@@ -32,6 +44,10 @@ module Dapp
32
44
  raise
33
45
  end
34
46
 
47
+ def setup?
48
+ false
49
+ end
50
+
35
51
  def setup(_image)
36
52
  raise
37
53
  end
@@ -12,18 +12,21 @@ module Dapp
12
12
  DEFAULT_CHEFDK_IMAGE = 'dappdeps/chefdk:0.17.3-1'.freeze # TODO: config, DSL, DEFAULT_CHEFDK_IMAGE
13
13
 
14
14
  [:infra_install, :infra_setup, :install, :setup].each do |stage|
15
- define_method(:"#{stage}_checksum") { stage_cookbooks_checksum(stage) }
15
+ define_method("#{stage}_checksum") { stage_cookbooks_checksum(stage) }
16
16
 
17
- define_method(:"#{stage}") do |image|
17
+ define_method("#{stage}?") { !stage_empty?(stage) }
18
+
19
+ define_method("#{stage}") do |image|
18
20
  unless stage_empty?(stage)
19
21
  image.add_volumes_from(chefdk_container)
20
- image.add_commands 'export PATH=/.dapp/deps/chefdk/bin:$PATH',
21
- "export DAPP_BUILD_STAGE=#{stage}"
22
-
23
- image.add_volume "#{stage_tmp_path(stage)}:#{container_stage_tmp_path(stage)}"
24
- image.add_commands ['chef-solo',
25
- "-c #{container_stage_config_path(stage)}",
26
- "-o #{stage_cookbooks_runlist(stage).join(',')}"].join(' ')
22
+ image.add_command 'export PATH=/.dapp/deps/chefdk/bin:$PATH',
23
+ "export DAPP_BUILD_STAGE=#{stage}"
24
+
25
+ image.add_volume "#{stage_build_path(stage)}:#{container_stage_build_path(stage)}:ro"
26
+ image.add_command ['chef-solo',
27
+ '--legacy-mode',
28
+ "-c #{container_stage_config_path(stage)}",
29
+ "-o #{stage_cookbooks_runlist(stage).join(',')}"].join(' ')
27
30
  end
28
31
  end
29
32
  end
@@ -34,7 +37,7 @@ module Dapp
34
37
 
35
38
  def chef_cookbooks(image)
36
39
  image.add_volume "#{cookbooks_vendor_path}:#{application.container_dapp_path('chef_vendored_cookbooks')}"
37
- image.add_commands(
40
+ image.add_command(
38
41
  'mkdir -p /usr/share/dapp/chef_repo',
39
42
  ["cp -a #{application.container_dapp_path('chef_vendored_cookbooks')} ",
40
43
  '/usr/share/dapp/chef_repo/cookbooks'].join
@@ -96,7 +99,7 @@ module Dapp
96
99
  end
97
100
 
98
101
  def stage_cookbooks_checksum_path(stage)
99
- application.metadata_path("#{cookbooks_checksum}.#{stage}.checksum")
102
+ application.build_path("#{cookbooks_checksum}.#{stage}.checksum")
100
103
  end
101
104
 
102
105
  def stage_cookbooks_checksum(stage)
@@ -294,28 +297,45 @@ module Dapp
294
297
  install_stage_cookbooks(stage)
295
298
 
296
299
  @stage_cookbooks_runlist ||= {}
297
- @stage_cookbooks_runlist[stage] ||= [].tap do |res|
298
- to_entry = proc { |cookbook, entrypoint| "#{cookbook}::#{entrypoint}" }
299
- to_recipe_entry = proc do |cookbook, entrypoint|
300
- entrypoint_file = stage_cookbooks_path(stage, cookbook, 'recipes', "#{entrypoint}.rb")
301
- next unless entrypoint_file.exist?
302
- to_entry[cookbook, entrypoint]
300
+ @stage_cookbooks_runlist[stage] ||= begin
301
+ res = []
302
+
303
+ does_entry_exist = ->(cookbook, entrypoint) do
304
+ stage_cookbooks_path(stage, cookbook, 'recipes', "#{entrypoint}.rb").exist?
305
+ end
306
+
307
+ format_entry = ->(cookbook, entrypoint) do
308
+ entrypoint = 'void' if entrypoint.nil?
309
+ "#{cookbook}::#{entrypoint}"
303
310
  end
304
311
 
305
312
  enabled_modules
306
- .map { |mod| to_recipe_entry["mdapp-#{mod}", stage] || to_entry["mdapp-#{mod}", 'void'] }
313
+ .map do |mod|
314
+ cookbook = "mdapp-#{mod}"
315
+ if does_entry_exist[cookbook, stage]
316
+ [cookbook, stage]
317
+ else
318
+ [cookbook, nil]
319
+ end
320
+ end
307
321
  .tap { |entries| res.concat entries }
308
322
 
309
323
  enabled_recipes
310
- .map { |recipe| to_recipe_entry[project_name, recipe] }
311
- .compact
324
+ .map { |recipe| [project_name, recipe] }
325
+ .select { |entry| does_entry_exist[*entry] }
312
326
  .tap do |entries|
313
327
  if entries.any?
314
328
  res.concat entries
315
329
  else
316
- res << to_entry[project_name, 'void']
330
+ res << [project_name, nil]
317
331
  end
318
332
  end
333
+
334
+ if res.all? { |_, entrypoint| entrypoint.nil? }
335
+ []
336
+ else
337
+ res.map &format_entry
338
+ end
319
339
  end
320
340
  end
321
341
  # rubocop:enable Metrics/AbcSize
@@ -325,30 +345,30 @@ module Dapp
325
345
  end
326
346
 
327
347
  def stage_cookbooks_path(stage, *path)
328
- stage_tmp_path(stage, 'cookbooks', *path)
348
+ stage_build_path(stage, 'cookbooks', *path)
329
349
  end
330
350
 
331
351
  def install_chef_solo_stage_config(stage)
332
352
  @install_chef_solo_stage_config ||= {}
333
353
  @install_chef_solo_stage_config[stage] ||= true.tap do
334
- stage_tmp_path(stage, 'config.rb').write [
335
- "file_cache_path \"/var/cache/dapp/chef\"\n",
336
- "cookbook_path \"#{container_stage_tmp_path(stage, 'cookbooks')}\"\n"
354
+ stage_build_path(stage, 'config.rb').write [
355
+ "file_cache_path \"/.dapp/chef/cache\"\n",
356
+ "cookbook_path \"#{container_stage_build_path(stage, 'cookbooks')}\"\n"
337
357
  ].join
338
358
  end
339
359
  end
340
360
 
341
361
  def container_stage_config_path(stage, *path)
342
362
  install_chef_solo_stage_config(stage)
343
- container_stage_tmp_path(stage, 'config.rb', *path)
363
+ container_stage_build_path(stage, 'config.rb', *path)
344
364
  end
345
365
 
346
- def stage_tmp_path(stage, *path)
366
+ def stage_build_path(stage, *path)
347
367
  application.tmp_path(application.config._name, stage).join(*path)
348
368
  end
349
369
 
350
- def container_stage_tmp_path(_stage, *path)
351
- path.compact.map(&:to_s).inject(Pathname.new('/chef_build'), &:+)
370
+ def container_stage_build_path(_stage, *path)
371
+ path.compact.map(&:to_s).inject(Pathname.new('/.dapp/chef/build'), &:+)
352
372
  end
353
373
 
354
374
  def _paths_checksum(paths)
@@ -3,15 +3,24 @@ module Dapp
3
3
  # Shell
4
4
  class Shell < Base
5
5
  [:infra_install, :infra_setup, :install, :setup].each do |stage|
6
- define_method(:"#{stage}_checksum") do
6
+ define_method("#{stage}_checksum") do
7
7
  [application.config._shell.public_send("_#{stage}"),
8
8
  application.config._shell.public_send("_#{stage}_cache_version")].flatten
9
9
  end
10
- define_method(:"#{stage}") do |image|
11
- commands = application.config._shell.public_send("_#{stage}")
12
- image.add_commands("export DAPP_BUILD_STAGE=#{stage}", *commands) if commands
10
+ define_method("#{stage}?") { !stage_empty?(stage) }
11
+ define_method("#{stage}") do |image|
12
+ image.add_command("export DAPP_BUILD_STAGE=#{stage}",
13
+ *stage_commands(stage)) unless stage_empty?(stage)
13
14
  end
14
15
  end
16
+
17
+ def stage_empty?(stage)
18
+ stage_commands(stage).empty?
19
+ end
20
+
21
+ def stage_commands(stage)
22
+ application.config._shell.public_send("_#{stage}")
23
+ end
15
24
  end
16
25
  end
17
26
  end
data/lib/dapp/cli.rb CHANGED
@@ -7,7 +7,7 @@ module Dapp
7
7
  include Mixlib::CLI
8
8
  include Helper::Trivia
9
9
 
10
- SUBCOMMANDS = %w(build smartpush push list run stages metadata).freeze
10
+ SUBCOMMANDS = %w(build smartpush push list run stages).freeze
11
11
 
12
12
  banner <<BANNER.freeze
13
13
  Usage: dapp [options] sub-command [sub-command options]
@@ -20,7 +20,6 @@ dapp smartpush [options] [PATTERN ...] REPOPREFIX
20
20
  dapp list [options] [PATTERN ...]
21
21
  dapp run [options] [PATTERN...] [DOCKER ARGS]
22
22
  dapp stages
23
- dapp metadata
24
23
 
25
24
  Options:
26
25
  BANNER
@@ -20,9 +20,9 @@ BANNER
20
20
  long: '--tmp-dir-prefix PREFIX',
21
21
  description: 'Tmp directory prefix'
22
22
 
23
- option :metadata_dir,
24
- long: '--metadata-dir PATH',
25
- description: 'Metadata directory'
23
+ option :build_dir,
24
+ long: '--build-dir PATH',
25
+ description: 'Directory where build cache stored (DIR/.dapps-build by default)'
26
26
 
27
27
  option :git_artifact_branch,
28
28
  long: '--git-artifact-branch BRANCH',
@@ -41,8 +41,8 @@ BANNER
41
41
  option :introspect_stage,
42
42
  long: '--introspect-stage STAGE',
43
43
  proc: proc { |v| v.to_sym },
44
- in: [nil, :from, :infra_install, :source_1_archive, :source_1, :install, :source_2,
45
- :infra_setup, :source_3, :chef_cookbooks, :setup, :source_4, :source_5]
44
+ in: [nil, :from, :infra_install, :source_1_archive, :source_1, :install, :artifact, :source_2,
45
+ :infra_setup, :source_3, :chef_cookbooks, :setup, :source_4, :source_5, :docker_instructions]
46
46
  end
47
47
  end
48
48
  end
data/lib/dapp/cli/push.rb CHANGED
@@ -15,10 +15,6 @@ Usage:
15
15
  Options:
16
16
  BANNER
17
17
 
18
- option :metadata_dir,
19
- long: '--metadata-dir PATH',
20
- description: 'Metadata directory'
21
-
22
18
  option :git_artifact_branch,
23
19
  long: '--git-artifact-branch BRANCH',
24
20
  description: 'Default branch to archive artifacts from'
data/lib/dapp/cli/run.rb CHANGED
@@ -16,9 +16,6 @@ Usage:
16
16
 
17
17
  Options:
18
18
  BANNER
19
- option :metadata_dir,
20
- long: '--metadata-dir PATH',
21
- description: 'Metadata directory'
22
19
 
23
20
  def read_cli_options(args)
24
21
  self.class.cli_wrapper(self) do
@@ -48,35 +48,12 @@ module Dapp
48
48
  # Stage
49
49
  class Stage < Base
50
50
  attr_accessor :_config
51
- attr_accessor :_before, :_after
52
-
53
- def initialize(*args)
54
- super
55
- raise Error::Config, code: :stage_artifact_not_associated if _before.nil? && _after.nil?
56
- end
57
-
58
- def _before=(stage)
59
- @_before = stage.to_sym
60
- validate_associated_option(option: :before, value: @_before)
61
- end
62
-
63
- def _after=(stage)
64
- @_after = stage.to_sym
65
- validate_associated_option(option: :after, value: @_after)
66
- end
67
51
 
68
52
  protected
69
53
 
70
54
  def code
71
55
  :artifact_unexpected_attribute
72
56
  end
73
-
74
- private
75
-
76
- def validate_associated_option(option:, value:)
77
- return if Dapp::Application::STAGES.include? value
78
- raise Error::Config, code: :stage_artifact_incorrect_associated_value, data: { option: option, value: value }
79
- end
80
57
  end
81
58
  end
82
59
  end
@@ -62,14 +62,6 @@ module Dapp
62
62
  end
63
63
  end
64
64
 
65
- def metadata_flush
66
- build_configs.each do |config|
67
- log(config._name)
68
- app = Application.new(config: config, cli_options: cli_options, ignore_git_fetch: true)
69
- FileUtils.rm_rf app.metadata_path
70
- end
71
- end
72
-
73
65
  private
74
66
 
75
67
  def build_configs
@@ -87,7 +79,15 @@ module Dapp
87
79
 
88
80
  def apps(dappfile_path, app_filters:)
89
81
  config = Config::Main.new(dappfile_path: dappfile_path) do |conf|
90
- conf.instance_eval File.read(dappfile_path), dappfile_path
82
+ begin
83
+ conf.instance_eval File.read(dappfile_path), dappfile_path
84
+ rescue SyntaxError, StandardError => e
85
+ message = case e
86
+ when ArgumentError then "#{e.backtrace.first[/`.*'$/]}: #{e.message}"
87
+ else e.message
88
+ end
89
+ raise Error::Dappfile, code: :incorrect, data: { error: e.class.name, path: dappfile_path, message: message }
90
+ end
91
91
  end
92
92
  config._apps.select { |app| app_filters.any? { |pattern| File.fnmatch(pattern, app._name) } }
93
93
  end
@@ -0,0 +1,6 @@
1
+ module Dapp
2
+ module Error
3
+ # Dappfile
4
+ class Dappfile < Base; end
5
+ end
6
+ end
@@ -63,8 +63,8 @@ module Dapp
63
63
  [@paths].flatten.compact.map { |path| (with_cwd && cwd ? "#{cwd}/#{path}" : path).gsub(%r{^\/*|\/*$}, '') }.join(' ') if @paths
64
64
  end
65
65
 
66
- def filename(ending)
67
- "#{repo.name}#{name ? "_#{name}" : nil}#{ending}"
66
+ def full_name
67
+ "#{repo.name}#{name ? "_#{name}" : nil}"
68
68
  end
69
69
 
70
70
  protected
@@ -54,7 +54,7 @@ module Dapp
54
54
  add_option(:entrypoint, value)
55
55
  end
56
56
 
57
- def add_commands(*commands)
57
+ def add_command(*commands)
58
58
  @bash_commands.concat(commands.flatten)
59
59
  end
60
60
 
@@ -78,9 +78,7 @@ module Dapp
78
78
  def from_options
79
79
  return {} if from.nil?
80
80
  [:entrypoint, :cmd].each_with_object({}) do |option, options|
81
- output = shellout!("docker inspect --format='{{json .Config.#{option.to_s.capitalize}}}' #{from.built_id}").stdout.strip
82
- options[option] = output == 'null' ? [] : JSON.parse(output)
83
- options
81
+ options[option] = self.class.image_config_option(image_id: from.built_id, option: option)
84
82
  end
85
83
  end
86
84
 
@@ -48,6 +48,11 @@ module Dapp
48
48
  [cache[:created_at], cache[:size]]
49
49
  end
50
50
 
51
+ def self.image_config_option(image_id:, option:)
52
+ output = shellout!("docker inspect --format='{{json .Config.#{option.to_s.capitalize}}}' #{image_id}").stdout.strip
53
+ output == 'null' ? [] : JSON.parse(output)
54
+ end
55
+
51
56
  protected
52
57
 
53
58
  def cache
@@ -14,6 +14,10 @@ module Dapp
14
14
  super(name: name, from: from)
15
15
  end
16
16
 
17
+ def labels
18
+ self.class.image_config_option(image_id: built_id, option: 'labels')
19
+ end
20
+
17
21
  def built_id
18
22
  @built_id ||= id
19
23
  end
data/lib/dapp/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  # Version
2
2
  module Dapp
3
- VERSION = '0.4.8'.freeze
4
- BUILD_CACHE_VERSION = 1
3
+ VERSION = '0.5.0'.freeze
4
+ BUILD_CACHE_VERSION = 2
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
@@ -331,8 +331,10 @@ files:
331
331
  - lib/dapp/application/logging.rb
332
332
  - lib/dapp/application/path.rb
333
333
  - lib/dapp/application/tags.rb
334
+ - lib/dapp/build/stage/artifact.rb
334
335
  - lib/dapp/build/stage/base.rb
335
336
  - lib/dapp/build/stage/chef_cookbooks.rb
337
+ - lib/dapp/build/stage/docker_instructions.rb
336
338
  - lib/dapp/build/stage/from.rb
337
339
  - lib/dapp/build/stage/infra_install.rb
338
340
  - lib/dapp/build/stage/infra_setup.rb
@@ -342,11 +344,17 @@ files:
342
344
  - lib/dapp/build/stage/setup.rb
343
345
  - lib/dapp/build/stage/source_1.rb
344
346
  - lib/dapp/build/stage/source_1_archive.rb
347
+ - lib/dapp/build/stage/source_1_archive_dependencies.rb
348
+ - lib/dapp/build/stage/source_1_dependencies.rb
345
349
  - lib/dapp/build/stage/source_2.rb
350
+ - lib/dapp/build/stage/source_2_dependencies.rb
346
351
  - lib/dapp/build/stage/source_3.rb
352
+ - lib/dapp/build/stage/source_3_dependencies.rb
347
353
  - lib/dapp/build/stage/source_4.rb
354
+ - lib/dapp/build/stage/source_4_dependencies.rb
348
355
  - lib/dapp/build/stage/source_5.rb
349
356
  - lib/dapp/build/stage/source_base.rb
357
+ - lib/dapp/build/stage/source_dependencies_base.rb
350
358
  - lib/dapp/builder/base.rb
351
359
  - lib/dapp/builder/chef.rb
352
360
  - lib/dapp/builder/chef/berksfile.rb
@@ -357,8 +365,6 @@ files:
357
365
  - lib/dapp/cli/base.rb
358
366
  - lib/dapp/cli/build.rb
359
367
  - lib/dapp/cli/list.rb
360
- - lib/dapp/cli/metadata.rb
361
- - lib/dapp/cli/metadata/flush.rb
362
368
  - lib/dapp/cli/push.rb
363
369
  - lib/dapp/cli/run.rb
364
370
  - lib/dapp/cli/smartpush.rb
@@ -378,6 +384,7 @@ files:
378
384
  - lib/dapp/error/build.rb
379
385
  - lib/dapp/error/config.rb
380
386
  - lib/dapp/error/controller.rb
387
+ - lib/dapp/error/dappfile.rb
381
388
  - lib/dapp/error/shellout.rb
382
389
  - lib/dapp/exception/base.rb
383
390
  - lib/dapp/exception/introspect_image.rb