dapp 0.22.6 → 0.22.7

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 (106) hide show
  1. checksums.yaml +4 -4
  2. data/bin/dapp +9 -5
  3. data/config/en/common.yml +2 -0
  4. data/config/en/net_status.yml +9 -12
  5. data/lib/dapp.rb +12 -47
  6. data/lib/dapp/cli/command/options/tag.rb +39 -0
  7. data/lib/dapp/config/directive/base.rb +2 -1
  8. data/lib/dapp/dapp.rb +6 -9
  9. data/lib/dapp/dapp/command/common.rb +9 -4
  10. data/lib/dapp/dapp/logging/i18n.rb +5 -1
  11. data/lib/dapp/dapp/logging/process.rb +2 -2
  12. data/lib/dapp/deployment/config/config.rb +5 -5
  13. data/lib/dapp/deployment/config/directive/expose.rb +1 -1
  14. data/lib/dapp/deployment/config/directive/namespace/instance_methods.rb +1 -1
  15. data/lib/dapp/deployment/error/app.rb +1 -1
  16. data/lib/dapp/deployment/error/{base.rb → default.rb} +1 -1
  17. data/lib/dapp/deployment/error/deployment.rb +1 -1
  18. data/lib/dapp/deployment/error/kubernetes.rb +1 -1
  19. data/lib/dapp/deployment/kubernetes.rb +3 -3
  20. data/lib/dapp/deployment/kubernetes/error.rb +4 -4
  21. data/lib/dapp/deployment/secret.rb +1 -1
  22. data/lib/dapp/dimg/cli/command/dimg.rb +2 -1
  23. data/lib/dapp/dimg/cli/command/dimg/build_context/export.rb +5 -0
  24. data/lib/dapp/dimg/cli/command/dimg/flush_local.rb +24 -0
  25. data/lib/dapp/dimg/cli/command/dimg/push.rb +2 -26
  26. data/lib/dapp/dimg/cli/command/dimg/stages/base.rb +2 -2
  27. data/lib/dapp/dimg/cli/command/dimg/tag.rb +11 -4
  28. data/lib/dapp/dimg/config/config.rb +1 -1
  29. data/lib/dapp/dimg/config/directive/artifact.rb +5 -5
  30. data/lib/dapp/dimg/config/directive/artifact_base.rb +5 -5
  31. data/lib/dapp/dimg/config/directive/dimg/instance_methods.rb +1 -1
  32. data/lib/dapp/dimg/config/directive/dimg/validation.rb +11 -13
  33. data/lib/dapp/dimg/config/directive/docker/artifact.rb +1 -1
  34. data/lib/dapp/dimg/config/directive/docker/base.rb +1 -1
  35. data/lib/dapp/dimg/config/directive/git_artifact_local.rb +19 -3
  36. data/lib/dapp/dimg/config/directive/git_artifact_remote.rb +3 -1
  37. data/lib/dapp/dimg/config/directive/mount.rb +3 -3
  38. data/lib/dapp/dimg/dapp/command/build.rb +1 -1
  39. data/lib/dapp/dimg/dapp/command/build_context/export.rb +17 -13
  40. data/lib/dapp/dimg/dapp/command/build_context/import.rb +24 -17
  41. data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +26 -33
  42. data/lib/dapp/dimg/dapp/command/common.rb +53 -56
  43. data/lib/dapp/dimg/dapp/command/flush_local.rb +18 -0
  44. data/lib/dapp/dimg/dapp/command/mrproper.rb +1 -1
  45. data/lib/dapp/dimg/dapp/command/push.rb +2 -8
  46. data/lib/dapp/dimg/dapp/command/spush.rb +2 -4
  47. data/lib/dapp/dimg/dapp/command/stages/cleanup_local.rb +41 -46
  48. data/lib/dapp/dimg/dapp/command/stages/cleanup_repo.rb +35 -39
  49. data/lib/dapp/dimg/dapp/command/stages/common.rb +13 -3
  50. data/lib/dapp/dimg/dapp/command/stages/flush_local.rb +1 -3
  51. data/lib/dapp/dimg/dapp/command/stages/flush_repo.rb +3 -3
  52. data/lib/dapp/dimg/dapp/command/stages/pull.rb +2 -12
  53. data/lib/dapp/dimg/dapp/command/stages/push.rb +2 -8
  54. data/lib/dapp/dimg/dapp/command/tag.rb +3 -6
  55. data/lib/dapp/dimg/dapp/dapp.rb +1 -0
  56. data/lib/dapp/dimg/dapp/dappfile.rb +11 -1
  57. data/lib/dapp/dimg/dimg.rb +39 -31
  58. data/lib/dapp/dimg/error/build.rb +1 -1
  59. data/lib/dapp/dimg/error/chef.rb +1 -5
  60. data/lib/dapp/dimg/error/{command.rb → default.rb} +1 -1
  61. data/lib/dapp/dimg/error/dimg.rb +1 -1
  62. data/lib/dapp/dimg/error/lock.rb +1 -1
  63. data/lib/dapp/dimg/error/registry.rb +1 -1
  64. data/lib/dapp/dimg/error/rugged.rb +1 -1
  65. data/lib/dapp/dimg/error/tar_writer.rb +1 -1
  66. data/lib/dapp/dimg/git_artifact.rb +3 -1
  67. data/lib/dapp/dimg/image/argument.rb +3 -1
  68. data/lib/dapp/dimg/image/dimg.rb +15 -0
  69. data/lib/dapp/dimg/image/stage.rb +0 -9
  70. data/lib/dapp/error/base.rb +1 -5
  71. data/lib/dapp/error/command.rb +5 -0
  72. data/lib/dapp/error/config.rb +5 -0
  73. data/lib/dapp/error/dapp.rb +1 -1
  74. data/lib/dapp/error/dappfile.rb +1 -1
  75. data/lib/dapp/error/default.rb +11 -0
  76. data/lib/dapp/error/mod/user.rb +11 -0
  77. data/lib/dapp/error/shellout.rb +1 -1
  78. data/lib/dapp/exception/base.rb +1 -1
  79. data/lib/dapp/helper/yaml.rb +3 -2
  80. data/lib/dapp/kube/cli/command/kube/deploy.rb +2 -26
  81. data/lib/dapp/kube/cli/command/kube/lint.rb +1 -26
  82. data/lib/dapp/kube/cli/command/kube/render.rb +2 -26
  83. data/lib/dapp/kube/cli/command/kube/secret_key_generate.rb +2 -2
  84. data/lib/dapp/kube/dapp/command/common.rb +19 -23
  85. data/lib/dapp/kube/dapp/command/deploy.rb +16 -9
  86. data/lib/dapp/kube/dapp/command/dismiss.rb +1 -1
  87. data/lib/dapp/kube/dapp/command/lint.rb +4 -10
  88. data/lib/dapp/kube/dapp/command/minikube_setup.rb +12 -18
  89. data/lib/dapp/kube/dapp/command/secret_edit.rb +2 -2
  90. data/lib/dapp/kube/error/{command.rb → default.rb} +1 -1
  91. data/lib/dapp/kube/error/kubernetes.rb +1 -1
  92. data/lib/dapp/kube/helm/release.rb +7 -33
  93. data/lib/dapp/kube/helm/values.rb +140 -0
  94. data/lib/dapp/kube/kubernetes/client.rb +9 -10
  95. data/lib/dapp/kube/kubernetes/client/error.rb +14 -8
  96. data/lib/dapp/kube/kubernetes/error.rb +15 -0
  97. data/lib/dapp/kube/kubernetes/manager/deployment.rb +2 -2
  98. data/lib/dapp/kube/secret.rb +1 -1
  99. data/lib/dapp/version.rb +1 -1
  100. metadata +15 -11
  101. data/lib/dapp/config/error/config.rb +0 -7
  102. data/lib/dapp/deployment/error/command.rb +0 -7
  103. data/lib/dapp/deployment/error/config.rb +0 -7
  104. data/lib/dapp/dimg/error/base.rb +0 -7
  105. data/lib/dapp/dimg/error/config.rb +0 -7
  106. data/lib/dapp/kube/error/base.rb +0 -11
