dapp 0.5.13 → 0.6.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 (116) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dapp +3 -0
  3. data/config/en/common.yml +35 -6
  4. data/config/en/net_status.yml +20 -6
  5. data/lib/dapp.rb +53 -27
  6. data/lib/dapp/application.rb +48 -27
  7. data/lib/dapp/application/git_artifact.rb +1 -1
  8. data/lib/dapp/application/path.rb +2 -18
  9. data/lib/dapp/application/tags.rb +5 -5
  10. data/lib/dapp/build/stage/artifact.rb +8 -3
  11. data/lib/dapp/build/stage/base.rb +43 -30
  12. data/lib/dapp/build/stage/{infra_install.rb → before_install.rb} +6 -6
  13. data/lib/dapp/build/stage/before_setup.rb +27 -0
  14. data/lib/dapp/build/stage/docker_instructions.rb +12 -1
  15. data/lib/dapp/build/stage/from.rb +4 -3
  16. data/lib/dapp/build/stage/{source_1_archive.rb → ga_archive.rb} +7 -7
  17. data/lib/dapp/build/stage/{source_1_archive_dependencies.rb → ga_archive_dependencies.rb} +4 -4
  18. data/lib/dapp/build/stage/{source_base.rb → ga_base.rb} +31 -7
  19. data/lib/dapp/build/stage/{source_dependencies_base.rb → ga_dependencies_base.rb} +5 -6
  20. data/lib/dapp/build/stage/{source_5.rb → ga_latest_patch.rb} +6 -6
  21. data/lib/dapp/build/stage/install/ga_post_install_patch.rb +21 -0
  22. data/lib/dapp/build/stage/install/ga_post_install_patch_dependencies.rb +21 -0
  23. data/lib/dapp/build/stage/install/ga_pre_install_patch.rb +21 -0
  24. data/lib/dapp/build/stage/install/ga_pre_install_patch_dependencies.rb +31 -0
  25. data/lib/dapp/build/stage/install/install.rb +31 -0
  26. data/lib/dapp/build/stage/mod/artifact.rb +9 -19
  27. data/lib/dapp/build/stage/mod/group.rb +42 -0
  28. data/lib/dapp/build/stage/mod/logging.rb +62 -26
  29. data/lib/dapp/build/stage/setup/chef_cookbooks.rb +37 -0
  30. data/lib/dapp/build/stage/setup/ga_post_setup_patch.rb +25 -0
  31. data/lib/dapp/build/stage/setup/ga_post_setup_patch_dependencies.rb +31 -0
  32. data/lib/dapp/build/stage/setup/ga_pre_setup_patch.rb +25 -0
  33. data/lib/dapp/build/stage/setup/ga_pre_setup_patch_dependencies.rb +27 -0
  34. data/lib/dapp/build/stage/setup/setup.rb +31 -0
  35. data/lib/dapp/builder/base.rb +9 -6
  36. data/lib/dapp/builder/chef.rb +128 -107
  37. data/lib/dapp/builder/chef/berksfile.rb +3 -0
  38. data/lib/dapp/builder/shell.rb +4 -3
  39. data/lib/dapp/cli.rb +8 -6
  40. data/lib/dapp/cli/base.rb +6 -1
  41. data/lib/dapp/cli/bp.rb +41 -0
  42. data/lib/dapp/cli/build.rb +17 -4
  43. data/lib/dapp/cli/cleanup.rb +24 -0
  44. data/lib/dapp/cli/list.rb +2 -2
  45. data/lib/dapp/cli/push.rb +8 -9
  46. data/lib/dapp/cli/run.rb +3 -4
  47. data/lib/dapp/cli/spush.rb +20 -0
  48. data/lib/dapp/cli/stages.rb +2 -0
  49. data/lib/dapp/cli/stages/cleanup.rb +7 -3
  50. data/lib/dapp/cli/stages/flush.rb +6 -3
  51. data/lib/dapp/config/application.rb +17 -11
  52. data/lib/dapp/config/chef.rb +4 -0
  53. data/lib/dapp/config/docker.rb +3 -2
  54. data/lib/dapp/config/git_artifact.rb +1 -2
  55. data/lib/dapp/config/main.rb +5 -2
  56. data/lib/dapp/config/shell.rb +20 -16
  57. data/lib/dapp/docker_registry.rb +32 -0
  58. data/lib/dapp/docker_registry/base.rb +47 -0
  59. data/lib/dapp/docker_registry/default.rb +18 -0
  60. data/lib/dapp/docker_registry/mod/authorization.rb +62 -0
  61. data/lib/dapp/docker_registry/mod/request.rb +44 -0
  62. data/lib/dapp/error/image.rb +6 -0
  63. data/lib/dapp/error/project.rb +6 -0
  64. data/lib/dapp/error/registry.rb +6 -0
  65. data/lib/dapp/exception/registry.rb +6 -0
  66. data/lib/dapp/git_artifact.rb +6 -7
  67. data/lib/dapp/git_repo/base.rb +1 -1
  68. data/lib/dapp/git_repo/remote.rb +6 -38
  69. data/lib/dapp/helper/sha256.rb +3 -3
  70. data/lib/dapp/helper/shellout.rb +25 -7
  71. data/lib/dapp/helper/streaming.rb +1 -3
  72. data/lib/dapp/image/argument.rb +31 -18
  73. data/lib/dapp/image/docker.rb +15 -8
  74. data/lib/dapp/image/stage.rb +10 -12
  75. data/lib/dapp/lock/base.rb +44 -0
  76. data/lib/dapp/lock/error.rb +14 -0
  77. data/lib/dapp/lock/file.rb +33 -0
  78. data/lib/dapp/prctl.rb +22 -0
  79. data/lib/dapp/project.rb +75 -0
  80. data/lib/dapp/project/command/bp.rb +24 -0
  81. data/lib/dapp/project/command/build.rb +21 -0
  82. data/lib/dapp/project/command/cleanup.rb +24 -0
  83. data/lib/dapp/project/command/common.rb +51 -0
  84. data/lib/dapp/project/command/list.rb +14 -0
  85. data/lib/dapp/project/command/push.rb +21 -0
  86. data/lib/dapp/project/command/run.rb +15 -0
  87. data/lib/dapp/project/command/spush.rb +17 -0
  88. data/lib/dapp/project/command/stages_cleanup.rb +70 -0
  89. data/lib/dapp/project/command/stages_flush.rb +18 -0
  90. data/lib/dapp/project/dappfile.rb +70 -0
  91. data/lib/dapp/project/lock.rb +27 -0
  92. data/lib/dapp/project/logging/base.rb +107 -0
  93. data/lib/dapp/project/logging/process.rb +104 -0
  94. data/lib/dapp/project/paint.rb +16 -0
  95. data/lib/dapp/project/ssh_agent.rb +77 -0
  96. data/lib/dapp/version.rb +1 -1
  97. metadata +74 -27
  98. data/lib/dapp/application/deps/gitartifact.rb +0 -39
  99. data/lib/dapp/application/logging.rb +0 -120
  100. data/lib/dapp/application/system_shellout.rb +0 -63
  101. data/lib/dapp/build/stage/chef_cookbooks.rb +0 -33
  102. data/lib/dapp/build/stage/infra_setup.rb +0 -27
  103. data/lib/dapp/build/stage/install.rb +0 -27
  104. data/lib/dapp/build/stage/setup.rb +0 -27
  105. data/lib/dapp/build/stage/source_1.rb +0 -21
  106. data/lib/dapp/build/stage/source_1_dependencies.rb +0 -27
  107. data/lib/dapp/build/stage/source_2.rb +0 -17
  108. data/lib/dapp/build/stage/source_2_dependencies.rb +0 -17
  109. data/lib/dapp/build/stage/source_3.rb +0 -17
  110. data/lib/dapp/build/stage/source_3_dependencies.rb +0 -23
  111. data/lib/dapp/build/stage/source_4.rb +0 -21
  112. data/lib/dapp/build/stage/source_4_dependencies.rb +0 -27
  113. data/lib/dapp/cli/smartpush.rb +0 -19
  114. data/lib/dapp/controller.rb +0 -119
  115. data/lib/dapp/error/controller.rb +0 -6
  116. data/lib/dapp/helper/log.rb +0 -73
@@ -6,7 +6,7 @@ module Dapp
6
6
  include Mod::Artifact
7
7
 
8
8
  def initialize(application, next_stage)
9
- @prev_stage = Install.new(application, self)
9
+ @prev_stage = InstallGroup::GAPostInstallPatch.new(application, self)
10
10
  super
11
11
  end
12
12
 
@@ -16,13 +16,18 @@ module Dapp
16
16
 
17
17
  def image
18
18
  super do |image|
19
- artifacts.each { |artifact| apply_artifact(artifact, image) }
19
+ artifacts_labels = {}
20
+ artifacts.each do |artifact|
21
+ apply_artifact(artifact, image)
22
+ artifacts_labels["dapp-artifact-#{artifact[:name]}".to_sym] = artifact[:app].send(:last_stage).image.built_id
23
+ end
24
+ image.add_service_change_label artifacts_labels
20
25
  end
21
26
  end
22
27
 
23
28
  protected
24
29
 
25
- def should_be_not_detailed?
30
+ def should_not_be_detailed?
26
31
  true
27
32
  end
28
33
 
@@ -17,17 +17,46 @@ module Dapp
17
17
  @next_stage.prev_stage = self
18
18
  end
19
19
 
20
+ def build_lock!
21
+ return yield if application.project.dry_run?
22
+
23
+ try_lock = lambda do
24
+ next yield unless should_be_tagged?
25
+
26
+ no_lock = false
27
+
28
+ application.project.lock("#{application.config._basename}.image.#{image.name}") do
29
+ image.cache_reset
30
+
31
+ if should_be_tagged?
32
+ yield
33
+ else
34
+ no_lock = true
35
+ end
36
+ end
37
+
38
+ yield if no_lock
39
+ end
40
+
41
+ if prev_stage
42
+ prev_stage.build_lock! { try_lock.call }
43
+ else
44
+ try_lock.call
45
+ end
46
+ end
47
+
20
48
  def build!
21
49
  return if should_be_skipped?
22
50
  prev_stage.build! if prev_stage
23
- image_build unless empty? && !application.log_verbose?
51
+ log_image_build(&method(:image_build)) if image_should_be_build?
24
52
  raise Exception::IntrospectImage, data: { built_id: image.built_id, options: image.send(:prepared_options) } if should_be_introspected?
25
53
  end
26
54
 
27
55
  def save_in_cache!
28
56
  prev_stage.save_in_cache! if prev_stage
29
57
  return unless should_be_tagged?
30
- image.tag!(log_verbose: application.log_verbose?, log_time: application.log_time?) unless application.dry_run?
58
+ image.tag!(log_verbose: application.project.log_verbose?,
59
+ log_time: application.project.log_time?) unless application.project.dry_run?
31
60
  end
32
61
 
33
62
  def image
@@ -35,14 +64,18 @@ module Dapp
35
64
  if empty?
36
65
  prev_stage.image
37
66
  else
38
- Image::Stage.new(name: image_name, from: from_image).tap do |image|
39
- image.add_change_label dapp: application.config._basename
67
+ Image::Stage.new(name: image_name, from: from_image, project: application.project).tap do |image|
68
+ image.add_service_change_label dapp: application.stage_dapp_label
40
69
  yield image if block_given?
41
70
  end
42
71
  end
43
72
  end
44
73
  end
45
74
 
75
+ def image_should_be_build?
76
+ !empty? || application.project.log_verbose?
77
+ end
78
+
46
79
  def empty?
47
80
  dependencies_empty?
48
81
  end
@@ -65,35 +98,15 @@ module Dapp
65
98
 
66
99
  protected
67
100
 
68
- # rubocop:disable Metrics/AbcSize
69
101
  def image_build
70
- if empty?
71
- application.log_state(name, state: application.t(code: 'state.empty'))
72
- elsif image.tagged?
73
- application.log_state(name, state: application.t(code: 'state.using_cache'))
74
- elsif should_be_not_present?
75
- application.log_state(name, state: application.t(code: 'state.not_present'))
76
- elsif application.dry_run?
77
- application.log_state(name, state: application.t(code: 'state.build'), styles: { status: :success })
78
- else
79
- application.log_process(name, process: application.t(code: 'status.process.building'), short: should_not_be_detailed?) do
80
- image_do_build
81
- end
82
- end
83
- ensure
84
- log_build
85
- end
86
- # rubocop:enable Metrics/AbcSize
87
-
88
- def image_do_build
89
- image.build!(log_verbose: application.log_verbose?,
90
- log_time: application.log_time?,
91
- introspect_error: application.cli_options[:introspect_error],
92
- introspect_before_error: application.cli_options[:introspect_before_error])
102
+ image.build!(log_verbose: application.project.log_verbose?,
103
+ log_time: application.project.log_time?,
104
+ introspect_error: application.project.cli_options[:introspect_error],
105
+ introspect_before_error: application.project.cli_options[:introspect_before_error])
93
106
  end
94
107
 
95
108
  def should_be_tagged?
96
- !(image.tagged? || empty? || should_be_not_present?)
109
+ !(empty? || image.tagged? || should_be_not_present?)
97
110
  end
98
111
 
99
112
  def should_be_not_present?
@@ -102,7 +115,7 @@ module Dapp
102
115
  end
103
116
 
104
117
  def image_name
105
- "#{application.config._basename}-dappstage:#{signature}"
118
+ application.stage_cache_format % { signature: signature }
106
119
  end
107
120
 
108
121
  def from_image
@@ -1,27 +1,27 @@
1
1
  module Dapp
2
2
  module Build
3
3
  module Stage
4
- # InfraInstall
5
- class InfraInstall < Base
4
+ # BeforeInstall
5
+ class BeforeInstall < Base
6
6
  def initialize(application, next_stage)
7
7
  @prev_stage = From.new(application, self)
8
8
  super
9
9
  end
10
10
 
11
11
  def empty?
12
- super && !application.builder.infra_install?
12
+ super && !application.builder.before_install?
13
13
  end
14
14
 
15
15
  def dependencies
16
- [application.builder.infra_install_checksum]
16
+ [application.builder.before_install_checksum]
17
17
  end
18
18
 
19
19
  def image
20
20
  super do |image|
21
- application.builder.infra_install(image)
21
+ application.builder.before_install(image)
22
22
  end
23
23
  end
24
- end # InfraInstall
24
+ end # BeforeInstall
25
25
  end # Stage
26
26
  end # Build
27
27
  end # Dapp
@@ -0,0 +1,27 @@
1
+ module Dapp
2
+ module Build
3
+ module Stage
4
+ # BeforeSetup
5
+ class BeforeSetup < Base
6
+ def initialize(application, next_stage)
7
+ @prev_stage = Artifact.new(application, self)
8
+ super
9
+ end
10
+
11
+ def empty?
12
+ super && !application.builder.before_setup?
13
+ end
14
+
15
+ def dependencies
16
+ prev_stage.prev_stage.prev_stage.dependencies # GAPostInstallPatchDependencies
17
+ end
18
+
19
+ def image
20
+ super do |image|
21
+ application.builder.before_setup(image)
22
+ end
23
+ end
24
+ end # BeforeSetup
25
+ end # Stage
26
+ end # Build
27
+ end # Dapp
@@ -4,7 +4,7 @@ module Dapp
4
4
  # DockerInstructions
5
5
  class DockerInstructions < Base
6
6
  def initialize(application)
7
- @prev_stage = Source5.new(application, self)
7
+ @prev_stage = GALatestPatch.new(application, self)
8
8
  @application = application
9
9
  end
10
10
 
@@ -20,6 +20,17 @@ module Dapp
20
20
  end
21
21
  end
22
22
 
23
+ def log_image_details
24
+ super
25
+ log_image_instructions
26
+ end
27
+
28
+ def log_image_instructions
29
+ return if (instructions = image.prepare_instructions(image.send(:change_options))).empty?
30
+ application.project.log_info application.project.t(code: 'image.instructions')
31
+ application.project.with_log_indent { application.project.log_info instructions.join("\n") }
32
+ end
33
+
23
34
  private
24
35
 
25
36
  def change_options
@@ -18,8 +18,9 @@ module Dapp
18
18
 
19
19
  protected
20
20
 
21
- def image_do_build
22
- from_image.pull!(log_time: application.log_time?)
21
+ def image_build
22
+ from_image.pull!(log_time: application.project.log_time?)
23
+ raise Error::Build, code: :from_image_not_found, data: { name: from_image_name } if from_image.built_id.nil?
23
24
  super
24
25
  end
25
26
 
@@ -30,7 +31,7 @@ module Dapp
30
31
  end
31
32
 
32
33
  def from_image
33
- @from_image ||= Image::Stage.new(name: from_image_name)
34
+ @from_image ||= Image::Stage.new(name: from_image_name, project: application.project)
34
35
  end
35
36
  end # Prepare
36
37
  end # Stage
@@ -1,19 +1,19 @@
1
1
  module Dapp
2
2
  module Build
3
3
  module Stage
4
- # Source1Archive
5
- class Source1Archive < SourceBase
4
+ # GAArchive
5
+ class GAArchive < GABase
6
6
  def initialize(application, next_stage)
7
- @prev_stage = Source1ArchiveDependencies.new(application, self)
7
+ @prev_stage = GAArchiveDependencies.new(application, self)
8
8
  super
9
9
  end
10
10
 
11
- def prev_source_stage
11
+ def prev_g_a_stage
12
12
  nil
13
13
  end
14
14
 
15
- def next_source_stage
16
- next_stage.next_stage
15
+ def next_g_a_stage
16
+ next_stage.next_stage # GAPreInstallPatch
17
17
  end
18
18
 
19
19
  protected
@@ -21,7 +21,7 @@ module Dapp
21
21
  def apply_command_method
22
22
  :archive_apply_command
23
23
  end
24
- end # Source1Archive
24
+ end # GAArchive
25
25
  end # Stage
26
26
  end # Build
27
27
  end # Dapp
@@ -1,17 +1,17 @@
1
1
  module Dapp
2
2
  module Build
3
3
  module Stage
4
- # Source1ArchiveDependencies
5
- class Source1ArchiveDependencies < SourceDependenciesBase
4
+ # GAArchiveDependencies
5
+ class GAArchiveDependencies < GADependenciesBase
6
6
  def initialize(application, next_stage)
7
- @prev_stage = InfraInstall.new(application, self)
7
+ @prev_stage = BeforeInstall.new(application, self)
8
8
  super
9
9
  end
10
10
 
11
11
  def dependencies
12
12
  [application.git_artifacts.map(&:paramshash).join]
13
13
  end
14
- end # Source1ArchiveDependencies
14
+ end # GAArchiveDependencies
15
15
  end # Stage
16
16
  end # Build
17
17
  end # Dapp
@@ -1,15 +1,17 @@
1
1
  module Dapp
2
2
  module Build
3
3
  module Stage
4
- # Base of source stages
5
- class SourceBase < Base
6
- attr_accessor :prev_source_stage, :next_source_stage
4
+ # GABase
5
+ class GABase < Base
6
+ attr_accessor :prev_g_a_stage, :next_g_a_stage
7
7
 
8
- def prev_source_stage
8
+ GITARTIFACT_IMAGE = 'dappdeps/gitartifact:0.1.5'.freeze
9
+
10
+ def prev_g_a_stage
9
11
  dependencies_stage.prev_stage.prev_stage
10
12
  end
11
13
 
12
- def next_source_stage
14
+ def next_g_a_stage
13
15
  next_stage.next_stage.next_stage
14
16
  end
15
17
 
@@ -19,7 +21,9 @@ module Dapp
19
21
 
20
22
  def image
21
23
  super do |image|
22
- image.add_volumes_from application.gitartifact_container
24
+ image.add_volumes_from g_a_container
25
+ image.add_command 'export PATH=/.dapp/deps/gitartifact/bin:$PATH'
26
+
23
27
  application.git_artifacts.each do |git_artifact|
24
28
  image.add_volume "#{git_artifact.repo.path}:#{git_artifact.repo.container_path}:ro"
25
29
  image.add_command git_artifact.send(apply_command_method, self)
@@ -44,6 +48,26 @@ module Dapp
44
48
 
45
49
  protected
46
50
 
51
+ def g_a_container_name # FIXME: hashsum(image) or dockersafe()
52
+ GITARTIFACT_IMAGE.tr('/', '_').tr(':', '_')
53
+ end
54
+
55
+ def g_a_container
56
+ @gitartifact_container ||= begin
57
+ if application.project.shellout("docker inspect #{g_a_container_name}").exitstatus.nonzero?
58
+ application.project.log_secondary_process(application.project.t(code: 'process.git_artifact_loading'), short: true) do
59
+ application.project.shellout ['docker run',
60
+ '--restart=no',
61
+ "--name #{g_a_container_name}",
62
+ "--volume /.dapp/deps/gitartifact #{GITARTIFACT_IMAGE}",
63
+ '2>/dev/null'].join(' ')
64
+ end
65
+ end
66
+
67
+ g_a_container_name
68
+ end
69
+ end
70
+
47
71
  def should_not_be_detailed?
48
72
  true
49
73
  end
@@ -61,7 +85,7 @@ module Dapp
61
85
  def commits
62
86
  @commits ||= {}
63
87
  end
64
- end # SourceBase
88
+ end # GABase
65
89
  end # Stage
66
90
  end # Build
67
91
  end # Dapp
@@ -1,12 +1,12 @@
1
1
  module Dapp
2
2
  module Build
3
3
  module Stage
4
- # base of source dependencies stages
5
- class SourceDependenciesBase < Base
4
+ # GADependenciesBase
5
+ class GADependenciesBase < Base
6
6
  def image
7
7
  super do |image|
8
8
  application.git_artifacts.each do |git_artifact|
9
- image.add_change_label(git_artifact.full_name.to_sym => git_artifact.latest_commit)
9
+ image.add_service_change_label(git_artifact.full_name.to_sym => git_artifact.latest_commit)
10
10
  end
11
11
  end
12
12
  end
@@ -18,12 +18,11 @@ module Dapp
18
18
  protected
19
19
 
20
20
  def dependencies_files_checksum(regs)
21
- regs.map! { |reg| File.directory?(File.join(application.project_path, reg)) ? File.join(reg, '**', '*') : reg }
22
- unless (files = regs.map { |reg| Dir[File.join(application.project_path, reg)].map { |f| File.read(f) if File.file?(f) } }).empty?
21
+ unless (files = regs.map { |reg| Dir[File.join(application.home_path, reg)].map { |f| File.read(f) if File.file?(f) } }).empty?
23
22
  hashsum files
24
23
  end
25
24
  end
26
- end # SourceBase
25
+ end # GADependenciesBase
27
26
  end # Stage
28
27
  end # Build
29
28
  end # Dapp
@@ -1,18 +1,18 @@
1
1
  module Dapp
2
2
  module Build
3
3
  module Stage
4
- # Source5
5
- class Source5 < SourceBase
4
+ # GALatestPatch
5
+ class GALatestPatch < GABase
6
6
  def initialize(application, next_stage)
7
- @prev_stage = Source4.new(application, self)
7
+ @prev_stage = SetupGroup::GAPostSetupPatch.new(application, self)
8
8
  super
9
9
  end
10
10
 
11
- def prev_source_stage
11
+ def prev_g_a_stage
12
12
  prev_stage
13
13
  end
14
14
 
15
- def next_source_stage
15
+ def next_g_a_stage
16
16
  nil
17
17
  end
18
18
 
@@ -39,7 +39,7 @@ module Dapp
39
39
  def commit_list
40
40
  application.git_artifacts.map { |git_artifact| layer_commit(git_artifact) }
41
41
  end
42
- end # Source5
42
+ end # GALatestPatch
43
43
  end # Stage
44
44
  end # Build
45
45
  end # Dapp