dapp 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d92ae2acd1b2b9398e83d79445241ac190a6855d
4
- data.tar.gz: 489ae183ac1cc60b312f9827d1b8c89ca18654e2
3
+ metadata.gz: 344169cb4810496ce7bdffabb39b0e0d67d922be
4
+ data.tar.gz: 80300942c9abcfd25956099e7680d06c980deba1
5
5
  SHA512:
6
- metadata.gz: 3e3ce3bbd3155ae5b3e9c43c737cb190218fce09cb1fc9f2c67495a3c1cf630cbb9e717a60ff04fee89bc34fa4ef2da3cc18c48fdbba130a14eeb513526cfb2a
7
- data.tar.gz: 1c0fccb84466f1fce3700a8bdeceb040fed68f723d4ab3ef8ac0a98d9c724167efa1a8f07e82b9b5d2cecfb83ac47568cd61a3977f6728683ed1295e5a3b0444
6
+ metadata.gz: 6c9f6344686884f6be5132acad1e4be8a433dbdc7362b07a0e9cdede2d45aeebf699536d4860e7b82d69c060ffee7c52c796488181cd0c2fba140817ed3ae592
7
+ data.tar.gz: d7ec6ba5e7adcaa342c64cb5258e1cb74a6a4579d522e13c863dee0e24a0c9fdb4df04fcc80cbd463ad5a7c6a0c54206017da8e8421775a5d2ba402a1cd952a9
data/config/en/common.yml CHANGED
@@ -28,4 +28,5 @@ en:
28
28
  using_cache: '[USING CACHE]'
29
29
  not_present: '[NOT PRESENT]'
30
30
  build: '[BUILD]'
31
+ empty: '[EMPTY]'
31
32
  push: '[PUSH]'
@@ -8,6 +8,8 @@ en:
8
8
  application_not_run: "Application run failed!"
9
9
  git_branch_without_name: "Application has specific revision that isn't associated with a branch name!"
10
10
  ci_environment_required: 'CI environment required (Travis or GitLab CI)!'
11
+ dappfile:
12
+ incorrect: "Dappfile '%{path}' with '%{error}':\n%{message}"
11
13
  build:
12
14
  from_image_required: 'Missing from_image!'
13
15
  image_already_untagged: "Image `%{name}` already untagged!"
@@ -24,8 +26,6 @@ en:
24
26
  builder_type_unsupported: "Defined unsupported builder type `%{type}`!"
25
27
  docker_from_not_defined: "Docker `from` not defined!"
26
28
  artifact_unexpected_attribute: "Artifact doesn't has attribute '%{attr}'!"
27
- stage_artifact_not_associated: "Artifact not associated with any stage!"
28
- stage_artifact_incorrect_associated_value: "Artifact option '%{option}' has incorrect value '%{value}'!"
29
29
  git_artifact_unexpected_attribute: "'%{type}' git artifact doesn't has attribute '%{attr}'!"
30
30
  chef:
31
31
  stage_path_overlap: "Cannot install '%{cookbook}' cookbook's path %{from} into %{to}: already exists"
data/lib/dapp.rb CHANGED
@@ -27,6 +27,7 @@ require 'dapp/helper/shellout'
27
27
  require 'dapp/helper/net_status'
28
28
  require 'dapp/error/base'
29
29
  require 'dapp/error/application'
30
+ require 'dapp/error/dappfile'
30
31
  require 'dapp/error/build'
31
32
  require 'dapp/error/config'
32
33
  require 'dapp/error/controller'
@@ -37,8 +38,6 @@ require 'dapp/cli/build'
37
38
  require 'dapp/cli/push'
38
39
  require 'dapp/cli/smartpush'
39
40
  require 'dapp/cli/list'
40
- require 'dapp/cli/metadata'
41
- require 'dapp/cli/metadata/flush'
42
41
  require 'dapp/cli/stages'
43
42
  require 'dapp/cli/stages/flush'
44
43
  require 'dapp/cli/stages/cleanup'
@@ -61,18 +60,26 @@ require 'dapp/build/stage/mod/artifact'
61
60
  require 'dapp/build/stage/mod/logging'
62
61
  require 'dapp/build/stage/base'
63
62
  require 'dapp/build/stage/source_base'
63
+ require 'dapp/build/stage/source_dependencies_base'
64
64
  require 'dapp/build/stage/from'
65
65
  require 'dapp/build/stage/infra_install'
66
66
  require 'dapp/build/stage/infra_setup'
67
67
  require 'dapp/build/stage/install'
