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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 07ca14f07b8e2971cc7bdbb6777171d187814a5a
4
- data.tar.gz: 2d24f78202c74b7da5e94ff052b841ef2efa09db
3
+ metadata.gz: 6ad43a1b900c01b03836a4856a0ea69070bec9a7
4
+ data.tar.gz: 6b178ca3754198f17e378b3b1ff489bc893e7b41
5
5
  SHA512:
6
- metadata.gz: 6602da6be978f09efd3eead028827fe0d5cd7ab24af73e9fc92d263ff559c70e46876ab086b4d54f6e23813fd5b836ad1f14dd53bde4a21a90d4f54f30795a43
7
- data.tar.gz: 4b18317cefa95594d33aff7c7ff2812c93fde137648bd67de046a35b611fd915cebe1955ae287179238ef585f500b9e5c7dae205d4729fafebe25a0329f70668
6
+ metadata.gz: 90cbe4a4cbced7f1bc8a5c0140227693740c940b8192664ec1bb85c0220946955402d638d6ea549eab0bdc4f8e19bdeda4058fb94deae3648f91a895c0fe4360
7
+ data.tar.gz: ccd71154c84ba441339fdfd078edfae8ba2ef41f846017c0a764e2df88f2badcf388d7db1394f5dc666e7ba30665d8fe07bbb400793fe82ecd51e189763187f9
data/bin/dapp CHANGED
@@ -20,7 +20,15 @@ begin
20
20
  check_docker_version
21
21
 
22
22
  begin
23
- Dapp::CLI.new.run
23
+ begin
24
+ Dapp::CLI.new.run
25
+ rescue Dapp::Error::Base => e
26
+ unless (message = Dapp::Helper::NetStatus.before_error_message(e)).empty?
27
+ $stderr.puts(message)
28
+ end
29
+
30
+ raise
31
+ end
24
32
  rescue ::SystemExit
25
33
  raise
26
34
  rescue ::Exception => e
@@ -8,7 +8,6 @@ en:
8
8
  dimg_not_run: "Dimg run failed!"
9
9
  git_branch_without_name: "Dimg has specific revision that isn't associated with a branch name!"
10
10
  ci_environment_required: 'CI environment required (Travis or GitLab CI)!'
11
- chef_stage_checksum_not_calculated: "Chef stage `%{stage}` checksum is not calculated yet, run build first"
12
11
  dappfile:
13
12
  incorrect: "Dappfile with `%{error}`:\n%{message}"
14
13
  build:
@@ -34,7 +33,9 @@ en:
34
33
  config:
35
34
  dimg_name_required: 'Dimg name required!'
36
35
  dimg_name_incorrect: "Dimg has incorrect name `%{name}`: doesn't match regex `%{reg}`!"
36
+ mount_from_required: "Mount: `from` directive required!"
37
37
  export_to_required: "Export: `to` directive required!"
38
+ add_to_required: "Add: `to` directive required!"
38
39
  export_cwd_absolute_path_required: "Export: given cwd path must be absolute!"
39
40
  export_to_absolute_path_required: "Export: given `to` path must be absolute!"
40
41
  export_include_paths_relative_path_required: "Export: given `include_paths` path must be relative!"
@@ -45,7 +46,7 @@ en:
45
46
  builder_type_conflict: 'Conflict between builder types!'
46
47
  builder_type_unsupported: "Defined unsupported builder type `%{type}`!"
47
48
  docker_from_incorrect: "`docker.from` has incorrect value `%{name}`!"
48
- docker_from_without_tag: "`docker.from`: image `%{name}` without !"
49
+ docker_from_without_tag: "`docker.from`: image `%{name}` without tag!"
49
50
  stage_artifact_not_associated: "Artifact not associated with any stage: expected `before` or `after` attribute!"
50
51
  stage_artifact_double_associate: "Cannot use `%{stage}` stage for artifact, already used in `%{conflict_stage}` stage!"
