dapp 0.9.4 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dapp +9 -1
  3. data/config/en/net_status.yml +5 -2
  4. data/lib/dapp.rb +2 -1
  5. data/lib/dapp/config/base.rb +5 -0
  6. data/lib/dapp/config/directive/base.rb +5 -4
  7. data/lib/dapp/dapp.rb +1 -1
  8. data/lib/dapp/dapp/deps/base.rb +2 -2
  9. data/lib/dapp/dapp/logging/paint.rb +1 -1
  10. data/lib/dapp/dapp/logging/process.rb +18 -5
  11. data/lib/dapp/dimg/build/stage/base.rb +39 -5
  12. data/lib/dapp/dimg/build/stage/before_setup.rb +2 -0
  13. data/lib/dapp/dimg/build/stage/build_artifact.rb +2 -0
  14. data/lib/dapp/dimg/build/stage/from.rb +2 -2
  15. data/lib/dapp/dimg/build/stage/ga_archive.rb +0 -8
  16. data/lib/dapp/dimg/build/stage/ga_artifact_patch.rb +1 -5
  17. data/lib/dapp/dimg/build/stage/ga_base.rb +4 -10
  18. data/lib/dapp/dimg/build/stage/ga_latest_patch.rb +0 -8
  19. data/lib/dapp/dimg/build/stage/install/ga_post_install_patch.rb +0 -4
  20. data/lib/dapp/dimg/build/stage/install/ga_post_install_patch_dependencies.rb +1 -1
  21. data/lib/dapp/dimg/build/stage/install/ga_pre_install_patch.rb +0 -4
  22. data/lib/dapp/dimg/build/stage/install/ga_pre_install_patch_dependencies.rb +1 -1
  23. data/lib/dapp/dimg/build/stage/install/install.rb +1 -0
  24. data/lib/dapp/dimg/build/stage/mod/git_artifact_dependencies.rb +23 -0
  25. data/lib/dapp/dimg/build/stage/mod/group.rb +1 -1
  26. data/lib/dapp/dimg/build/stage/mod/logging.rb +4 -2
  27. data/lib/dapp/dimg/build/stage/setup/ga_post_setup_patch.rb +0 -4
  28. data/lib/dapp/dimg/build/stage/setup/ga_post_setup_patch_dependencies.rb +1 -1
  29. data/lib/dapp/dimg/build/stage/setup/ga_pre_setup_patch.rb +0 -4
  30. data/lib/dapp/dimg/build/stage/setup/ga_pre_setup_patch_dependencies.rb +1 -1
  31. data/lib/dapp/dimg/build/stage/setup/setup.rb +1 -0
  32. data/lib/dapp/dimg/builder/chef.rb +3 -3
  33. data/lib/dapp/dimg/config/artifact_group.rb +12 -16
  34. data/lib/dapp/dimg/config/dimg/instance_methods.rb +22 -20
  35. data/lib/dapp/dimg/config/dimg/validation.rb +5 -5
  36. data/lib/dapp/dimg/config/directive/artifact.rb +18 -15
  37. data/lib/dapp/dimg/config/directive/artifact_base.rb +30 -27
  38. data/lib/dapp/dimg/config/directive/base.rb +5 -1
  39. data/lib/dapp/dimg/config/directive/chef.rb +14 -12
  40. data/lib/dapp/dimg/config/directive/docker/base.rb +7 -6
  41. data/lib/dapp/dimg/config/directive/docker/dimg.rb +9 -11
  42. data/lib/dapp/dimg/config/directive/git_artifact_local.rb +11 -5
  43. data/lib/dapp/dimg/config/directive/git_artifact_remote.rb +10 -14
  44. data/lib/dapp/dimg/config/directive/mount.rb +10 -6
  45. data/lib/dapp/dimg/config/directive/shell/dimg.rb +14 -16
  46. data/lib/dapp/dimg/dapp/command/stages/cleanup_local.rb +1 -1
  47. data/lib/dapp/dimg/dimg.rb +1 -1
  48. data/lib/dapp/dimg/dimg/stages.rb +5 -1
  49. data/lib/dapp/dimg/git_artifact.rb +10 -12
  50. data/lib/dapp/dimg/git_repo/base.rb +2 -0
  51. data/lib/dapp/dimg/git_repo/own.rb +1 -1
  52. data/lib/dapp/dimg/image/docker.rb +1 -0
  53. data/lib/dapp/dimg/image/stage.rb +1 -1
  54. data/lib/dapp/dimg/lock/file.rb +1 -1
  55. data/lib/dapp/helper/cli.rb +2 -1
  56. data/lib/dapp/helper/net_status.rb +13 -3
  57. data/lib/dapp/version.rb +1 -1
  58. metadata +17 -3
  59. data/lib/dapp/dimg/error/shellout.rb +0 -7
