dapp 0.32.4 → 0.32.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 9f5583e1391377bea9cf4e8b6be0f3ec8bf71f7059f7162cad6ce53da868452f
4
- data.tar.gz: b94d1240dff28b874918b9bddc502b08e6a84f28c9e40546bad3e8f70937faa0
3
+ metadata.gz: 82dd12f915fdea20821fc8d4e9e98282d73d811c5e0a694eb9694c52dc57b26a
4
+ data.tar.gz: 6ed9eea4366ff81215c1b38c0fb22642a4dea9bf4c3e629c1a0cb85c02ad74ac
5
5
  SHA512:
6
- metadata.gz: 6cf03c1bf20a9bbb866190968e32fd0ba019bac185dd09ffd19f0fb0c5a371548bfbc650fdf9707b2b7fe0af1e34c1ffe84f9d3ea6a7586020bb347e981fbd0b
7
- data.tar.gz: ecfab8ad64fa943b334428d902374433659275c50fc7321f42f2b2d0df98e087d2ebe5175568e6b6edaf889f2d49b3c10a2da70a3c8fb8a034a137646ff638b7
6
+ metadata.gz: fa49403a731072c4fff6cf45a74ddf5b629c7a8eaae8ed380c4caccb10c8cd643f3fa3b4eb4287705078d61dfcdc429179843d000c2010d5d1304eabf42b8033
7
+ data.tar.gz: 4b57e61eb048ea6a3ba32aae026acf3344bf296a1c816a2ff32bc9577f78e80631dec57f4caeb6f7265c9f0b52c7b29ed15ea2e0a40459a98dde8dbb6b4472cf
@@ -3,13 +3,15 @@ module Dapp
3
3
  module Dapp
4
4
  module Command
5
5
  module CleanupRepo
6
- GIT_TAGS_LIMIT_POLICY = 10
7
- EXPIRY_DATE_PERIOD_POLICY = 60 * 60 * 24 * 30
6
+ GIT_TAGS_LIMIT_POLICY = 10
7
+ EXPIRY_DATE_PERIOD_POLICY = 60 * 60 * 24 * 30
8
+ GIT_COMMITS_LIMIT_POLICY = 50
9
+ GIT_COMMITS_EXPIRY_DATE_PERIOD_POLICY = 60 * 60 * 24 * 30
8
10
 
9
11
  def cleanup_repo
10
12
  lock_repo(repo = option_repo) do
11
13
  log_step_with_indent(repo) do
12
- log_step_with_indent("Searching for images being used in kubernetes clusters in one of the kube-config contexts") do
14
+ log_step_with_indent('Searching for images being used in kubernetes clusters in one of the kube-config contexts') do
13
15
  deployed_docker_images.each do |deployed_img|
14
16
  log(deployed_img)
15
17
  end
@@ -52,15 +54,13 @@ module Dapp
52
54
 
53
55
  def cleanup_repo_by_nonexistent_git_primitive(registry, detailed_dimgs_images_by_scheme)
54
56
  %w(git_tag git_branch git_commit).each do |scheme|
55
- cleanup_repo_by_nonexistent_git_base(detailed_dimgs_images_by_scheme, scheme) do |detailed_dimg_image|
56
- delete_repo_image(registry, detailed_dimg_image) unless begin
57
- case scheme
58
- when 'git_tag' then consistent_git_tags.include?(detailed_dimg_image[:tag])
59
- when 'git_branch' then consistent_git_remote_branches.include?(detailed_dimg_image[:tag])
60
- when 'git_commit' then git_own_repo.commit_exists?(detailed_dimg_image[:tag])
61
- else
62
- raise
63
- end
57
+ cleanup_repo_by_nonexistent_git_base(registry, detailed_dimgs_images_by_scheme, scheme) do |detailed_dimg_image|
58
+ case scheme
59
+ when 'git_tag' then consistent_git_tags.include?(detailed_dimg_image[:tag])
60
+ when 'git_branch' then consistent_git_remote_branches.include?(detailed_dimg_image[:tag])
61
+ when 'git_commit' then git_own_repo.commit_exists?(detailed_dimg_image[:tag])
62
+ else
63
+ raise
64
64
  end