68
+ require 'dapp/build/stage/artifact'
68
69
  require 'dapp/build/stage/setup'
69
70
  require 'dapp/build/stage/chef_cookbooks'
70
71
  require 'dapp/build/stage/source_1_archive'
72
+ require 'dapp/build/stage/source_1_archive_dependencies'
71
73
  require 'dapp/build/stage/source_1'
74
+ require 'dapp/build/stage/source_1_dependencies'
72
75
  require 'dapp/build/stage/source_2'
76
+ require 'dapp/build/stage/source_2_dependencies'
73
77
  require 'dapp/build/stage/source_3'
78
+ require 'dapp/build/stage/source_3_dependencies'
74
79
  require 'dapp/build/stage/source_4'
80
+ require 'dapp/build/stage/source_4_dependencies'
75
81
  require 'dapp/build/stage/source_5'
82
+ require 'dapp/build/stage/docker_instructions'
76
83
  require 'dapp/controller'
77
84
  require 'dapp/application/git_artifact'
78
85
  require 'dapp/application/logging'
@@ -16,17 +16,14 @@ module Dapp
16
16
  attr_reader :ignore_git_fetch
17
17
  attr_reader :is_artifact
18
18
 
19
- STAGES = [:from, :infra_install, :source_1_archive, :source_1, :install, :source_2,
20
- :infra_setup, :source_3, :chef_cookbooks, :setup, :source_4, :source_5].freeze
21
-
22
19
  def initialize(config:, cli_options:, ignore_git_fetch: false, is_artifact: false)
23
20
  @config = config
24
21
  @cli_options = cli_options
25
22
 
26
23
  @tmp_path = Dir.mktmpdir(cli_options[:tmp_dir_prefix] || 'dapp-')
27
- @metadata_path = cli_options[:metadata_dir] || home_path('.dapps-metadata')
24
+ @build_path = cli_options[:build_dir] || home_path('.dapps-build')
28
25
 
29
- @last_stage = Build::Stage::Source5.new(self)
26
+ @last_stage = Build::Stage::DockerInstructions.new(self)
30
27
  @ignore_git_fetch = ignore_git_fetch
31
28
  @is_artifact = is_artifact
32
29
  end
@@ -8,11 +8,11 @@ module Dapp
8
8
  end
9
9
 
10
10
  def tmp_path(*path)
11
- make_path(@tmp_path, *path).expand_path.tap { |p| FileUtils.mkdir_p p.parent }
11
+ make_path(@tmp_path, *path).expand_path.tap { |p| p.parent.mkpath }
12
12
  end
13
13
 
14
- def metadata_path(*path)
15
- make_path(@metadata_path, home_path.basename, *path).expand_path.tap { |p| FileUtils.mkdir_p p.parent }
14
+ def build_path(*path)
15
+ make_path(@build_path, home_path.basename, *path).expand_path.tap { |p| p.parent.mkpath }
16
16
  end
17
17
 
18
18
  def container_dapp_path(*path)
@@ -0,0 +1,35 @@
1
+ module Dapp
2
+ module Build
3
+ module Stage
4
+ # Artifact
5
+ class Artifact < Base
6
+ include Mod::Artifact
7
+
8
+ def initialize(application, next_stage)
9
+ @prev_stage = Install.new(application, self)
10
+ super
11
+ end
12
+
13
+ def dependencies
14
+ artifacts_signatures
15
+ end
16
+
17
+ def image
18
+ super do |image|
19
+ artifacts.each { |artifact| apply_artifact(artifact, image) }
20
+ end
21
+ end
22
+
23
+ protected
24
+
25
+ def should_be_not_detailed?
26
+ true
27
+ end
28
+
29
+ def ignore_log_commands?
30
+ true
31
+ end
32
+ end # Artifact
33
+ end # Stage
34
+ end # Build
35
+ end # Dapp
@@ -5,7 +5,6 @@ module Dapp
5
5
  class Base
6
6
  include Helper::Sha256
7
7
  include Helper::Trivia
8
- include Mod::Artifact
9
8
  include Mod::Logging
10
9
 
11
10
  attr_accessor :prev_stage, :next_stage
@@ -21,41 +20,56 @@ module Dapp
21
20
  def build!
22
21
  return if should_be_skipped?
23
22
  prev_stage.build! if prev_stage
24
- image_build
23
+ image_build unless empty? && !application.log_verbose?
25
24
  raise Exception::IntrospectImage, data: { built_id: image.built_id, options: image.send(:prepared_options) } if should_be_introspected?
26
25
  end
27
26
 
28
27
  def save_in_cache!
29
- return if image.tagged?
30
- prev_stage.save_in_cache! if prev_stage
28
+ prev_stage.save_in_cache! if prev_stage
29
+ return unless should_be_tagged?
31
30
  image.tag!(log_verbose: application.log_verbose?, log_time: application.log_time?) unless application.dry_run?
32
31
  end
33
32
 
34
- def signature
35
- hashsum [prev_stage.signature, artifacts_signatures]
36
- end
37
-
38
33
  def image
39
34
  @image ||= begin
40
- Image::Stage.new(name: image_name, from: from_image).tap do |image|
41
- image.add_volume "#{application.tmp_path}:#{application.container_tmp_path}"
42
- image.add_change_label dapp: application.config._basename
43
- before_artifacts.each { |artifact| apply_artifact(artifact, image) }
44
- yield image if block_given?
45
- after_artifacts.each { |artifact| apply_artifact(artifact, image) }
35
+ if empty?
36
+ prev_stage.image
37
+ else
38
+ Image::Stage.new(name: image_name, from: from_image).tap do |image|
39
+ image.add_change_label dapp: application.config._basename
40
+ yield image if block_given?
41
+ end
46
42
  end
47
43
  end
48
44
  end
49
45
 
50
- protected
46
+ def empty?
47
+ dependencies_empty?
48
+ end
51
49
 
52
- def name
53
- class_to_lowercase.to_sym
50
+ def dependencies_empty?
51
+ dependencies.flatten.compact.delete_if { |val| val.respond_to?(:empty?) && val.empty? }.empty?
52
+ end
53
+
54
+ def signature
55
+ if empty?
56
+ prev_stage.signature
57
+ else
58
+ hashsum [prev_stage.signature, *dependencies.flatten]
59
+ end
60
+ end
61
+
62
+ def dependencies
63
+ []
54
64
  end
55
65
 
66
+ protected
67
+
56
68
  # rubocop:disable Metrics/AbcSize
57
69
  def image_build
58
- if image.tagged?
70
+ if empty?
71
+ application.log_state(name, state: application.t(code: 'state.empty'))
72
+ elsif image.tagged?
59
73
  application.log_state(name, state: application.t(code: 'state.using_cache'))
60
74
  elsif should_be_not_present?
61
75
  application.log_state(name, state: application.t(code: 'state.not_present'))
@@ -78,14 +92,22 @@ module Dapp
78
92
  introspect_before_error: application.cli_options[:introspect_before_error])
79
93
  end
80
94
 
95
+ def should_be_tagged?
96
+ !(image.tagged? || empty?)
97
+ end
98
+
99
+ def image_name
100
+ "#{application.config._basename}-dappstage:#{signature}"
101
+ end
102
+
81
103
  def from_image
82
104
  prev_stage.image if prev_stage || begin
83
105
  raise Error::Build, code: :from_image_required
84
106
  end
85
107
  end
86
108
 
87
- def image_name
88
- "#{application.config._basename}-dappstage:#{signature}"
109
+ def name
110
+ class_to_lowercase.to_sym
89
111
  end
90
112
  end # Base
91
113
  end # Stage
@@ -8,8 +8,8 @@ module Dapp
8
8
  super
9
9
  end
10
10
 
11
- def signature
12
- hashsum [super, *application.builder.chef_cookbooks_checksum]
11
+ def dependencies
12
+ [application.builder.chef_cookbooks_checksum]
13
13
  end
14
14
 
15
15
  def image
@@ -17,6 +17,16 @@ module Dapp
17
17
  application.builder.chef_cookbooks(image)
18
18
  end
19
19
  end
20
+
21
+ protected
22
+
23
+ def should_be_not_detailed?
24
+ true
25
+ end
26
+
27
+ def ignore_log_commands?
28
+ true
29
+ end
20
30
  end # ChefCookbooks
21
31
  end # Stage
22
32
  end # Build
@@ -0,0 +1,31 @@
1
+ module Dapp
2
+ module Build
3
+ module Stage
4
+ # DockerInstructions
5
+ class DockerInstructions < Base
6
+ def initialize(application)
7
+ @prev_stage = Source5.new(application, self)
8
+ @application = application
9
+ end
10
+
11
+ def dependencies
12
+ [change_options]
13
+ end
14
+
15
+ def image
16
+ super do |image|
17
+ change_options.each do |k, v|
18
+ image.public_send("add_change_#{k}", v)
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def change_options
26
+ @change_options ||= application.config._docker._change_options.delete_if { |_, val| val.nil? || (val.respond_to?(:empty?) && val.empty?) }
27
+ end
28
+ end # DockerInstructions
29
+ end # Stage
30
+ end # Build
31
+ end # Dapp
@@ -4,10 +4,11 @@ module Dapp
4
4
  # From
5
5
  class From < Base
6
6
  def signature
7
- hashsum [from_image_name,
8
- artifacts_signatures,
9
- application.config._docker._from_cache_version,
10
- Dapp::BUILD_CACHE_VERSION]
7
+ hashsum [*dependencies.flatten]
8
+ end
9
+
10
+ def dependencies
11
+ [from_image_name, application.config._docker._from_cache_version, Dapp::BUILD_CACHE_VERSION]
11
12
  end
12
13
 
13
14
  def save_in_cache!
@@ -8,8 +8,12 @@ module Dapp
8
8
  super
9
9
  end
10
10
 
11
- def signature
12
- hashsum [super, *application.builder.infra_install_checksum]
11
+ def empty?
12
+ super && !application.builder.infra_install?
13
+ end
14
+
15
+ def dependencies
16
+ [application.builder.infra_install_checksum]
13
17
  end
14
18
 
15
19
  def image
@@ -8,6 +8,14 @@ module Dapp
8
8
  super
9
9
  end
10
10
 
11
+ def empty?
12
+ super && !application.builder.infra_setup?
13
+ end
14
+
15
+ def dependencies
16
+ prev_stage.prev_stage.dependencies
17
+ end
18
+
11
19
  def image
12
20
  super do |image|
13
21
  application.builder.infra_setup(image)
@@ -8,6 +8,14 @@ module Dapp
8
8
  super
9
9
  end
10
10
 
11
+ def empty?
12
+ super && !application.builder.install?
13
+ end
14
+
15
+ def dependencies
16
+ prev_stage.prev_stage.dependencies
17
+ end
18
+
11
19
  def image
12
20
  super do |image|
13
21
  application.builder.install(image)
@@ -5,25 +5,19 @@ module Dapp
5
5
  module Mod
6
6
  # Artifact
7
7
  module Artifact
8
- def before_artifacts
9
- @before_artifacts ||= do_artifacts(application.config._artifact.select { |artifact| artifact._before == name })
10
- end
11
-
12
- def after_artifacts
13
- @after_artifacts ||= do_artifacts(application.config._artifact.select { |artifact| artifact._after == name })
14
- end
15
-
16
- def do_artifacts(artifacts)
17
- verbose = application.log_verbose?
18
- artifacts.map do |artifact|
19
- process = application.t(code: 'process.artifact_building', data: { name: artifact._config._name })
20
- application.log_secondary_process(process, short: !verbose) do
21
- application.with_log_indent do
22
- {
23
- name: artifact._config._name,
24
- options: artifact._artifact_options,
25
- app: Application.new(artifact_app_options(artifact, verbose)).tap(&:build!)
26
- }
8
+ def artifacts
9
+ @artifacts ||= begin
10
+ verbose = application.log_verbose?
11
+ application.config._artifact.map do |artifact|
12
+ process = application.t(code: 'process.artifact_building', data: { name: artifact._config._name })
13
+ application.log_secondary_process(process, short: !verbose) do
14
+ application.with_log_indent do
15
+ {
16
+ name: artifact._config._name,
17
+ options: artifact._artifact_options,
18
+ app: Application.new(artifact_app_options(artifact, verbose)).tap(&:build!)
19
+ }
20
+ end
27
21
  end
28
22
  end
29
23
  end
@@ -39,7 +33,7 @@ module Dapp
39
33
  end
40
34
 
41
35
  def artifacts_signatures
42
- (before_artifacts + after_artifacts).map { |artifact| hashsum [artifact[:app].signature, artifact[:options]] }
36
+ artifacts.map { |artifact| hashsum [artifact[:app].signature, artifact[:options]] }
43
37
  end
44
38
 
45
39
  # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@@ -63,7 +57,8 @@ module Dapp
63
57
  end
64
58
 
65
59
  commands = safe_cp(application.container_tmp_path('artifact', artifact_name), where_to_add, owner, group, cwd, paths)
66
- image.add_commands commands
60
+ image.add_command commands
61
+ image.add_volume "#{application.tmp_path('artifact', artifact_name)}:#{application.container_tmp_path('artifact', artifact_name)}:ro"
67
62
  end
68
63
  # rubocop:enable Metrics/AbcSize, Metrics/MethodLength
69
64