51
52
  stage_artifact_not_supported_associated_stage: "Bad artifact stage `%{stage}`!"
@@ -57,6 +58,7 @@ en:
57
58
  scratch_artifact_associated: "Scratch artifact cannot be associated: not expected `before`/`after` attribute!"
58
59
  scratch_artifact_docker_from: "Scratch artifact must have directive `docker.from`!"
59
60
  chef:
61
+ stage_checksum_not_calculated: "Chef stage `%{stage}` checksum is not calculated yet, run build first"
60
62
  stage_path_overlap: "Cannot install `%{cookbook}` cookbook's path %{from} into %{to}: already exists"
61
63
  builder_cookbook_not_found: "Dapp cookbook directory not found at %{path}"
62
64
  berksfile_absolute_path_forbidden: "Absolute paths in Berksfile are not allowed (cookbook `%{cookbook}`, path: `%{path}`)"
@@ -66,6 +68,7 @@ en:
66
68
  page_not_found: "Registry `%{registry}`: page `%{url}` not found!"
67
69
  user_not_authorized: 'Registry `%{registry}`: user not authorized!'
68
70
  rugged:
71
+ git_repository_reference_error: "Git repo `%{name}`: %{message}!"
69
72
  rugged_remote_error: "Remote git repo `%{url}`: `%{message}`!"
70
73
  local_git_repository_does_not_exist: "Local git repo: doesn't exist!"
71
74
  commit_not_found_in_local_git_repository: "Local git repo: commit `%{commit}` not found!\nIf commit has been rebased: run command `dapp dimg stages cleanup local --improper-git-commit`!"
@@ -17,6 +17,7 @@ require 'paint'
17
17
  require 'inifile'
18
18
  require 'rugged'
19
19
  require 'rubygems/package'
20
+ require 'murmurhash3'
20
21
 
21
22
  require 'net_status'
22
23
 
@@ -63,6 +64,7 @@ require 'dapp/dimg/builder/shell'
63
64
  require 'dapp/dimg/builder/none'
64
65
  require 'dapp/dimg/build/stage/mod/logging'
65
66
  require 'dapp/dimg/build/stage/mod/group'
67
+ require 'dapp/dimg/build/stage/mod/git_artifact_dependencies'
66
68
  require 'dapp/dimg/build/stage/base'
67
69
  require 'dapp/dimg/build/stage/ga_base'
68
70
  require 'dapp/dimg/build/stage/ga_dependencies_base'
@@ -170,7 +172,6 @@ require 'dapp/dimg/error/tar_writer'
170
172
  require 'dapp/dimg/error/rugged'
171
173
  require 'dapp/dimg/error/registry'
172
174
  require 'dapp/dimg/error/chef'
173
- require 'dapp/dimg/error/shellout'
174
175
  require 'dapp/dimg/error/lock'
175
176
  require 'dapp/dimg/error/config'
176
177
  require 'dapp/dimg/error/command'
@@ -10,6 +10,11 @@ module Dapp
10
10
 
11
11
  attr_reader :dapp
12
12
 
13
+ def directive_eval(directive, &blk)
14
+ directive.instance_eval(&blk) if block_given?
15
+ directive
16
+ end
17
+
13
18
  def ref_variables
14
19
  [:@dapp]
15
20
  end
@@ -2,14 +2,15 @@ module Dapp
2
2
  module Config
3
3
  module Directive
4
4
  class Base < Config::Base
5
- protected
6
-
7
5
  def clone
8
6
  _clone
9
7
  end
10
8
 
11
- def clone_to_artifact
12
- clone
9
+ protected
10
+
11
+ def sub_directive_eval
12
+ yield if block_given?
13
+ self
13
14
  end
14
15
 
15
16
  def path_format(path)
@@ -78,7 +78,7 @@ module Dapp
78
78
 
79
79
  def local_git_artifact_exclude_paths(&blk)
80
80
  super do |exclude_paths|
81
- build_path_relpath = Pathname.new(build_path).subpath_of(path)
81
+ build_path_relpath = Pathname.new(build_path).subpath_of(File.dirname(git_path))
82
82
  exclude_paths << build_path_relpath.to_s if build_path_relpath
83
83
 
84
84
  yield exclude_paths if block_given?
@@ -2,7 +2,7 @@ module Dapp
2
2
  class Dapp
3
3
  module Deps
4
4
  module Base
5
- BASE_VERSION = '0.1.14'.freeze
5
+ BASE_VERSION = '0.1.15'.freeze
6
6
 
7
7
  def base_container_name # FIXME: hashsum(image) or dockersafe()
8
8
  "dappdeps_base_#{BASE_VERSION}"
@@ -24,7 +24,7 @@ module Dapp
24
24
  end
25
25
 
26
26
  %w(rm rsync diff date cat
27
- stat sleep mkdir find
27
+ stat test sleep mkdir find
28
28
  install sed cp true
29
29
  bash tar sudo).each do |cmd|
30
30
  define_method("#{cmd}_bin") { "/.dapp/deps/base/#{BASE_VERSION}/bin/#{cmd}" }
@@ -13,7 +13,7 @@ module Dapp
13
13
 
14
14
  def self.initialize(mode)
15
15
  ::Paint.mode = case mode
16
- when 'auto' then STDOUT.tty? ? 8 : 0
16
+ when 'auto' then (ENV['TRAVIS'] || ENV['GITLAB_CI'] || STDOUT.tty?) ? 8 : 0
17
17
  when 'on' then 8
18
18
  when 'off' then 0
19
19
  else raise
@@ -2,6 +2,7 @@ module Dapp
2
2
  class Dapp
3
3
  module Logging
4
4
  module Process
