dapp 0.35.13 → 0.35.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9a9837abcf859677dfcfc1ac5d345c291a78a20481bddb731f51cbed9a0dc8da
4
- data.tar.gz: 2d23a99bd288dee61a27605eac7c8a9be7ae8b0f4cbc832885900d5517fe0674
3
+ metadata.gz: 9b79f74ea56e3fa0b73cf59ffcf7575c03ed24c570b6340a29e87080144e89be
4
+ data.tar.gz: d0a49cdf9540c200d2d3a3c511ac5d983aed2bc74212b289f074d2042ccae029
5
5
  SHA512:
6
- metadata.gz: f8e25c106fca1b5362cd2898db82814e0c135a9640158c79d9c278c17140a4abc8209d5a3b40cff858a97d3975302eead06456122efb74923db7e15976f7039c
7
- data.tar.gz: 1af9e3d8bcc73a5dc8ab910101861c2d8010dba4ce42aa61fe2aab158e71dcd55009fa68924f8c2c8bc9648f8ec618adcb4dee4067703341acbc4bb400a8288d
6
+ metadata.gz: 55790f11cd30cd2f1ed9de5ba581369a76bdd06c9475f64f06aa17163ce9fe6b77fc09e25167ac0f2bcff9385a12f1b8856611f2ff38a1c02e668fba9d42c0af
7
+ data.tar.gz: eeaac232968bf0a80d1748b14f48e8a6eeb9ab156fc5d721eddbe6a1bc53b34ebf5536cc378f7716249493b210381cab2cc74e995d93b8a2b30e5b298d096276
@@ -24,11 +24,7 @@ module Dapp
24
24
  cleanup_repo_by_policies(registry, actual_detailed_dimgs_images_by_scheme(registry))
25
25
  end
26
26
 
27
- begin
28
- repo_dimgs = repo_dimgs_images(registry)
29
- repo_dimgstages = repo_dimgstages_images(registry)
30
- repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages)
31
- end if with_stages?
27
+ repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages) if with_stages?
32
28
  end
33
29
  end
34
30
  end
@@ -16,9 +16,11 @@ module Dapp
16
16
  force: true
17
17
  }
18
18
  },
19
- with_dimgs: true,
20
- with_stages: with_stages?,
21
- only_repo: false,
19
+ mode: {
20
+ with_dimgs: true,
21
+ with_stages: with_stages?,
22
+ only_repo: false,
23
+ },
22
24
  }.tap do |json|
23
25
  break JSON.dump(json)
24
26
  end
@@ -14,9 +14,11 @@ module Dapp
14
14
  dimg_names: dimgs_names,
15
15
  dry_run: dry_run?
16
16
  },
17
- with_dimgs: true,
18
- with_stages: with_stages?,
19
- only_repo: true,
17
+ mode: {
18
+ with_dimgs: true,
19
+ with_stages: with_stages?,
20
+ only_repo: true,
21
+ },
20
22
  }.tap do |json|
21
23
  break JSON.dump(json)
22
24
  end
@@ -14,6 +14,34 @@ module Dapp
14
14
  raise Error::Build, code: :ruby2go_cleanup_command_failed_unexpected_error, data: { command: command, message: res["error"] } unless res["error"].nil?
15
15
  end
16
16
  end
17
+
18
+ def ruby2go_cleanup_sync_common_project_options
19
+ {
20
+ common_project_options: {
21
+ project_name: name,
22
+ common_options: {
23
+ dry_run: dry_run?,
24
+ force: true
25
+ }
26
+ },
27
+ }
28
+ end
29
+
30
+ def ruby2go_cleanup_sync_cache_version_option
31
+ {
32
+ cache_version: ::Dapp::BUILD_CACHE_VERSION.to_s
33
+ }
34
+ end
35
+
36
+ def ruby2go_cleanup_sync_common_repo_options
37
+ {
38
+ common_repo_options: {
39
+ repository: option_repo,
40
+ dimg_names: dimgs_names,
41
+ dry_run: dry_run?
42
+ }
43
+ }
44
+ end
17
45
  end