@@ -6,9 +6,7 @@ module Dapp
6
6
  module CleanupLocal
7
7
  def stages_cleanup_local
8
8
  lock_repo(option_repo, readonly: true) do
9
- raise Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
10
-
11
- dapp_project_containers_flush
9
+ raise ::Dapp::Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
12
10
 
13
11
  proper_cache if proper_cache_version?
14
12
  stages_cleanup_by_repo if proper_repo_cache?
@@ -21,18 +19,13 @@ module Dapp
21
19
  def proper_cache
22
20
  log_proper_cache do
23
21
  lock("#{name}.images") do
24
- remove_project_images(dapp_project_images_ids.select { |image_id| !actual_cache_project_images_ids.include?(image_id) })
22
+ remove_project_images(dapp_project_dimgstages - actual_cache_project_dimgstages)
25
23
  end
26
24
  end
27
25
  end
28
26
 
29
- def actual_cache_project_images_ids
30
- @actual_cache_project_images_ids ||= begin
31
- shellout!(%(#{host_docker} images -f "label=dapp" -f "label=dapp-cache-version=#{::Dapp::BUILD_CACHE_VERSION}" -q --no-trunc #{stage_cache}))
32
- .stdout
33
- .lines
34
- .map(&:strip)
35
- end
27
+ def actual_cache_project_dimgstages
28
+ @actual_cache_project_images_ids ||= prepare_docker_images("-f \"label=dapp-cache-version=#{::Dapp::BUILD_CACHE_VERSION}\" #{stage_cache}")
36
29
  end
37
30
 
38
31
  def stages_cleanup_by_repo
@@ -40,74 +33,76 @@ module Dapp
40
33
  lock("#{name}.images") do
41
34
  registry = dimg_registry(option_repo)
42
35
  repo_dimgs = repo_detailed_dimgs_images(registry)
36
+ dimgstages = clone_dapp_project_dimgstages
43
37
 
44
- dapp_project_dangling_images_flush
45
-
46
- _, dimgstages = dapp_project_images.partition { |image| repo_dimgs.any? { |dimg| dimg[:id] == image[:id] } }
47
- repo_dimgs.each { |repo_dimg| except_dapp_project_image_with_parents(repo_dimg[:parent], dimgstages) }
38
+ repo_dimgs.each { |repo_dimg| except_image_id_with_parents(repo_dimg[:parent], dimgstages) }
48
39
 
49
40
  # Удаление только образов старше 2ч
50
41
  dimgstages.delete_if do |dimgstage|
51
42
  Time.now - dimgstage[:created_at] < 2*60*60
52
43
  end
53
44
 
54
- remove_project_images(dimgstages.map { |dimgstage| dimgstage[:id]} )
45
+ remove_project_images(dimgstages)
55
46
  end
56
47
  end
57
48
  end
58
49
 
59
- def except_dapp_project_image_with_parents(image_id, dimgstages)
60
- if dapp_project_image_exist?(image_id)
61
- dapp_project_image_artifacts_ids_in_labels(image_id).each { |aiid| except_dapp_project_image_with_parents(aiid, dimgstages) }
62
- iid = image_id
63
- loop do
64
- dimgstages.delete_if { |dimgstage| dimgstage[:id] == iid }
65
- break if (iid = dapp_project_image_parent_id(iid)).nil?
66
- end
67
- else
68
- dimgstages.delete_if { |dimgstage| dimgstage[:id] == dimgstage }
50
+ def clone_dapp_project_dimgstages
51
+ Marshal.load(Marshal.dump(dapp_project_dimgstages))
52
+ end
53
+
54
+ def except_image_id_with_parents(image_id, dimgstages)
55
+ return unless (project_image = dapp_project_image_by_id(image_id))
56
+ except_dapp_project_image_with_parents(project_image, dimgstages)
57
+ end
58
+
59
+ def except_dapp_project_image_with_parents(image, dimgstages)
60
+ dapp_project_image_artifacts_ids_in_labels(image).each { |aiid| except_image_id_with_parents(aiid, dimgstages) }
61
+ i = image
62
+ loop do
63
+ dimgstages.delete_if { |dimgstage| dimgstage == i }
64
+ break if (i = dapp_project_image_parent(i)).nil?
69
65
  end
70
66
  end
71
67
 
72
- def dapp_project_image_artifacts_ids_in_labels(image_id)
73
- select_dapp_artifacts_ids(dapp_project_image_labels(image_id))
68
+ def dapp_project_image_artifacts_ids_in_labels(image)
69
+ select_dapp_artifacts_ids(dapp_project_image_labels(image))
74
70
  end
75
71
 
76
72
  def proper_git_commit
77
73
  log_proper_git_commit do
78
74
  lock("#{name}.images") do
79
- dapp_project_dangling_images_flush
80
-
81
- unproper_images_ids = []
82
- dapp_project_images_ids.each do |image_id|
83
- dapp_project_image_labels(image_id).each do |repo_name, commit|
75
+ unproper_images = []
76
+ dapp_project_dimgstages.each do |dimgstage|
77
+ dapp_project_image_labels(dimgstage).each do |repo_name, commit|
84
78
  next if (repo = dapp_git_repositories[repo_name]).nil?
85
- unproper_images_ids.concat(dapp_project_image_hierarchy(image_id)) unless repo.commit_exists?(commit)
79
+ unproper_images.concat(dapp_project_image_with_children(dimgstage)) unless repo.commit_exists?(commit)
86
80
  end
87
81
  end
88
- remove_project_images(unproper_images_ids)
82
+ remove_project_images(unproper_images)
89
83
  end
90
84
  end
91
85
  end
92
86
 
93
- def dapp_project_image_hierarchy(image_id)
94
- hierarchy = []
95
- iids = [image_id]
87
+ def dapp_project_image_with_children(image)
88
+ children = []
89
+ images = [image]
96
90
 
97
91
  loop do
98
- hierarchy.concat(dapp_project_images_ids.select { |image_id| iids.include?(image_id) })
99
- break if begin
100
- iids.map! do |iid|
101
- dapp_project_images_ids.select { |image_id| dapp_project_image_parent_id(image_id) == iid }
102
- end.flatten!.empty?
92
+ children.concat(dapp_project_images.select { |project_image| images.include?(project_image) })
93
+ images.map! do |parent_image|
94
+ dapp_project_images
95
+ .select { |project_image| dapp_project_image_parent(project_image) == parent_image }
103
96
  end
97
+ images.flatten!
98
+ break if images.empty?
104
99
  end
105
100
 
106
- hierarchy
101
+ children
107
102
  end
108
103
 
109
- def dapp_project_image_parent_id(image_id)
110
- dapp_project_image_inspect(image_id)['Parent']
104
+ def dapp_project_image_parent(image)
105
+ dapp_project_image_by_id(dapp_project_image_inspect(image)['Parent'])
111
106
  end
112
107
  end
113
108
  end
@@ -6,17 +6,19 @@ module Dapp
6
6
  module CleanupRepo
7
7
  def stages_cleanup_repo
8
8
  lock_repo(repo = option_repo) do
9
- raise Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
9
+ raise ::Dapp::Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
10
10
 
11
- registry = dimg_registry(repo)
12
- repo_dimgs = repo_dimgs_images(registry)
13
- repo_dimgstages = repo_dimgstages_images(registry)
11
+ log_step_with_indent("#{repo} stages") do
12
+ registry = dimg_registry(repo)
13
+ repo_dimgs = repo_dimgs_images(registry)
14
+ repo_dimgstages = repo_dimgstages_images(registry)
14
15
 
15
- repo_dimgstages.delete_if { |dimgstage| repo_dimgs.any? { |dimg| dimgstage[:id] == dimg[:id] } } # ignoring stages with dimgs ids (v2)
16
+ repo_dimgstages.delete_if { |dimgstage| repo_dimgs.any? { |dimg| dimgstage[:id] == dimg[:id] } } # ignoring stages with dimgs ids (v2)
16
17
 
17
- proper_repo_cache(registry, repo_dimgstages) if proper_cache_version?
18
- repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages) if proper_repo_cache?
19
- proper_repo_git_commit(registry) if proper_git_commit?
18
+ proper_repo_cache(registry, repo_dimgstages) if proper_cache_version?
19
+ repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages) if proper_repo_cache?
20
+ proper_repo_git_commit(registry) if proper_git_commit?
21
+ end
20
22
  end