@@ -12,7 +12,7 @@ module Dapp
12
12
  end
13
13
 
14
14
  def dependencies
15
- next_stage.next_stage.context # Install
15
+ dimg.stage_by_name(:install).context
16
16
  end
17
17
  end # GAPreInstallPatchDependencies
18
18
  end
@@ -5,6 +5,7 @@ module Dapp
5
5
  module Install
6
6
  class Install < Base
7
7
  include Mod::Group
8
+ include Mod::GitArtifactsDependencies
8
9
 
9
10
  def initialize(dimg, next_stage)
10
11
  @prev_stage = GAPreInstallPatch.new(dimg, self)
@@ -0,0 +1,23 @@
1
+ module Dapp
2
+ module Dimg
3
+ module Build
4
+ module Stage
5
+ module Mod
6
+ module GitArtifactsDependencies
7
+ def local_git_artifacts_dependencies
8
+ dimg.local_git_artifacts.map do |git_artifact|
9
+ args = []
10
+ args << self
11
+ if dimg.dev_mode?
12
+ args << git_artifact.latest_commit
13
+ args << nil
14
+ end
15
+ git_artifact.stage_dependencies_checksums(*args)
16
+ end
17
+ end
18
+ end
19
+ end # Mod
20
+ end # Stage
21
+ end # Build
22
+ end # Dimg
23
+ end # Dapp
@@ -24,7 +24,7 @@ module Dapp
24
24
 
25
25
  def group_opened?
26
26
  return false if prev_group_stage.nil?
27
- prev_group_stage.group_opened? || !prev_group_stage.empty?
27
+ prev_group_stage.group_opened? || prev_group_stage.image_should_be_build?
28
28
  end
29
29
 
30
30
  def prev_group_stage
@@ -74,8 +74,10 @@ module Dapp
74
74
  end
75
75
 
76
76
  def log_image_build_process
77
- return yield if should_be_quiet?
78
- dimg.dapp.log_process(log_name, process: dimg.dapp.t(code: 'status.process.building'), short: should_not_be_detailed?) { yield }
77
+ dimg.dapp.log_process(log_name,
78
+ process: dimg.dapp.t(code: 'status.process.building'),
79
+ short: should_not_be_detailed?,
80
+ quiet: should_be_quiet?) { yield }
79
81
  end
80
82
 
81
83
  def ignore_log_commands?
@@ -10,10 +10,6 @@ module Dapp
10
10
  @prev_stage = GAPostSetupPatchDependencies.new(dimg, self)
11
11
  super
12
12
  end
13
-
14
- def next_g_a_stage
15
- next_stage.next_stage
16
- end
17
13
  end # GAPostSetupPatch
18
14
  end
19
15
  end # Stage
@@ -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.layer_commit(git_artifact), git_artifact.latest_commit)
24
+ git_artifact.patch_size(prev_g_a_stage.layer_commit(git_artifact), git_artifact.latest_commit)
25
25
  end.reduce(0, :+)
26
26
  end
27
27
  end # GAPostSetupPatchDependencies
@@ -10,10 +10,6 @@ module Dapp
10
10
  @prev_stage = GAPreSetupPatchDependencies.new(dimg, self)
11
11
  super
12
12
  end