18
46
  end
19
47
  end
@@ -5,115 +5,28 @@ module Dapp
5
5
  module Stages
6
6
  module CleanupLocal
7
7
  def stages_cleanup_local
8
- lock_repo(option_repo, readonly: true) do
9
- raise ::Dapp::Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
8
+ raise ::Dapp::Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
10
9
 
11
- proper_cache if proper_cache_version?
12
- stages_cleanup_by_repo if proper_repo_cache?
13
- proper_git_commit if proper_git_commit?
14
-
15
- dapp_containers_flush_by_label("dapp=#{name}")
16
- dapp_dangling_images_flush_by_label("dapp=#{name}")
10
+ if proper_cache_version?
11
+ ruby2go_cleanup_command(:sync, cleanup_local_proper_cache_version_options)
17
12
  end
18
- end
19
13
 
20
- protected
21
-
22
- def proper_cache
23
- log_proper_cache do
24
- lock("#{name}.images") do
25
- remove_project_images begin
26
- dapp_project_dimgstages.select do |image|
27
- !actual_cache_project_dimgstages.map { |dimgstage| dimgstage["Id"] }.include?(image["Id"])
28
- end
29
- end
30
- end
14
+ if proper_repo_cache?
15
+ ruby2go_cleanup_command(:sync, cleanup_local_proper_repo_cache_options)
31
16
  end
32
17
  end
33
18
 
34
- def actual_cache_project_dimgstages
35
- @actual_cache_project_dimgstages ||= begin
36
- filters = [{ label: "dapp-cache-version=#{::Dapp::BUILD_CACHE_VERSION}", reference: stage_cache }]
37
- prepare_docker_images(extra_filters: filters)
19
+ def cleanup_local_proper_cache_version_options
20
+ ruby2go_cleanup_sync_common_project_options.merge(ruby2go_cleanup_sync_cache_version_option).tap do |data|
21
+ break JSON.dump(data)
38
22
  end
39
23
  end
40
24
 
41
- def stages_cleanup_by_repo
42
- log_proper_repo_cache do
43
- lock("#{name}.images") do
44
- registry = dimg_registry(option_repo)
45
- repo_dimgs = repo_detailed_dimgs_images(registry)
46
- dimgstages = clone_dapp_project_dimgstages
47
-
48
- repo_dimgs.each { |repo_dimg| except_image_id_with_parents(repo_dimg[:parent], dimgstages) }
49
-
50
- # Удаление только образов старше 2ч
51
- dimgstages.delete_if do |dimgstage|
52
- Time.now.to_i - dimgstage["Created"] < 2 * 60 * 60
53
- end unless ENV['DAPP_STAGES_CLEANUP_LOCAL_DISABLED_DATE_POLICY']
54
-
55
- remove_project_images(dimgstages)
56
- end
57
- end
58
- end
59
-
60
- def clone_dapp_project_dimgstages
61
- Marshal.load(Marshal.dump(dapp_project_dimgstages))
62
- end
63
-
64
- def except_image_id_with_parents(image_id, dimgstages)
65
- return unless (project_image = dapp_project_image_by_id(image_id))
66
- except_dapp_project_image_with_parents(project_image, dimgstages)
67
- end
68
-
69
- def except_dapp_project_image_with_parents(image, dimgstages)
70
- dapp_project_image_artifacts_ids_in_labels(image).each { |aiid| except_image_id_with_parents(aiid, dimgstages) }
71
- i = image
72
- loop do
73
- array_hash_delete_if_by_id(dimgstages, i)
74
- break if (i = dapp_project_image_parent(i)).nil?
25
+ def cleanup_local_proper_repo_cache_options
26
+ ruby2go_cleanup_sync_common_project_options.merge(ruby2go_cleanup_sync_common_repo_options).tap do |data|
27
+ break JSON.dump(data)
75
28
  end
76
29
  end