65
65
  end unless detailed_dimgs_images_by_scheme[scheme].empty?
66
66
  end
@@ -74,56 +74,81 @@ module Dapp
74
74
  @consistent_git_remote_branches ||= git_own_repo.remote_branches.map(&method(:consistent_uniq_slugify))
75
75
  end
76
76
 
77
- def cleanup_repo_by_nonexistent_git_base(repo_dimgs_images_by_scheme, dapp_tag_scheme)
78
- return if repo_dimgs_images_by_scheme[dapp_tag_scheme].empty?
79
- log_step_with_indent(:"nonexistent #{dapp_tag_scheme.split('_').join(' ')}") do
80
- repo_dimgs_images_by_scheme[dapp_tag_scheme]
81
- .select { |dimg_image| dimg_image[:labels]['dapp-tag-scheme'] == dapp_tag_scheme }
82
- .each { |dimg_image| yield dimg_image }
83
- end
77
+ def cleanup_repo_by_nonexistent_git_base(registry, repo_dimgs_images_by_scheme, dapp_tag_scheme)
78
+ nonexist_repo_images = repo_dimgs_images_by_scheme[dapp_tag_scheme]
79
+ .select { |dimg_image| dimg_image[:labels]['dapp-tag-scheme'] == dapp_tag_scheme }
80
+ .select { |dimg_image| !(yield dimg_image) }
81
+
82
+ log_step_with_indent(:"#{dapp_tag_scheme.split('_').join(' ')} nonexistent") do
83
+ nonexist_repo_images.each { |repo_image| delete_repo_image(registry, repo_image) }
84
+ end unless nonexist_repo_images.empty?
84
85
  end
85
86
 
86
87
  def cleanup_repo_by_policies(registry, detailed_dimgs_images_by_scheme)
87
- %w(git_tag git_commit).each_with_object([]) do |scheme, dimgs_images|
88
- dimgs_images.concat begin
89
- detailed_dimgs_images_by_scheme[scheme].select do |dimg|
90
- if scheme == 'git_tag'
91
- consistent_git_tags.include?(dimg[:tag])
92
- elsif scheme == 'git_commit'
93
- git_own_repo.commit_exists?(dimg[:tag])
94
- end
95
- end
96
- end
97
- end.tap do |detailed_dimgs_images|
98
- sorted_detailed_dimgs_images = detailed_dimgs_images.sort_by { |dimg| dimg[:created_at] }.reverse
99
- expired_dimgs_images, not_expired_dimgs_images = sorted_detailed_dimgs_images.partition do |dimg_image|
100
- dimg_image[:created_at] < expiry_date_policy
101
- end
88
+ cleanup_repo_tags_by_policies(registry, detailed_dimgs_images_by_scheme)
89
+ cleanup_repo_commits_by_policies(registry, detailed_dimgs_images_by_scheme)
90
+ end
102
91
 
103
- log_step_with_indent(:"date policy (before #{DateTime.strptime(expiry_date_policy.to_s, '%s')})") do
104
- expired_dimgs_images.each { |dimg| delete_repo_image(registry, dimg) }
105
- end
92
+ def cleanup_repo_tags_by_policies(registry, detailed_dimgs_images_by_scheme)
93
+ cleanup_repo_by_policies_base(
94
+ registry,
95
+ detailed_dimgs_images_by_scheme['git_tag'].select { |dimg| consistent_git_tags.include?(dimg[:tag]) },
96
+ expiry_date_policy: git_tags_expiry_date_policy,
97
+ limit_policy: git_tags_limit_policy,
98
+ log_primitive: 'tag'
99
+ )
100
+ end
106
101
 
