dapp 0.9.4 → 0.10.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 (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
@@ -2,7 +2,11 @@ module Dapp
2
2
  module Dimg
3
3
  module Config
4
4
  module Directive
5
- class Base < ::Dapp::Config::Directive::Base; end
5
+ class Base < ::Dapp::Config::Directive::Base
6
+ def clone_to_artifact
7
+ clone
8
+ end
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -14,24 +14,28 @@ module Dapp
14
14
  end
15
15
 
16
16
  def dimod(name, *args)
17
- @_dimod << name
18
- cookbook(name, *args)
17
+ sub_directive_eval do
18
+ @_dimod << name
19
+ cookbook(name, *args)
20
+ end
19
21
  end
20
22
 
21
23
  def recipe(name)
22
- @_recipe << name
24
+ sub_directive_eval { @_recipe << name }
23
25
  end
24
26
 
25
27
  def attributes
26
28
  @_attributes ||= Attributes.new
27
29
  end
28
30
 
29
- def cookbook(name, version_constraint=nil, **kwargs)
30
- @_cookbook[name] = {}.tap do |desc|
31
- desc.update(kwargs)
32
- desc[:name] = name
33
- desc[:version_constraint] = version_constraint if version_constraint
34
- desc[:path] = File.expand_path(desc[:path], dapp.path) if desc.key? :path
31
+ def cookbook(name, version_constraint = nil, **kwargs)
32
+ sub_directive_eval do
33
+ @_cookbook[name] = {}.tap do |desc|
34
+ desc.update(kwargs)
35
+ desc[:name] = name
36
+ desc[:version_constraint] = version_constraint if version_constraint
37
+ desc[:path] = File.expand_path(desc[:path], dapp.path) if desc.key? :path
38
+ end
35
39
  end
36
40
  end
37
41
 
@@ -52,12 +56,10 @@ module Dapp
52
56
 
53
57
  %i(before_install install before_setup setup build_artifact).each do |stage|
54
58
  define_method("__#{stage}_attributes") do
55
- attributes.in_depth_merge send("_#{stage}_attributes")
59
+ attributes.in_depth_merge public_send("_#{stage}_attributes")
56
60
  end
57
61
  end
58
62
 
59
- protected
60
-
61
63
  def empty?
62
64
  (@_dimod + @_recipe).empty? && attributes.empty?
63
65
  end
@@ -7,12 +7,13 @@ module Dapp
7
7
  attr_reader :_from, :_from_cache_version
8
8
 
9
9
  def from(image, cache_version: nil)
10
- image = image.to_s
11
- raise(Error::Config, code: :docker_from_incorrect,
12
- data: { name: image }) unless ::Dapp::Dimg::Image::Docker.image_name?(image)
13
- raise(Error::Config, code: :docker_from_without_tag, data: { name: image }) unless image.include?(':')
14
- @_from = image
15
- @_from_cache_version = cache_version
10
+ sub_directive_eval do
11
+ image = image.to_s
12
+ raise(Error::Config, code: :docker_from_incorrect, data: { name: image }) unless ::Dapp::Dimg::Image::Docker.image_name?(image)
13
+ raise(Error::Config, code: :docker_from_without_tag, data: { name: image }) unless image.include?(':')
14
+ @_from = image
15
+ @_from_cache_version = cache_version
16
+ end
16
17
  end
17
18
  end
18
19
  end
@@ -18,39 +18,39 @@ module Dapp
18
18
  end
19
19
 
20
20
  def volume(*args)
21
- @_volume.concat(args)
21
+ sub_directive_eval { @_volume.concat(args) }
22
22
  end
23
23
 
24
24
  def expose(*args)
25
- @_expose.concat(args)
25
+ sub_directive_eval { @_expose.concat(args) }
26
26
  end
27
27
 
28
28
  def env(**options)
29
- @_env.merge!(options)
29
+ sub_directive_eval { @_env.merge!(options) }
30
30
  end
31
31
 
32
32
  def label(**options)
33
- @_label.merge!(options)
33
+ sub_directive_eval { @_label.merge!(options) }
34
34
  end
35
35
 
36
36
  def cmd(*args)
37
- @_cmd.concat(args)
37
+ sub_directive_eval { @_cmd.concat(args) }
38
38
  end
39
39
 
40
40
  def onbuild(*args)
41
- @_onbuild.concat(args)
41
+ sub_directive_eval { @_onbuild.concat(args) }
42
42
  end
43
43
 
44
44
  def workdir(path)
45
- @_workdir = path_format(path)
45
+ sub_directive_eval { @_workdir = path_format(path) }
46
46
  end
47
47
 
48
48
  def user(val)
49
- @_user = val
49
+ sub_directive_eval { @_user = val }
50
50
  end
51
51
 
52
52
  def entrypoint(*cmd_with_args)
53
- @_entrypoint = cmd_with_args.flatten
53
+ sub_directive_eval { @_entrypoint = cmd_with_args.flatten }
54
54
  end
55
55
 
56
56
  def _change_options
@@ -67,8 +67,6 @@ module Dapp
67
67
  }
68
68
  end
69
69
 
70
- protected
71
-
72
70
  def clone_to_artifact
73
71
  Artifact.new(dapp: dapp).tap do |docker|
74
72
  docker.instance_variable_set('@_from', @_from)
@@ -11,19 +11,25 @@ module Dapp
11
11
  @stage_dependencies ||= StageDependencies.new(&blk)
12
12
  end
13
13
 
14
+ def validate!
15
+ raise Error::Config, code: :add_to_required if _to.nil?
16
+ end
17
+
14
18
  def _artifact_options
15
19
  super.merge(stages_dependencies: stage_dependencies.to_h)
16
20
  end
17
21
 
18
- class StageDependencies < Base
22
+ class StageDependencies < Directive::Base
19
23
  STAGES = [:install, :setup, :before_setup, :build_artifact].freeze
20
24
 
21
25
  STAGES.each do |stage|
22
26
  define_method(stage) do |*glob|
23
- if (globs = glob.map { |g| path_format(g) }).any? { |g| Pathname(g).absolute? }
24
- raise Error::Config, code: :stages_dependencies_paths_relative_path_required, data: { stage: stage }
27
+ sub_directive_eval do
28
+ if (globs = glob.map { |g| path_format(g) }).any? { |g| Pathname(g).absolute? }
29
+ raise Error::Config, code: :stages_dependencies_paths_relative_path_required, data: { stage: stage }
30
+ end
31
+ instance_variable_set(:"@#{stage}", globs)
25
32
  end
26
- instance_variable_set(:"@#{stage}", globs)
27
33
  end
28
34
 
29
35
  define_method("_#{stage}") do
@@ -36,7 +42,7 @@ module Dapp
36
42
  end
37
43
 
38
44
  def to_h
39
- STAGES.map { |stage| [stage, send("_#{stage}")] }.to_h
45
+ STAGES.map { |stage| [stage, public_send("_#{stage}")] }.to_h
40
46
  end
41
47
  end
42
48
  end
@@ -15,6 +15,14 @@ module Dapp
15
15
  super(**kwargs, &blk)
16
16
  end
17
17
 
18
+ def branch(value)
19
+ sub_directive_eval { @_branch = value }
20
+ end
21
+
22
+ def commit(value)
23
+ sub_directive_eval { @_commit = value }
24
+ end
25
+
18
26
  def _export
19
27
  super do |export|
20
28
  export._url = @_url
@@ -31,14 +39,12 @@ module Dapp
31
39
  super.merge(name: _name, branch: _branch, commit: _commit)
32
40
  end
33
41
 
34
- protected
35
-
36
42
  def branch(value)
37
- @_branch = value
43
+ sub_directive_eval { @_branch = value }
38
44
  end
39
45
 
40
46
  def commit(value)
41
- @_commit = value
47
+ sub_directive_eval { @_commit = value }
42
48
  end
43
49
 
44
50
  def validate!
@@ -46,16 +52,6 @@ module Dapp
46
52
  raise Error::Config, code: :git_artifact_remote_branch_with_commit if !_branch.nil? && !_commit.nil?
47
53
  end
48
54
  end
49
-
50
- protected
51
-
52
- def branch(value)
53
- @_branch = value
54
- end
55
-
56
- def commit(value)
57
- @_commit = value
58
- end
59
55
  end
60
56
  end
61
57
  end
@@ -3,7 +3,7 @@ module Dapp
3
3
  module Config
4
4
  module Directive
5
5
  class Mount < Base
6
- attr_reader :_from, :_to
6
+ attr_reader :_to
7
7
  attr_reader :_type
8
8
 
9
9
  def initialize(to, **kwargs, &blk)
@@ -13,12 +13,16 @@ module Dapp
13
13
  super(**kwargs, &blk)
14
14
  end
15
15
 
16
- protected
17
-
18
16
  def from(type)
19
- type = type.to_sym
20
- raise Error::Config, code: :mount_from_type_required unless [:tmp_dir, :build_dir].include? type
21
- @_type = type
17
+ sub_directive_eval do
18
+ type = type.to_sym
19
+ raise Error::Config, code: :mount_from_type_required unless [:tmp_dir, :build_dir].include? type
20
+ @_type = type
21
+ end
22
+ end
23
+
24
+ def validate!
25
+ raise Error::Config, code: :mount_from_required if _type.nil?
22
26
  end
23
27
  end
24
28
  end
@@ -8,13 +8,14 @@ module Dapp
8
8
  attr_reader :_before_install, :_before_setup, :_install, :_setup
9
9
 
10
10
  def version(value)
11
- @_version = value
11
+ sub_directive_eval { @_version = value }
12
12
  end
13
13
 
14
14
  def self.stage_command_generator(stage)
15
15
  define_method stage do |&blk|
16
- (variable = instance_variable_get("@_#{stage}") || StageCommand.new(dapp: dapp)).instance_eval(&blk)
17
- instance_variable_set("@_#{stage}", variable)
16
+ (instance_variable_get("@_#{stage}") || StageCommand.new(dapp: dapp)).tap do |variable|
17
+ instance_variable_set("@_#{stage}", directive_eval(variable, &blk))
18
+ end
18
19
  end
19
20
 
20
21
  define_method "_#{stage}_command" do
@@ -29,34 +30,31 @@ module Dapp
29
30
  end
30
31
  [:before_install, :before_setup, :install, :setup].each(&method(:stage_command_generator))
31
32
 
33
+ def empty?
34
+ (_before_install_command + _before_setup_command + _install_command + _setup_command).empty?
35
+ end
36
+
37
+ def clone_to_artifact
38
+ _clone_to Artifact.new(dapp: dapp)
39
+ end
40
+
32
41
  class StageCommand < Directive::Base
33
42
  attr_reader :_version
34
43
  attr_reader :_run
35
44
 
36
45
  def initialize(**kwargs, &blk)
37
46
  @_run = []
38
-
39
47
  super(**kwargs, &blk)
40
48
  end
41
49
 
42
50
  def run(*args)
43
- @_run.concat(args)
51
+ sub_directive_eval { @_run.concat(args) }
44
52
  end
45
53
 
46
54
  def version(value)
47
- @_version = value
55
+ sub_directive_eval { @_version = value }
48
56
  end
49
57
  end
50
-
51
- protected
52
-
53
- def empty?
54
- (_before_install_command + _before_setup_command + _install_command + _setup_command).empty?
55
- end
56
-
57
- def clone_to_artifact
58
- _clone_to Artifact.new(dapp: dapp)
59
- end
60
58
  end
61
59
  end
62
60
  end
@@ -79,7 +79,7 @@ module Dapp
79
79
  def image_exist?(image_id)
80
80
  shellout!(%(docker inspect #{image_id}))
81
81
  true
82
- rescue Error::Shellout
82
+ rescue ::Dapp::Error::Shellout
83
83
  false
84
84
  end
85
85
 
@@ -98,7 +98,7 @@ module Dapp
98
98
  begin
99
99
  image_name = format(format, repo: repo, signature: image.name.split(':').last)
100
100
  import_base!(image, image_name)
101
- rescue Error::Shellout
101
+ rescue ::Dapp::Error::Shellout
102
102
  next
103
103
  end
104
104
  break unless dapp.pull_all_stages?
@@ -6,6 +6,10 @@ module Dapp
6
6
  last_stage.send(:signature)
7
7
  end
8
8
 
9
+ def stage_by_name(name)
10
+ stages.find { |s| s.name == name }
11
+ end
12
+
9
13
  def stage_cache_format
10
14
  "#{dapp.stage_cache}:%{signature}"
11
15
  end
@@ -46,7 +50,7 @@ module Dapp
46
50
  end
47
51
 
48
52
  def stages
49
- (@stages ||= []).tap do |stages|
53
+ @stages ||= [].tap do |stages|
50
54
  stage = last_stage
51
55
  loop do
52
56
  stages << stage
@@ -52,13 +52,14 @@ module Dapp
52
52
  patch_command(stage.prev_g_a_stage.layer_commit(self), nil)
53
53
  end
54
54
 
55
- def stage_dependencies_checksums(stage)
55
+ def stage_dependencies_checksums(stage, from_commit = nil, to_commit = latest_commit)
56
56
  return [] if (stage_dependencies = stages_dependencies[stage.name]).empty?
57
57
 
58
58
  paths = include_paths(true) + base_paths(stage_dependencies, true)
59
- diff_patches(nil, latest_commit, paths: paths).map do |patch|
59
+ diff_patches(from_commit, to_commit, paths: paths).map do |patch|
60
60
  delta_new_file = patch.delta.new_file
61
- Digest::SHA256.hexdigest [delta_new_file[:path], repo.lookup_object(delta_new_file[:oid]).content].join(':::')
61
+ content = patch.hunks.map { |h| h.lines.select { |l| l.line_origin == :context }.map(&:content).join }.join
62
+ Digest::SHA256.hexdigest [delta_new_file[:path], content].join(':::')
62
63
  end
63
64
  end
64
65
 
@@ -122,10 +123,10 @@ module Dapp
122
123
  repo.dimg.dapp.sudo_command(owner: owner, group: group)
123
124
  end
124
125
 
125
- def archive_file(commit)
126
- create_file(repo.dimg.tmp_path('archives', archive_file_name(commit))) do |f|
126
+ def archive_file(to_commit)
127
+ create_file(repo.dimg.tmp_path('archives', archive_file_name(to_commit))) do |f|
127
128
  Gem::Package::TarWriter.new(f) do |tar|
128
- diff_patches(nil, commit).each do |patch|
129
+ diff_patches(nil, to_commit).each do |patch|
129
130
  entry = patch.delta.new_file
130
131
  tar.add_file slice_cwd(entry[:path]), entry[:mode] do |tf|
131
132
  tf.write repo.lookup_object(entry[:oid]).content
@@ -133,7 +134,7 @@ module Dapp
133
134
  end
134
135
  end
135
136
  end
136
- repo.dimg.container_tmp_path('archives', archive_file_name(commit))
137
+ repo.dimg.container_tmp_path('archives', archive_file_name(to_commit))
137
138
  rescue Gem::Package::TooLongFileName => e
138
139
  raise Error::TarWriter, message: e.message
139
140
  end
@@ -212,10 +213,7 @@ module Dapp
212
213
  end
213
214
 
214
215
  def diff_patches(from, to, paths: include_paths_or_cwd)
215
- (@diff_patches ||= {})[[from, to, paths]] = repo.patches(from, to,
216
- paths: paths,
217
- exclude_paths: exclude_paths(true),
218
- force_text: true)
216
+ (@diff_patches ||= {})[[from, to, paths]] = repo.patches(from, to, paths: paths, exclude_paths: exclude_paths(true))
219
217
  end
220
218
 
221
219
  def include_paths_or_cwd
@@ -228,7 +226,7 @@ module Dapp
228
226
  end
229
227
 
230
228
  def exclude_paths(with_cwd = false)
231
- base_paths(repo.exclude_paths + @exclude_paths, with_cwd)
229
+ repo.exclude_paths + base_paths(@exclude_paths, with_cwd)
232
230
  end
233
231
 
234
232
  def include_paths(with_cwd = false)
@@ -39,6 +39,8 @@ module Dapp
39
39
 
40
40
  def branch
41
41
  git.head.name.sub(/^refs\/heads\//, '')
42
+ rescue Rugged::ReferenceError => e
43
+ raise Error::Rugged, code: :git_repository_reference_error, data: { name: name, message: e.message.downcase }
42
44
  end
43
45
 
44
46
  def commit_at(commit)
@@ -18,7 +18,7 @@ module Dapp
18
18
 
19
19
  def diff(from, to, **kwargs)
20
20
  if to.nil?
21
- git.lookup(from).diff_workdir
21
+ git.lookup(from).diff_workdir(**kwargs)
22
22
  else
23
23
  super
24
24
  end
@@ -106,6 +106,7 @@ module Dapp
106
106
  .lines
107
107
  .each do |l|
108
108
  name, id, created_at, size_field = l.split(';')
109
+ name = name.reverse.chomp('docker.io/'.reverse).reverse
109
110
  size = begin
110
111
  number, unit = size_field.split
111
112
  coef = case unit.to_s.downcase