77
-
78
- def dapp_project_image_artifacts_ids_in_labels(image)
79
- select_dapp_artifacts_ids(image['Labels'])
80
- end
81
-
82
- def proper_git_commit
83
- log_proper_git_commit do
84
- lock("#{name}.images") do
85
- unproper_images = []
86
- dapp_project_dimgstages.each do |dimgstage|
87
- dimgstage["Labels"].each do |repo_name, commit|
88
- next if (repo = dapp_git_repositories[repo_name]).nil?
89
- unproper_images.concat(dapp_project_image_with_children(dimgstage)) unless repo.commit_exists?(commit)
90
- end
91
- end
92
- remove_project_images(unproper_images)
93
- end
94
- end
95
- end
96
-
97
- def dapp_project_image_with_children(image)
98
- children = []
99
- images = [image]
100
-
101
- loop do
102
- children.concat(dapp_project_images.select { |project_image| images.include?(project_image) })
103
- images.map! do |parent_image|
104
- dapp_project_images
105
- .select { |project_image| dapp_project_image_parent(project_image) == parent_image }
106
- end
107
- images.flatten!
108
- break if images.empty?
109
- end
110
-
111
- children
112
- end
113
-
114
- def dapp_project_image_parent(image)
115
- dapp_project_image_by_id(image['ParentId'])
116
- end
117
30
  end
118
31
  end
119
32
  end
@@ -8,103 +8,26 @@ module Dapp
8
8
  lock_repo(repo = option_repo) do
9
9
  raise ::Dapp::Error::Command, code: :stages_cleanup_required_option unless stages_cleanup_option?
10
10
 
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)
15
-
16
- array_hash_delete_if_by_id(repo_dimgstages, repo_dimgs) # ignoring stages with dimgs ids (v2)
17
-
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
11
+ ruby2go_cleanup_command(:sync, cleanup_repo_proper_cache_version_options) if proper_cache_version?
12
+ repo_dimgstages_cleanup if proper_repo_cache?
22
13
  end
23
14
  end
24
15
 
25
- protected
26
-
27
- def proper_repo_cache(registry, repo_dimgstages)
28
- log_proper_cache do
29
- repo_dimgstages
30
- .select { |dimgstage| repo_image_dapp_cache_version_label(registry, dimgstage) != ::Dapp::BUILD_CACHE_VERSION.to_s }
31
- .each { |dimgstage| delete_repo_image(registry, dimgstage); repo_dimgstages.delete_at(repo_dimgstages.index(dimgstage)) }
32
- end
16
+ def repo_dimgstages_cleanup
17
+ ruby2go_cleanup_command(:sync, cleanup_repo_proper_repo_cache_options)
33
18
  end
34
19
 
35
- def repo_dimgstages_cleanup(registry, repo_dimgs, repo_dimgstages)
36
- log_proper_repo_cache do
37
- repo_dimgs.each { |dimg| except_repo_image_with_parents(registry, dimg, repo_dimgstages) }
38
- repo_dimgstages.each { |dimgstage| delete_repo_image(registry, dimgstage) }
20
+ def cleanup_repo_proper_cache_version_options
21
+ ruby2go_cleanup_sync_common_repo_options.merge({ mode: { sync_repo: true, only_cache_version: true } }).merge(ruby2go_cleanup_sync_cache_version_option).tap do |data|
22
+ break JSON.dump(data)
39
23
  end
40
24
  end