13
-
14
- def prev_g_a_stage
15
- super.prev_stage.prev_stage # GAPostInstallPatch
16
- end
17
13
  end # GAPrePatch
18
14
  end
19
15
  end # Stage
@@ -12,7 +12,7 @@ module Dapp
12
12
  end
13
13
 
14
14
  def dependencies
15
- next_stage.next_stage.context # Setup
15
+ dimg.stage_by_name(:setup).context
16
16
  end
17
17
  end # GAPreSetupPatchDependencies
18
18
  end
@@ -5,6 +5,7 @@ module Dapp
5
5
  module Setup
6
6
  class Setup < Base
7
7
  include Mod::Group
8
+ include Mod::GitArtifactsDependencies
8
9
 
9
10
  def initialize(dimg, next_stage)
10
11
  @prev_stage = GAPreSetupPatch.new(dimg, self)
@@ -1,7 +1,7 @@
1
1
  module Dapp
2
2
  module Dimg
3
3
  class Builder::Chef < Builder::Base
4
- DEFAULT_CHEFDK_IMAGE = 'dappdeps/chefdk:0.17.3-1'.freeze # TODO: config, DSL, DEFAULT_CHEFDK_IMAGE
4
+ DEFAULT_CHEFDK_IMAGE = 'dappdeps/chefdk:1.2.22-1'.freeze # TODO: config, DSL, DEFAULT_CHEFDK_IMAGE
5
5
 
6
6
  %i(before_install install before_setup setup build_artifact).each do |stage|
7
7
  define_method("#{stage}?") {!stage_empty?(stage)}
@@ -30,7 +30,7 @@ module Dapp
30
30
 
31
31
  %i(before_install install before_setup setup).each do |stage|
32
32
  unless stage_empty?(stage) || stage_cookbooks_checksum_path(stage).exist?
33
- raise Error::Chef, code: :chef_stage_checksum_not_calculated, data: {stage: stage}
33
+ raise Error::Chef, code: :stage_checksum_not_calculated, data: {stage: stage}
34
34
  end
35
35
  end
36
36
  end
@@ -71,7 +71,7 @@ module Dapp
71
71
  def builder_cookbook
72
72
  @builder_cookbook ||= begin
73
73
  unless dimg.dapp.builder_cookbook_path.exist?
74
- raise Error,
74
+ raise Error::Chef,
75
75
  code: :builder_cookbook_not_found,
76
76
  data: {path: dimg.dapp.builder_cookbook_path.to_s}
77
77
  end
@@ -2,6 +2,14 @@ module Dapp
2
2
  module Dimg
3
3
  module Config
4
4
  class ArtifactGroup < DimgGroup
5
+ def export(*args, &blk)
6
+ artifact_config = pass_to_default(ArtifactDimg.new("artifact-#{SecureRandom.hex(2)}", dapp: dapp))
7
+ artifact = Directive::Artifact.new(dapp: dapp, config: artifact_config)
8
+ artifact.export(*args, &blk).tap do
9
+ _export.concat artifact._export
10
+ end
11
+ end
12
+
5
13
  def _shell(&blk)
6
14
  @_shell ||= Directive::Shell::Artifact.new(dapp: dapp, &blk)
7
15
  end
@@ -14,28 +22,16 @@ module Dapp
14
22
  @_export ||= []
15
23
  end
16
24
 
25
+ def validate!
26
+ _export.each(&:validate!)
27
+ end
28
+
17
29
  undef :artifact
18
30
  undef :dimg
19
31
  undef :dimg_group
20
32
 
21
33
  protected
22
34
 
23
- def export(*args, &blk)
24
- _export.concat begin
25
- artifact_config = pass_to_default(
26
- ArtifactDimg.new(
27
- "artifact-#{SecureRandom.hex(2)}",
28
- dapp: dapp
29
- )
30
- )
31
-
32
- artifact = Directive::Artifact.new(dapp: dapp, config: artifact_config)
33
- artifact.send(:export, *args, &blk)
34
-
35
- artifact._export
36
- end
37
- end
38
-
39
35
  def check_dimg_directive_order(_directive)
40
36
  end
41
37
 
@@ -5,6 +5,7 @@ module Dapp
5
5
  module InstanceMethods
6
6
  attr_reader :_builder
7
7
  attr_reader :_chef, :_shell, :_docker, :_git_artifact, :_mount, :_artifact
8
+ attr_reader :_artifact_groups
8
9
 
9
10
  def dev_mode
10
11
  @_dev_mode = true
@@ -25,20 +26,20 @@ module Dapp
25
26
  end
26
27
 
27
28
  def artifact(&blk)
28
- _artifact.concat begin
29
- pass_to_custom(ArtifactGroup.new(dapp: dapp), :clone_to_artifact).tap do |artifact_group|
30
- artifact_group.instance_eval(&blk) if block_given?
31
- end._export
32
- end
29
+ pass_to_custom(ArtifactGroup.new(dapp: dapp), :clone_to_artifact).tap do |artifact_group|
30
+ _artifact_groups << directive_eval(artifact_group, &blk)
31
+ end
33
32
  end
34
33
 
35
34
  def git(url = nil, &blk)
36
35
  type = url.nil? ? :local : :remote
37
- _git_artifact.send(type, url.to_s, &blk)
36
+ _git_artifact.public_send(type, url.to_s, &blk)
38
37
  end
39
38
 
40
39
  def mount(to, &blk)
41
- _mount << Directive::Mount.new(to, dapp: dapp, &blk)
40
+ Directive::Mount.new(to, dapp: dapp, &blk).tap do |mount|
41
+ _mount << mount
42
+ end
42
43
  end
43
44
 
44
45
  def _dev_mode
@@ -75,8 +76,12 @@ module Dapp
75
76
  end
76
77
  end
77
78
 
79
+ def _artifact_groups
80
+ @_artifact_groups ||= []
81
+ end
82
+
78
83
  def _artifact
79
- @_artifact ||= []
84
+ _artifact_groups.map(&:_export).flatten
80
85
  end
81
86
 
82
87
  [:before, :after].each do |order|
@@ -104,11 +109,15 @@ module Dapp
104
109
  end
105
110
 
106
111
  def local(_, &blk)
107
- @_local << Directive::GitArtifactLocal.new(dapp: dapp, &blk)
112
+ Directive::GitArtifactLocal.new(dapp: dapp, &blk).tap do |git|
113
+ @_local << git
114
+ end
108
115
  end
109
116
 
110
117
  def remote(repo_url, &blk)
111
- @_remote << Directive::GitArtifactRemote.new(repo_url, dapp: dapp, &blk)
118
+ Directive::GitArtifactRemote.new(repo_url, dapp: dapp, &blk).tap do |git|
119
+ @_remote << git
120
+ end
112
121
  end
113
122
 
114
123
  def _local
@@ -119,14 +128,12 @@ module Dapp
119
128
  @_remote.map(&:_export).flatten
120
129
  end
121
130
 
122
- protected
123
-
124
131
  def empty?
125
132
  (_local + _remote).empty?
126
133
  end
127
134
 
128
135
  def validate!
129
- (_local + _remote).each { |exp| exp.send(:validate!) }
136
+ (_local + _remote).each(&:validate!)
130
137
  end
131
138
  end
132
139
 
@@ -137,11 +144,6 @@ module Dapp
137
144
  raise Error::Config, code: :builder_type_conflict unless @_builder == type
138
145
  end
139
146
 
140
- def directive_eval(directive, &blk)
141
- directive.instance_eval(&blk) if block_given?
142
- directive
143
- end
144
-
145
147
  def pass_to_default(dimg)
146
148
  pass_to_custom(dimg, :clone)
147
149
  end
@@ -152,7 +154,7 @@ module Dapp
152
154
 
153
155
  obj.instance_variable_set(directive, begin
154
156
  case variable
155
- when Directive::Base, GitArtifact then variable.send(clone_method)
157
+ when Directive::Base, GitArtifact then variable.public_send(clone_method)
156
158
  when Symbol then variable
157
159
  when Array then variable.dup
158
160
  when TrueClass, FalseClass then variable
@@ -167,7 +169,7 @@ module Dapp
167
169
  def passed_directives
168
170
  [:@_chef, :@_shell, :@_docker,
169
171
  :@_git_artifact, :@_mount,
170
- :@_artifact, :@_builder, :@_dev_mode]
172
+ :@_artifact_groups, :@_builder, :@_dev_mode]
171
173
  end
172
174
  end # InstanceMethods
173
175
  # rubocop:enable Metrics/ModuleLength
@@ -3,8 +3,6 @@ module Dapp
3
3
  module Config
4
4
  class Dimg < Base
5
5
  module Validation
6
- protected
7
-
8
6
  def validate!
9
7
  directives_validate!
10
8
  validate_scratch!
@@ -12,6 +10,8 @@ module Dapp
12
10
  validate_artifacts_artifacts!
13
11
  end
14
12
 
13
+ protected
14
+
15
15
  def validate_scratch!
16
16
  if _docker._from.nil?
17
17
  validate_scratch_directives!
@@ -25,7 +25,7 @@ module Dapp
25
25
  passed_directives.each do |v|
26
26
  next if (value = instance_variable_get(v)).nil?
27
27
  Array(value).each do |elm|
28
- elm.send(:validate!) if elm.methods.include?(:validate!)
28
+ elm.validate! if elm.respond_to?(:validate!)
29
29
  end
30
30
  end
31
31
  end
@@ -36,7 +36,7 @@ module Dapp
36
36
  directives.each do |name, user_name|
37
37
  raise Error::Config,
38
38
  code: :scratch_unsupported_directive,
39
- data: { directive: user_name } unless public_send(name).send(:empty?)
39
+ data: { directive: user_name } unless public_send(name).empty?
40
40
  end
41
41
 
42
42
  docker_directives = [:_expose, :_env, :_cmd, :_onbuild, :_workdir, :_user, :_entrypoint]
@@ -44,7 +44,7 @@ module Dapp
44
44
  value = _docker.public_send(directive)
45
45
  raise Error::Config,
46
46
  code: :scratch_unsupported_directive,
47
- data: { directive: "docker.#{directive}" } unless value.nil? || value.send(:empty?)
47
+ data: { directive: "docker.#{directive}" } unless value.nil? || value.empty?
48
48
  end
49
49
  end
50
50
 
@@ -7,7 +7,6 @@ module Dapp
7
7
 
8
8
  def initialize(config:, **kwargs, &blk)
9
9
  @_config = config
10
-
11
10
  super(**kwargs, &blk)
12
11
  end
13
12
 
@@ -23,27 +22,31 @@ module Dapp
23
22
  attr_accessor :_config
24
23
  attr_accessor :_before, :_after
25
24
 
26
- def not_associated?
27
- (_before || _after).nil?
28
- end
29
-
30
- protected
31
-
32
25
  def before(stage)
33
- stage = stage.to_sym
34
- associate_validation!(:before, stage, @_before)
35
- @_before = stage
26
+ sub_directive_eval do
27
+ stage = stage.to_sym
28
+ associate_validation!(:before, stage, @_before)
29
+ @_before = stage
30
+ end
36
31
  end
37
32
 
38
33
  def after(stage)
39
- stage = stage.to_sym
40
- associate_validation!(:after, stage, @_after)
41
- @_after = stage
34
+ sub_directive_eval do
35
+ stage = stage.to_sym
36
+ associate_validation!(:after, stage, @_after)
37
+ @_after = stage
38
+ end
42
39
  end
43
40
 
41
+ def not_associated?
42
+ (_before || _after).nil?
43
+ end
44
+
45
+ protected
46
+
44
47
  def associate_validation!(type, stage, _old_stage)
45
48
  conflict_type = [:before, :after].find { |t| t != type }
46
- conflict_stage = send("_#{conflict_type}")
49
+ conflict_stage = public_send("_#{conflict_type}")
47
50
 