21
23
  end
22
24
 
@@ -31,24 +33,24 @@ module Dapp
31
33
  end
32
34
 
33
35
  def repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages)
34
- log_step_with_indent(option_repo) do
35
- repo_dimgs.each { |dimg| except_repo_image_with_parents(registry, repo_dimgstages, dimg) }
36
+ log_proper_repo_cache do
37
+ repo_dimgs.each { |dimg| except_repo_image_with_parents(registry, dimg, repo_dimgstages) }
36
38
  repo_dimgstages.each { |dimgstage| delete_repo_image(registry, dimgstage) }
37
39
  end
38
40
  end
39
41
 
40
- def except_repo_image_with_parents(registry, repo_dimgstages, repo_image)
41
- repo_image_dapp_artifacts_labels(registry, repo_image).each do |aid|
42
- repo_image = find_repo_image_by_id(repo_dimgstages, aid)
43
- except_repo_image_with_parents(registry, repo_dimgstages, repo_image) unless repo_image.nil?
42
+ def except_repo_image_with_parents(registry, repo_image, repo_dimgstages)
43
+ repo_image_dapp_artifacts_labels(registry, repo_image).each do |aiid|
44
+ unless (repo_artifact_image = repo_image_by_id(aiid, repo_dimgstages)).nil?
45
+ except_repo_image_with_parents(registry, repo_artifact_image, repo_dimgstages)
46
+ end
44
47
  end