41
25
 
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
47
- end
48
-
49
- ri = repo_image
50
- loop do
51
- array_hash_delete_if_by_id(repo_dimgstages, 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?
26
+ def cleanup_repo_proper_repo_cache_options
27
+ ruby2go_cleanup_sync_common_repo_options.merge({ sync_repo: true }).tap do |data|
28
+ break JSON.dump(data)
54
29
  end
55
30
  end
56
-
57
- def repo_image_dapp_artifacts_labels(registry, repo_image)
58
- select_dapp_artifacts_ids(registry.image_config(repo_image[:tag], repo_image[:dimg])["config"]["Labels"])
59
- end
60
-
61
- def repo_image_dapp_cache_version_label(registry, repo_image)
62
- registry.image_config(repo_image[:tag], repo_image[:dimg])["config"]["Labels"]['dapp-cache-version']
63
- end
64
-
65
- def repo_image_by_id(repo_image_id, repo_images)
66
- repo_images.find { |repo_image| repo_image[:id] == repo_image_id }
67
- end
68
-
69
- def proper_repo_git_commit(registry)
70
- log_proper_git_commit do
71
- unproper_dimgstages = []
72
- repo_detailed_dimgstage_images(registry).each do |dimgstage|
73
- dimgstage[:labels].each do |repo_name, commit|
74
- next if (repo = dapp_git_repositories[repo_name]).nil?
75
- unproper_dimgstages.concat(repo_detailed_image_with_children(registry, dimgstage)) unless repo.commit_exists?(commit)
76
- end
77
- end
78
- unproper_dimgstages.uniq.each { |dimgstage| delete_repo_image(registry, dimgstage) }
79
- end
80
- end
81
-
82
- def repo_detailed_dimgstage_images(registry)
83
- @repo_dapp_dimgstage_images_detailed ||= begin
84
- repo_dimgstages_images(registry).each do |dimgstage|
85
- image_config = registry.image_config(dimgstage[:tag], nil)
86
- dimgstage[:parent] = image_config["container_config"]["Image"]
87
- dimgstage[:labels] = image_config["config"]["Labels"]
88
- end
89
- end
90
- end
91
-
92
- def repo_detailed_image_with_children(registry, image)
93
- children = []
94
- detailed_images = [image]
95
-
96
- loop do
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] }
101
- end
102
- detailed_images.flatten!
103
- break if detailed_images.empty?
104
- end
105
-
106
- children
107
- end
108
31
  end
109
32
  end
110
33
  end
@@ -76,25 +76,6 @@ module Dapp
76
76
  end
77
77
  end
78
78
 
79
- def select_dapp_artifacts_ids(labels)
80
- labels.select { |k, _v| k.start_with?('dapp-artifact') }.values
81
- end
82
-
83
- def dapp_git_repositories
84
- @dapp_git_repositories ||= begin
85
- {}.tap do |repositories|
86
- dimgs = build_configs.map { |config| dimg(config: config, ignore_signature_auto_calculation: true) }
87
- dimgs.each do |dimg|
88
- [dimg, dimg.artifacts]
89
- .flatten
90
- .map(&:git_artifacts)
91
- .flatten
92
- .map { |git_artifact| repositories[dimgstage_g_a_commit_label(git_artifact.paramshash)] = git_artifact.repo }
93
- end
94
- end
95
- end
96
- end
97
-
98
79
  def proper_repo_cache?
99
80
  !!options[:proper_repo_cache]
100
81
  end
@@ -17,9 +17,11 @@ module Dapp
17
17
  force: true
18
18
  }
19
19
  },
20
- with_dimgs: false,
21
- with_stages: true,
22
- only_repo: false,
20
+ mode: {
21
+ with_dimgs: false,
22
+ with_stages: true,
23
+ only_repo: false,
24
+ },
23
25
  }.tap do |json|
24
26
  break JSON.dump(json)
25
27
  end
@@ -15,9 +15,11 @@ module Dapp
15
15
  dimg_names: dimgs_names,
16
16
  dry_run: dry_run?
17
17
  },
18
- with_dimgs: false,
19
- with_stages: true,
20
- only_repo: true,
18
+ mode: {
19
+ with_dimgs: false,
20
+ with_stages: true,
21
+ only_repo: true,
22
+ },
21
23
  }.tap do |json|
22
24
  break JSON.dump(json)
23
25
  end
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = "0.35.13"
2
+ VERSION = "0.35.14"
3
3
  BUILD_CACHE_VERSION = 31
4
4
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dapp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.35.13
4
+ version: 0.35.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dmitry Stolyarov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-10 00:00:00.000000000 Z
11
+ date: 2018-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout