dapp 0.33.8 → 0.33.9

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: e85caf6f03db8577e8958185b533f4198c0a4390f7947652809cb2c099049780
4
- data.tar.gz: 4354a1a48e36ab0652829dc768d6a58f2170ff94537a26503575680ed77416d7
3
+ metadata.gz: 10261cfd9081894480813cb881199bbb1ce2108b505f0f7083106ca987185373
4
+ data.tar.gz: 74846658314af31824985a685960dab406b97d8966c95ff1ae4218fdc61a47e1
5
5
  SHA512:
6
- metadata.gz: 126320c0079f5a19e9baaf21e32265d330c6a988ac8d07881cd469adf2a04a31b004e843b4f6592ea4723dbdaa7594281292672f7e98225abb2d313994125d88
7
- data.tar.gz: 335b681aaf58931f4a5d0fa4e3a4a91d6c158bbbef37ff7933d09d724ffc2dd65bb8aa1a5149ea9fa451842ad6099cc9e662d6ea96a0e76e6db0c5905b35b7f3
6
+ metadata.gz: 929567fd1eef6a4c3ede8ca0c9e8b3faf9627f0ee352d22ec8f6b028f652b32dca4c334cadb1762abe7c146f4de723538e0504104ece86834623b6558e8a7124
7
+ data.tar.gz: 854c78c21167d1097c374e8f63d50443e30e86a8bf60bc84effea5f220ea80a19ca97f9c7cb26e2a1062d2fac3329b147ee3e866e259e2678236775bc68cdaca
@@ -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.33.8"
2
+ VERSION = "0.33.9"
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.33.8
4
+ version: 0.33.9
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-24 00:00:00.000000000 Z
11
+ date: 2018-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-shellout