45
48
 
49
+ ri = repo_image
46
50
  loop do
47
- repo_dimgstages.delete_if { |dimgstage| dimgstage[:id] == repo_image[:id] }
48
- break if begin
49
- (iid = registry.image_parent_id(repo_image[:tag], repo_image[:dimg])).empty? ||
50
- (repo_image = find_repo_image_by_id(repo_dimgstages, iid)).nil?
51
- end
51
+ repo_dimgstages.delete_if { |dimgstage| dimgstage == ri }
52
+ ri_parent_id = registry.image_parent_id(ri[:tag], ri[:dimg])
53
+ break if ri_parent_id.empty? || (ri = repo_image_by_id(ri_parent_id, repo_dimgstages)).nil?
52
54
  end
53
55
  end
54
56
 
@@ -60,20 +62,20 @@ module Dapp
60
62
  registry.image_labels(repo_image[:tag], repo_image[:dimg])['dapp-cache-version']
61
63
  end
62
64
 
63
- def find_repo_image_by_id(repo_images, repo_image_id)
65
+ def repo_image_by_id(repo_image_id, repo_images)
64
66
  repo_images.find { |repo_image| repo_image[:id] == repo_image_id }
65
67
  end
66
68
 
67
69
  def proper_repo_git_commit(registry)
68
70
  log_proper_git_commit do
69
- unproper_images = []
71
+ unproper_dimgstages = []
70
72
  repo_detailed_dimgstage_images(registry).each do |dimgstage|
71
73
  dimgstage[:labels].each do |repo_name, commit|
72
74
  next if (repo = dapp_git_repositories[repo_name]).nil?
73
- unproper_images.concat(repo_image_tags_hierarchy(registry, dimgstage[:id])) unless repo.commit_exists?(commit)
75
+ unproper_dimgstages.concat(repo_detailed_image_with_children(registry, dimgstage)) unless repo.commit_exists?(commit)
74
76
  end
75
77
  end
76
- remove_repo_dapp_dimgstage_images(registry, unproper_images.uniq)
78
+ unproper_dimgstages.uniq.each { |dimgstage| delete_repo_image(registry, dimgstage) }
77
79
  end
78
80
  end
79
81
 
@@ -87,27 +89,21 @@ module Dapp
87
89
  end
88
90
  end
89
91
 
90
- def repo_image_tags_hierarchy(registry, registry_image_id)
91
- hierarchy = []
92
- iids = [registry_image_id]
92
+ def repo_detailed_image_with_children(registry, image)
93
+ children = []
94
+ detailed_images = [image]
93
95
 
94
96
  loop do