48
51
  raise Error::Config, code: :stage_artifact_not_supported_associated_stage,
49
52
  data: { stage: "#{type} #{stage.inspect}" } unless [:install, :setup].include? stage
@@ -52,7 +55,7 @@ module Dapp
52
55
  data: { stage: "#{type} #{stage.inspect}",
53
56
  conflict_stage: "#{conflict_type} #{conflict_stage.inspect}" } if conflict_stage
54
57
 
55
- defined_stage = send("_#{type}")
58
+ defined_stage = public_send("_#{type}")
56
59
  dapp.log_config_warning(
57
60
  desc: {
58
61
  code: :stage_artifact_rewritten,
@@ -7,10 +7,23 @@ module Dapp
7
7
 
8
8
  def initialize(**kwargs, &blk)
9
9
  @_export = []
10
-
11
10
  super(**kwargs, &blk)
12
11
  end
13
12
 
13
+ def owner(owner)
14
+ sub_directive_eval { @_owner = owner }
15
+ end
16
+
17
+ def group(group)
18
+ sub_directive_eval { @_group = group }
19
+ end
20
+
21
+ def export(absolute_dir_path = '/', &blk)
22
+ self.class.const_get('Export').new(absolute_dir_path, dapp: dapp, &blk).tap do |export|
23
+ @_export << export
24
+ end
25
+ end
26
+
14
27
  def _export
15
28
  @_export.each do |export|
16
29
  export._owner ||= @_owner
@@ -43,53 +56,43 @@ module Dapp
43
56
  }
44
57
  end
45
58
 
46
- protected
47
-
48
59
  def to(absolute_path)
49
- raise Error::Config, code: :export_to_absolute_path_required unless Pathname(absolute_path).absolute?
50
- @_to = path_format(absolute_path)
60
+ sub_directive_eval do
61
+ raise Error::Config, code: :export_to_absolute_path_required unless Pathname(absolute_path).absolute?
62
+ @_to = path_format(absolute_path)
63
+ end
51
64
  end
52
65
 
53
66
  def include_paths(*relative_paths)
54
- unless relative_paths.all? { |path| Pathname(path).relative? }
55
- raise Error::Config, code: :export_include_paths_relative_path_required
67
+ sub_directive_eval do
68
+ unless relative_paths.all? { |path| Pathname(path).relative? }
69
+ raise Error::Config, code: :export_include_paths_relative_path_required
70
+ end
71
+ _include_paths.concat(relative_paths.map(&method(:path_format)))
56
72
  end
57
- _include_paths.concat(relative_paths.map(&method(:path_format)))
58
73
  end
59
74
 
60
75
  def exclude_paths(*relative_paths)
61
- unless relative_paths.all? { |path| Pathname(path).relative? }
62
- raise Error::Config, code: :export_exclude_paths_relative_path_required
76
+ sub_directive_eval do
77
+ unless relative_paths.all? { |path| Pathname(path).relative? }
78
+ raise Error::Config, code: :export_exclude_paths_relative_path_required
79
+ end
80
+ _exclude_paths.concat(relative_paths.map(&method(:path_format)))
63
81
  end
64
- _exclude_paths.concat(relative_paths.map(&method(:path_format)))
65
82
  end
66
83
 
67
84
  def owner(owner)
68
- @_owner = owner
85
+ sub_directive_eval { @_owner = owner }
69
86
  end
70
87
 
71
88
  def group(group)
72
- @_group = group
89
+ sub_directive_eval { @_group = group }
73
90
  end
74
91
 
75
92
  def validate!
76
93
  raise Error::Config, code: :export_to_required if _to.nil?
77
94
  end
78
95
  end
79
-
80
- protected
81
-
82
- def owner(owner)
83
- @_owner = owner
84
- end
85
-
86
- def group(group)
87
- @_group = group
88
- end
89
-
90
- def export(absolute_dir_path = '/', &blk)
91
- @_export << self.class.const_get('Export').new(absolute_dir_path, dapp: dapp, &blk)
92
- end
93
96
  end
94
97
  end
95
98
  end