107
- {}.tap do |images_by_dimg|
108
- not_expired_dimgs_images.each { |dimg| (images_by_dimg[dimg[:dimg]] ||= []) << dimg }
109
- images_by_dimg.each do |dimg, images|
110
- log_step_with_indent(:"limit policy (> #{git_tag_limit_policy}) (`#{dimg || "nameless"}` dimg)") do
111
- images[git_tag_limit_policy..-1].each { |dimg| delete_repo_image(registry, dimg) }
112
- end unless images[git_tag_limit_policy..-1].nil?
113
- end
102
+ def cleanup_repo_commits_by_policies(registry, detailed_dimgs_images_by_scheme)
103
+ cleanup_repo_by_policies_base(
104
+ registry,
105
+ detailed_dimgs_images_by_scheme['git_commit'].select { |dimg| git_own_repo.commit_exists?(dimg[:tag]) },
106
+ expiry_date_policy: git_commits_expiry_date_policy,
107
+ limit_policy: git_commits_limit_policy,
108
+ log_primitive: 'commit'
109
+ )
110
+ end
111
+
112
+ def cleanup_repo_by_policies_base(registry, detailed_dimgs_images, expiry_date_policy:, limit_policy:, log_primitive:)
113
+ sorted_detailed_dimgs_images = detailed_dimgs_images.sort_by { |dimg| dimg[:created_at] }.reverse
114
+
115
+ expired_dimgs_images, not_expired_dimgs_images = sorted_detailed_dimgs_images.partition do |dimg_image|
116
+ dimg_image[:created_at] < expiry_date_policy
117
+ end
118
+
119
+ log_step_with_indent(:"git #{log_primitive} date policy (before #{DateTime.strptime(expiry_date_policy.to_s, '%s')})") do
120
+ expired_dimgs_images.each { |dimg| delete_repo_image(registry, dimg) }
121
+ end unless expired_dimgs_images.empty?
122
+
123
+ not_expired_dimgs_images
124
+ .each_with_object({}) { |dimg, images_by_dimg| (images_by_dimg[dimg[:dimg]] ||= []) << dimg }
125
+ .each do |dimg_name, images|
126
+ next if images[limit_policy..-1].nil?
127
+ log_step_with_indent(:"git #{log_primitive} limit policy (> #{limit_policy}) (`#{dimg_name || 'nameless'}` dimg)") do
128
+ images[limit_policy..-1].each { |dimg| delete_repo_image(registry, dimg) }
114
129
  end
115
130
  end
116
131
  end
117
132
 
118
- def expiry_date_policy
119
- @expiry_date_policy = begin
120
- expiry_date_period_policy = policy_value('EXPIRY_DATE_PERIOD_POLICY', default: EXPIRY_DATE_PERIOD_POLICY)
121
- Time.now.to_i - expiry_date_period_policy
122
- end
133
+ def git_tags_expiry_date_policy
134
+ @git_tags_expiry_date_policy ||= expiry_date_policy_value('EXPIRY_DATE_PERIOD_POLICY', default: EXPIRY_DATE_PERIOD_POLICY)
135
+ end
136
+
137
+ def git_tags_limit_policy
138
+ @git_tags_limit_policy ||= policy_value('GIT_TAGS_LIMIT_POLICY', default: GIT_TAGS_LIMIT_POLICY)
139
+ end
140
+
141
+ def git_commits_expiry_date_policy
142
+ @git_commits_expiry_date_policy ||= expiry_date_policy_value('GIT_COMMITS_EXPIRY_DATE_PERIOD_POLICY', default: GIT_COMMITS_EXPIRY_DATE_PERIOD_POLICY)
143
+ end
144
+
145
+ def git_commits_limit_policy
146
+ @git_commits_limit_policy ||= policy_value('GIT_COMMITS_LIMIT_POLICY', default: GIT_COMMITS_LIMIT_POLICY)
123
147
  end
124
148
 
125
- def git_tag_limit_policy
126
- @git_tag_limit_policy ||= policy_value('GIT_TAGS_LIMIT_POLICY', default: GIT_TAGS_LIMIT_POLICY)
149
+ def expiry_date_policy_value(env_key, default:)
150
+ expiry_date_period_policy = policy_value(env_key, default: default)
151
+ Time.now.to_i - expiry_date_period_policy
127
152
  end
128
153
 
129
154
  def policy_value(env_key, default:)
data/lib/dapp/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module Dapp
2
- VERSION = "0.32.4"
2
+ VERSION = "0.32.5"
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.32.4
4
+ version: 0.32.5
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-08-30 00:00:00.000000000 Z
11
+ date: 2018-09-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout