dapp 0.33.8 → 0.33.9
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 +4 -4
- data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +76 -51
- data/lib/dapp/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 10261cfd9081894480813cb881199bbb1ce2108b505f0f7083106ca987185373
|
4
|
+
data.tar.gz: 74846658314af31824985a685960dab406b97d8966c95ff1ae4218fdc61a47e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
7
|
-
EXPIRY_DATE_PERIOD_POLICY
|
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(
|
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
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
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
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
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
|
-
|
88
|
-
|
89
|
-
|
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
|
-
|
104
|
-
|
105
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
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
|
119
|
-
@
|
120
|
-
|
121
|
-
|
122
|
-
|
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
|
126
|
-
|
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
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.
|
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-
|
11
|
+
date: 2018-08-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: mixlib-shellout
|