5
+ DEFAULT_TERMINAL_WIDTH = 120
5
6
  DEFAULT_STYLE = {
6
7
  message: :step,
7
8
  process: :secondary,
@@ -25,8 +26,6 @@ module Dapp
25
26
 
26
27
  # rubocop:disable Metrics/ParameterLists
27
28
  def log_process(message, process: nil, short: false, quiet: false, style: {}, status: {}, &blk)
28
- return yield if quiet
29
-
30
29
  style[:message] ||= DEFAULT_STYLE[:message]
31
30
  style[:process] ||= DEFAULT_STYLE[:process]
32
31
  style[:failed] ||= DEFAULT_STYLE[:failed]
@@ -35,7 +34,9 @@ module Dapp
35
34
  status[:success] ||= t(code: 'status.success.default')
36
35
  status[:failed] ||= t(code: 'status.failed.default')
37
36
 
38
- if log_verbose? && !short
37
+ if quiet
38
+ log_process_quiet(message.to_s, style: style, status: status, &blk)
39
+ elsif log_verbose? && !short
39
40
  process ||= t(code: 'status.process.default')
40
41
  log_process_verbose(message.to_s, process: process, style: style, status: status, &blk)
41
42
  else
@@ -50,6 +51,15 @@ module Dapp
50
51
 
51
52
  protected
52
53
 
54
+ def log_process_quiet(message, style: {}, status: {})
55
+ yield
56
+ rescue Error::Base => e
57
+ info = paint_string(slice(message), style[:message])
58
+ failed_message = paint_string(rjust(status[:failed], info), style[:failed])
59
+ before_error_messages = [log_indent + info + failed_message, e.net_status[:data][:before_error_messages]].flatten
60
+ raise e.class, **e.net_status.merge(data: e.net_status[:data].merge(before_error_messages: before_error_messages))
61
+ end
62
+
53
63
  def log_process_verbose(message, process:, style: {}, status: {}, &blk)
54
64
  process = paint_string(rjust(process, message), style[:process])
55
65
  info = paint_string(message, style[:message]) + process
@@ -71,7 +81,7 @@ module Dapp
71
81
  message = success_message
72
82
  start = Time.now
73
83
  yield
74
- rescue Exception::Base, Error::Base, SignalException, StandardError => _e
84
+ rescue Error::Base, SignalException, StandardError => _e
75
85
  message = failed_message
76
86
  raise
77
87
  ensure
@@ -100,7 +110,10 @@ module Dapp
100
110
  end
101
111
 
102
112
  def terminal_width
103
- @terminal_width ||= `tput cols`.strip.to_i
113
+ @terminal_width ||= begin
114
+ tputs_cols = `tput cols`.strip.to_i
115
+ (tputs_cols == 0) ? DEFAULT_TERMINAL_WIDTH : tputs_cols
116
+ end
104
117
  end
105
118
  end
106
119
  end # Logging
@@ -22,14 +22,14 @@ module Dapp
22
22
  return yield if dimg.dapp.dry_run?
23
23
 
24
24
  try_lock = proc do
25
- next yield unless should_be_tagged?
25
+ next yield unless image_should_be_locked?
26
26
 
27
27
  no_lock = false
28
28
 
29
29
  dimg.dapp.lock("#{dimg.dapp.name}.image.#{image.name}") do
30
30
  image.cache_reset
31
31
 
32
- if should_be_tagged?
32
+ if image_should_be_locked?
33
33
  yield
34
34
  else
35
35
  no_lock = true
@@ -52,7 +52,7 @@ module Dapp
52
52
  return if build_should_be_skipped?
53
53
  prev_stage.build! if prev_stage
54
54
  if image_should_be_build?
55
- prepare_image if !image.built? && !should_be_not_present?
55
+ prepare_image if !image.built? && !should_be_not_present? || should_be_introspected?
56
56
  log_image_build(&method(:image_build))
57
57
  end
58
58
  dimg.introspect_image!(image: image.built_id, options: image.send(:prepared_options)) if should_be_introspected?
@@ -156,7 +156,19 @@ module Dapp
156
156
  end
157
157
 
158
158
  def git_artifacts_dependencies
159
- dimg.git_artifacts.map { |git_artifact| git_artifact.stage_dependencies_checksums(self) }
159
+ local_git_artifacts_dependencies + remote_git_artifacts_dependencies
160
+ end
161
+
162
+ def local_git_artifacts_dependencies
163
+ default_git_artifacts_dependencies(dimg.local_git_artifacts)
164
+ end
165
+
166
+ def remote_git_artifacts_dependencies
167
+ default_git_artifacts_dependencies(dimg.remote_git_artifacts)
168
+ end
169
+
170
+ def default_git_artifacts_dependencies(git_artifacts)
171
+ git_artifacts.map { |git_artifact| git_artifact.stage_dependencies_checksums(self) }
160
172
  end
161
173
 
162
174
  def dependencies
@@ -167,6 +179,24 @@ module Dapp
167
179
  false
168
180
  end
169
181
 
182
+ def g_a_stage?
183
+ false
184
+ end
185
+
186
+ def prev_g_a_stage
187
+ stage = self
188
+ until (stage = stage.prev_stage).nil?
189
+ return stage if stage.g_a_stage?
190
+ end
191
+ end
192
+
193
+ def next_g_a_stage
194
+ stage = self
195
+ until (stage = stage.next_stage).nil?
196
+ return stage if stage.g_a_stage?
197
+ end
198
+ end
199
+
170
200
  protected
171
201
 
172
202
  def image_build
@@ -178,7 +208,11 @@ module Dapp
178
208
  end
179
209
 
180
210
  def should_be_tagged?
181
- !(empty? || image.tagged? || should_be_not_present?) && image.built?
211
+ image.built? && !image.tagged?
212
+ end
213
+
214
+ def image_should_be_locked?
215
+ !(empty? || image.tagged? || should_be_not_present?)
182
216
  end
183
217
 
184
218
  def should_be_not_present?
@@ -3,6 +3,8 @@ module Dapp
3
3
  module Build
4
4
  module Stage
5
5
  class BeforeSetup < Base
6
+ include Mod::GitArtifactsDependencies
7
+
6
8
  def initialize(dimg, next_stage)
7
9
  @prev_stage = AfterInstallArtifact.new(dimg, self)
8
10
  super
@@ -3,6 +3,8 @@ module Dapp
3
3
  module Build
4
4
  module Stage
5
5
  class BuildArtifact < Base
6
+ include Mod::GitArtifactsDependencies
7
+
6
8
  def initialize(dimg)
7
9
  @prev_stage = GAArtifactPatch.new(dimg, self)
8
10
  @dimg = dimg
@@ -26,8 +26,8 @@ module Dapp
26
26
  [:tmp_dir, :build_dir].map { |type| config_mounts_by_type(type) }.flatten.uniq
27
27
  end
28
28
 
29
- def adding_mounts_by_type(type)
30
- labels_mounts_by_type(type)
29
+ def adding_mounts_by_type(_type)
30
+ []
31
31
  end
32
32
 
33
33
  def should_not_be_detailed?
@@ -8,14 +8,6 @@ module Dapp
8
8
  super
9
9
  end
10
10
 
11
- def prev_g_a_stage
12
- nil
13
- end
14
-
15
- def next_g_a_stage
16
- next_stage.next_stage # GAPreInstallPatch
17
- end
18
-
19
11
  protected
20
12
 
21
13
  def apply_command_method
@@ -9,11 +9,7 @@ module Dapp
9
9
  end
10
10
 
11
11
  def dependencies
12
- next_stage.context # BuildArtifact
13
- end
14
-
15
- def prev_g_a_stage
16
- super.prev_stage # GAPreSetupPatch
12
+ dimg.stage_by_name(:build_artifact).context
17
13
  end
18
14
  end # GAArtifactPatch
19
15
  end # Stage
@@ -3,16 +3,6 @@ module Dapp
3
3
  module Build
4
4
  module Stage
5
5
  class GABase < Base
6
- attr_accessor :prev_g_a_stage, :next_g_a_stage
7
-
8
- def prev_g_a_stage
9
- dependencies_stage.prev_stage.prev_stage
10
- end
11
-
12
- def next_g_a_stage
13
- next_stage.next_stage.next_stage
14
- end
15
-
16
6
  def dependencies_stage
17
7
  prev_stage
18
8
  end
@@ -44,6 +34,10 @@ module Dapp
44
34
  dependencies_stage.empty?
45
35
  end
46
36
 
37
+ def g_a_stage?
38
+ true
39
+ end
40
+
47
41
  def layer_commit(git_artifact)
48
42
  commits[git_artifact] ||= begin
49
43
  if dependencies_stage && dependencies_stage.image.tagged?
@@ -8,14 +8,6 @@ module Dapp
8
8
  super
9
9
  end
10
10
 
11
- def prev_g_a_stage
12
- prev_stage.prev_stage
13
- end
14
-
15
- def next_g_a_stage
16
- nil
17
- end
18
-
19
11
  def dependencies_stage
20
12
  nil
21
13
  end
@@ -10,10 +10,6 @@ module Dapp
10
10
  @prev_stage = GAPostInstallPatchDependencies.new(dimg, self)
11
11
  super
12
12
  end
13
-
14
- def next_g_a_stage
15
- super.next_stage.next_stage # GAPreSetupPatch
16
- end
17
13
  end # GAPostInstallPatch
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.next_stage.context # BeforeSetup
15
+ dimg.stage_by_name(:before_setup).context
16
16
  end
17
17
  end # GAPostInstallPatchDependencies
18
18
  end
@@ -10,10 +10,6 @@ module Dapp
10
10
  @prev_stage = GAPreInstallPatchDependencies.new(dimg, self)
11
11
  super
12
12
  end
13
-
14
- def prev_g_a_stage
15
- dependencies_stage.prev_stage # GAArchive
16
- end
17
13
  end # GAPostInstallPatch
18
14
  end
19
15
  end # Stage