95
- hierarchy.concat(iids)
96
- break if begin
97
- iids.map! do |iid|
98
- repo_detailed_dimgstage_images(registry).map { |dimgstage| dimgstage[:id] if dimgstage[:parent] == iid }.compact
99
- end.flatten!.empty?
97
+ children.concat(detailed_images)
98
+ detailed_images.map! do |repo_image|
99
+ repo_detailed_dimgstage_images(registry)
100
+ .select { |dimgstage| dimgstage[:parent] == repo_image[:id] }
100
101
  end
102
+ detailed_images.flatten!
103
+ break if detailed_images.empty?
101
104
  end
102
105
 
103
- repo_detailed_dimgstage_images(registry).map { |dimgstage| dimgstage[:tag] if hierarchy.include? dimgstage[:id] }.compact
104
- end
105
-
106
- def remove_repo_dapp_dimgstage_images(registry, tags)
107
- tags.each do |tag|
108
- log(tag) if log_verbose? || dry_run?
109
- registry.image_delete(tag, nil) unless dry_run?
110
- end
106
+ children
111
107
  end
112
108
  end
113
109
  end
@@ -6,6 +6,14 @@ module Dapp
6
6
  module Common
7
7
  protected
8
8
 
9
+ def repo_detailed_dimgs_images(registry)
10
+ repo_dimgs_images(registry).each do |dimg|
11
+ image_history = registry.image_history(dimg[:tag], dimg[:dimg])
12
+ dimg[:parent] = image_history['container_config']['Image']
13
+ dimg[:labels] = image_history['config']['Labels']
14
+ end
15
+ end
16
+
9
17
  def repo_dimgs_images(registry)
10
18
  [].tap do |dimgs_images|
11
19
  {}.tap do |dimgs_tags|
@@ -53,9 +61,11 @@ module Dapp
53
61
  {}.tap do |repositories|
54
62
  dimgs = build_configs.map { |config| Dimg.new(config: config, dapp: self, ignore_git_fetch: true) }
55
63
  dimgs.each do |dimg|
56
- [dimg, dimg.artifacts].flatten
57
- .map(&:git_artifacts).flatten
58
- .map { |git_artifact| repositories[dimgstage_g_a_commit_label(git_artifact.paramshash)] = git_artifact.repo }
64
+ [dimg, dimg.artifacts]
65
+ .flatten
66
+ .map(&:git_artifacts)
67
+ .flatten
68
+ .map { |git_artifact| repositories[dimgstage_g_a_commit_label(git_artifact.paramshash)] = git_artifact.repo }
59
69
  end
60
70
  end
61
71
  end
@@ -6,9 +6,7 @@ module Dapp
6
6
  module FlushLocal
7
7
  def stages_flush_local
8
8
  lock("#{name}.images") do
9
- dapp_project_containers_flush
10
- dapp_project_dangling_images_flush
11
- remove_project_images(dapp_project_images_ids)
9
+ log_step_with_indent('flush stages') { remove_project_images(dapp_project_dimgstages) }
12
10
  end
13
11
  end
14
12
  end
@@ -5,9 +5,9 @@ module Dapp
5
5
  module Stages
6
6
  module FlushRepo
7
7
  def stages_flush_repo
8
- lock_repo(option_repo) do
9
- log_step_with_indent(option_repo) do
10
- registry = dimg_registry(option_repo)
8
+ lock_repo(repo = option_repo) do
9
+ log_step_with_indent("#{repo} stages") do
10
+ registry = dimg_registry(repo)
11
11
  repo_dimgstages_images(registry).each { |repo_image| delete_repo_image(registry, repo_image) }
12
12
  end
13
13
  end
@@ -5,20 +5,10 @@ module Dapp
5
5
  module Stages
6
6
  module Pull
7
7
  def stages_pull
8
- repo = option_repo
9
- validate_repo_name!(repo)
10
- build_configs.each do |config|
11
- log_dimg_name_with_indent(config) do
12
- Dimg.new(config: config, dapp: self, ignore_git_fetch: true).tap do |dimg|
13
- dimg.import_stages!(repo, format: '%{repo}:dimgstage-%{signature}')
14
- end
15
- end
8
+ dimg_import_export_base(should_be_built: false) do |dimg|
9
+ dimg.import_stages!(option_repo, format: dimgstage_push_format)
16
10
  end
17
11
  end
18
-
19
- def pull_all_stages?
20
- !!options[:pull_all_stages]
21
- end
22
12
  end
23
13
  end
24
14
  end
@@ -5,14 +5,8 @@ module Dapp
5
5
  module Stages
6
6
  module Push
7
7
  def stages_push
8
- repo = option_repo
9
- validate_repo_name!(repo)
10
- build_configs.each do |config|
11
- log_dimg_name_with_indent(config) do
12
- Dimg.new(config: config, dapp: self, ignore_git_fetch: true, should_be_built: true).tap do |dimg|
13
- dimg.export_stages!(repo, format: '%{repo}:dimgstage-%{signature}')
14
- end
15
- end
8
+ dimg_import_export_base(should_be_built: false) do |dimg|
9
+ dimg.export_stages!(option_repo, format: dimgstage_push_format)
16
10
  end
17
11
  end
18
12
  end
@@ -3,12 +3,9 @@ module Dapp
3
3
  module Dapp
4
4
  module Command
5
5
  module Tag
6
- def tag(tag)
7
- one_dimg!
8
- validate_image_name!(tag)
9
-
10
- Dimg.new(config: build_configs.first, dapp: self, ignore_git_fetch: true, should_be_built: true).tap do |app|
11
- app.tag!(tag)
6
+ def tag
7
+ dimg_import_export_base do |dimg|
8
+ dimg.tag!(option_repo, format: push_format(dimg.config._name))
12
9
  end
13
10
  end
14
11
  end
@@ -20,6 +20,7 @@ module Dapp
20
20
  include Command::Stages::Pull
21
21
  include Command::Stages::Common
22
22
  include Command::CleanupRepo
23
+ include Command::FlushLocal
23
24
  include Command::FlushRepo
24
25
  include Command::Cleanup
25
26
  include Command::Mrproper
@@ -6,6 +6,16 @@ module Dapp
6
6
  dimgs_names.first.nil?
7
7
  end
8
8
 
9
+ def dimg_name!
10
+ one_dimg!
11
+ build_configs.first._name
12
+ end
13
+
14
+ def one_dimg!
15
+ return if build_configs.one?
16
+ raise ::Dapp::Error::Command, code: :command_unexpected_dimgs_number, data: { dimgs_names: build_configs.map(&:_name).join('`, `') }
17
+ end
18
+
9
19
  def dimgs_names
10
20
  build_configs.map(&:_name)
11
21
  end
@@ -15,7 +25,7 @@ module Dapp
15
25
  config._dimg.select do |dimg|
16
26
  dimgs_patterns.any? { |pattern| dimg._name.nil? || File.fnmatch(pattern, dimg._name) }
17
27
  end.tap do |dimgs|
18
- raise ::Dapp::Error::Dapp, code: :no_such_dimg, data: { dimgs_patterns: dimgs_patterns.join(', ') } if dimgs.empty?
28
+ raise ::Dapp::Error::Dapp, code: :no_such_dimg, data: { dimgs_patterns: dimgs_patterns.join('`, `') } if dimgs.empty?
19
29
  end
20
30
  end
21
31
  end
@@ -46,53 +46,60 @@ module Dapp
46
46
  artifacts.each { |artifact| artifact.last_stage.save_in_cache! }
47
47
  end
48
48
 
49
- def tag!(tag)
49
+ def tag!(repo, format:)
50
+ dimg_export_base!(repo, export_format: format)
51
+ end
52
+
53
+ def export!(repo, format:)
54
+ dimg_export_base!(repo, export_format: format, push: true)
55
+ end
56
+
57
+ def export_stages!(repo, format:)
50
58
  dapp.lock("#{dapp.name}.images", readonly: true) do
51
- dimg_name = config._name
52
- if dapp.dry_run?
53
- dapp.log_state(dimg_name, state: dapp.t(code: 'state.tag'), styles: { status: :success })
54
- else
55
- dapp.log_process(dimg_name, process: dapp.t(code: 'status.process.tagging')) do
56
- last_stage.image.tag!(tag)
59
+ export_images.each do |stage_image|
60
+ image_name = format(format, repo: repo, signature: stage_image.name.split(':').last)
61
+ export_base!(image_name, push: true) do
62
+ stage_image.export!(image_name)
57
63
  end
58
64
  end
59
65
  end
60
66
  end
61
67
 
62
- def export!(repo, format:)
68
+ def dimg_export_base!(repo, export_format:, push: false)
63
69
  dapp.lock("#{dapp.name}.images", readonly: true) do
64
70
  dapp.tags_by_scheme.each do |tag_scheme_name, tags|
65
- tags.each do |tag|
66
- image_name = format(format, repo: repo, dimg_name: config._name, tag: tag)
67
- export_base!(image_name) do
68
- last_stage.image.export_dimg!(image_name, sheme_name: tag_scheme_name)
71
+ dapp.log_step_with_indent(tag_scheme_name) do
72
+ tags.each do |tag|
73
+ image_name = format(export_format, repo: repo, dimg_name: config._name, tag: tag)
74
+ export_base!(image_name, push: push) do
75
+ export_image = build_export_image!(image_name, scheme_name: tag_scheme_name)
76
+ if push
77
+ export_image.export!
78
+ else
79
+ export_image.tag!
80
+ end
81
+ end
69
82
  end
70
- end
83
+ end unless tags.empty?
71
84
  end
72
85
  end
73
86
  end
74
87
 
75
- def export_stages!(repo, format:)
76
- dapp.lock("#{dapp.name}.images", readonly: true) do
77
- export_images.each do |image|
78
- image_name = format(format, repo: repo, signature: image.name.split(':').last)
79
- export_base!(image_name) do
80
- image.export!(image_name)
81
- end
82
- end
88
+ def build_export_image!(image_name, scheme_name:)
89
+ Image::Dimg.image_by_name(name: image_name, from: last_stage.image, dapp: dapp).tap do |export_image|
90
+ export_image.add_service_change_label(:'dapp-tag-scheme' => scheme_name)
91
+ export_image.add_service_change_label(:'dapp-dimg' => true)
92
+ export_image.build!
83
93
  end
84
94
  end
85
95
 
86
- def export_base!(image_name)
96
+ def export_base!(image_name, push: true)
87
97
  if dapp.dry_run?
88
- dapp.log_state(image_name, state: dapp.t(code: 'state.push'), styles: { status: :success })
98
+ dapp.log_state(image_name, state: dapp.t(code: push ? 'state.push' : 'state.export'), styles: { status: :success })
89
99
  else
90
100
  dapp.lock("image.#{hashsum image_name}") do
91
101
  ::Dapp::Dimg::Image::Docker.reset_image_inspect(image_name)
92
-
93
- dapp.log_process(image_name, process: dapp.t(code: 'status.process.pushing')) do
94
- yield
95
- end
102
+ dapp.log_process(image_name, process: dapp.t(code: push ? 'status.process.pushing' : 'status.process.exporting')) { yield }
96
103
  end
97
104
  end
98
105
  end
@@ -107,7 +114,7 @@ module Dapp
107
114
  dapp.log_info ::Dapp::Helper::NetStatus.message(e)
108
115
  next
109
116
  end
110
- break unless dapp.pull_all_stages?
117
+ break unless !!dapp.options[:pull_all_stages]
111
118
  end
112
119
  end
113
120
  end
@@ -117,9 +124,10 @@ module Dapp
117
124
  dapp.log_state(image_name, state: dapp.t(code: 'state.pull'), styles: { status: :success })
118
125
  else
119
126
  dapp.lock("image.#{hashsum image_name}") do
120
- dapp.log_process(image_name, process: dapp.t(code: 'status.process.pulling'),
121
- status: { failed: dapp.t(code: 'status.failed.not_pulled') },
122
- style: { failed: :secondary }) do
127
+ dapp.log_process(image_name,
128
+ process: dapp.t(code: 'status.process.pulling'),
129
+ status: { failed: dapp.t(code: 'status.failed.not_pulled') },
130
+ style: { failed: :secondary }) do
123
131
  image.import!(image_name)
124
132
  end
125
133
  end