dapp 0.32.10 → 0.33.0
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/bin/dapp +1 -23
- data/config/en/net_status.yml +7 -0
- data/lib/dapp.rb +3 -3
- data/lib/dapp/dapp.rb +13 -0
- data/lib/dapp/dapp/dappfile.rb +2 -2
- data/lib/dapp/dapp/deps/base.rb +5 -37
- data/lib/dapp/dapp/deps/common.rb +25 -0
- data/lib/dapp/dapp/deps/gitartifact.rb +2 -25
- data/lib/dapp/dapp/deps/toolchain.rb +1 -23
- data/lib/dapp/dapp/logging/base.rb +3 -3
- data/lib/dapp/dapp/ruby2go.rb +96 -0
- data/lib/dapp/dapp/sentry.rb +0 -1
- data/lib/dapp/dapp/shellout/base.rb +4 -2
- data/lib/dapp/dimg/build/stage/artifact_base.rb +7 -6
- data/lib/dapp/dimg/build/stage/base.rb +37 -7
- data/lib/dapp/dimg/build/stage/from.rb +1 -1
- data/lib/dapp/dimg/builder/ansible.rb +1 -209
- data/lib/dapp/dimg/builder/base.rb +0 -5
- data/lib/dapp/dimg/builder/none.rb +1 -34
- data/lib/dapp/dimg/builder/ruby2go.rb +51 -0
- data/lib/dapp/dimg/builder/shell.rb +1 -25
- data/lib/dapp/dimg/cli/command/dimg/bp.rb +10 -15
- data/lib/dapp/dimg/cli/command/dimg/build.rb +0 -5
- data/lib/dapp/dimg/config/directive/docker/base.rb +1 -1
- data/lib/dapp/dimg/dapp/command/build_context/export.rb +1 -1
- data/lib/dapp/dimg/dapp/command/build_context/import.rb +1 -1
- data/lib/dapp/dimg/dapp/command/cleanup_repo.rb +59 -90
- data/lib/dapp/dimg/dapp/command/common.rb +60 -74
- data/lib/dapp/dimg/dapp/command/mrproper.rb +2 -17
- data/lib/dapp/dimg/dapp/command/stages/cleanup_local.rb +9 -6
- data/lib/dapp/dimg/dimg.rb +26 -43
- data/lib/dapp/dimg/docker_registry/base/authorization.rb +1 -16
- data/lib/dapp/dimg/git_artifact.rb +142 -21
- data/lib/dapp/dimg/git_repo/base.rb +11 -0
- data/lib/dapp/dimg/git_repo/local.rb +14 -0
- data/lib/dapp/dimg/git_repo/remote.rb +25 -34
- data/lib/dapp/dimg/image/argument.rb +12 -58
- data/lib/dapp/dimg/image/stage.rb +202 -43
- data/lib/dapp/kube/kubernetes/client.rb +0 -6
- data/lib/dapp/kube/kubernetes/manager/deployment.rb +18 -30
- data/lib/dapp/version.rb +1 -1
- metadata +8 -8
- data/lib/dapp/dimg/builder/ansible/assets.rb +0 -349
- data/lib/dapp/dimg/exception/introspect_image.rb +0 -7
- data/lib/dapp/dimg/image/docker.rb +0 -144
@@ -1,29 +1,5 @@
|
|
1
1
|
module Dapp
|
2
2
|
module Dimg
|
3
|
-
class Builder::Shell < Builder::
|
4
|
-
[:before_install, :before_setup, :install, :setup, :build_artifact].each do |stage|
|
5
|
-
define_method("#{stage}_checksum") do
|
6
|
-
_checksum(
|
7
|
-
dimg.config._shell.public_send("_#{stage}_command"),
|
8
|
-
public_send("#{stage}_version_checksum")
|
9
|
-
)
|
10
|
-
end
|
11
|
-
define_method("#{stage}_version_checksum") do
|
12
|
-
_checksum(dimg.config._shell.public_send("_#{stage}_version"), dimg.config._shell._version)
|
13
|
-
end
|
14
|
-
define_method("#{stage}?") { !stage_empty?(stage) }
|
15
|
-
define_method(stage.to_s) do |image|
|
16
|
-
image.add_command(*stage_commands(stage)) unless stage_empty?(stage)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
def stage_empty?(stage)
|
21
|
-
stage_commands(stage).empty? && public_send("#{stage}_version_checksum").nil?
|
22
|
-
end
|
23
|
-
|
24
|
-
def stage_commands(stage)
|
25
|
-
dimg.config._shell.public_send("_#{stage}_command")
|
26
|
-
end
|
27
|
-
end # Builder::Shell
|
3
|
+
class Builder::Shell < Builder::Ruby2Go; end
|
28
4
|
end # Dimg
|
29
5
|
end # Dapp
|
@@ -19,27 +19,22 @@ BANNER
|
|
19
19
|
extend ::Dapp::CLI::Options::Ssh
|
20
20
|
|
21
21
|
option :tmp_dir_prefix,
|
22
|
-
|
23
|
-
|
22
|
+
long: '--tmp-dir-prefix PREFIX',
|
23
|
+
description: 'Tmp directory prefix (/tmp by default). Used for build process service directories.'
|
24
24
|
|
25
25
|
option :lock_timeout,
|
26
|
-
|
27
|
-
|
28
|
-
|
26
|
+
long: '--lock-timeout TIMEOUT',
|
27
|
+
description: 'Redefine resource locking timeout (in seconds)',
|
28
|
+
proc: ->(v) { v.to_i }
|
29
29
|
|
30
30
|
option :build_context_directory,
|
31
|
-
|
32
|
-
|
31
|
+
long: '--build-context-directory DIR_PATH',
|
32
|
+
default: nil
|
33
33
|
|
34
34
|
option :use_system_tar,
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
option :force_save_cache,
|
40
|
-
long: '--force-save-cache',
|
41
|
-
boolean: true,
|
42
|
-
default: false
|
35
|
+
long: '--use-system-tar',
|
36
|
+
boolean: true,
|
37
|
+
default: false
|
43
38
|
|
44
39
|
# push options
|
45
40
|
|
@@ -9,7 +9,7 @@ module Dapp
|
|
9
9
|
def from(image, cache_version: nil)
|
10
10
|
sub_directive_eval do
|
11
11
|
image = image.to_s
|
12
|
-
raise(::Dapp::Error::Config, code: :docker_from_incorrect, data: { name: image }) unless ::Dapp::Dimg::Image::
|
12
|
+
raise(::Dapp::Error::Config, code: :docker_from_incorrect, data: { name: image }) unless ::Dapp::Dimg::Image::Stage.image_name?(image)
|
13
13
|
@_from = image.include?(':') ? image : [image, 'latest'].join(':')
|
14
14
|
@_from_cache_version = cache_version
|
15
15
|
end
|
@@ -18,7 +18,7 @@ module Dapp
|
|
18
18
|
end.flatten
|
19
19
|
|
20
20
|
log_secondary_process(:images, short: true) do
|
21
|
-
Image::
|
21
|
+
Image::Stage.save!(self, context_images_names, build_context_images_tar, verbose: true, quiet: log_quiet?) unless dry_run?
|
22
22
|
end unless context_images_names.empty?
|
23
23
|
end
|
24
24
|
end
|
@@ -18,7 +18,7 @@ module Dapp
|
|
18
18
|
if build_context_images_tar.exist?
|
19
19
|
log_secondary_process(:images) do
|
20
20
|
lock("#{name}.images") do
|
21
|
-
Image::
|
21
|
+
Image::Stage.load!(self, build_context_images_tar, verbose: true, quiet: log_quiet?)
|
22
22
|
end unless dry_run?
|
23
23
|
end
|
24
24
|
else
|
@@ -3,15 +3,13 @@ module Dapp
|
|
3
3
|
module Dapp
|
4
4
|
module Command
|
5
5
|
module CleanupRepo
|
6
|
-
GIT_TAGS_LIMIT_POLICY
|
7
|
-
EXPIRY_DATE_PERIOD_POLICY
|
8
|
-
GIT_COMMITS_LIMIT_POLICY = 50
|
9
|
-
GIT_COMMITS_EXPIRY_DATE_PERIOD_POLICY = 60 * 60 * 24 * 30
|
6
|
+
GIT_TAGS_LIMIT_POLICY = 10
|
7
|
+
EXPIRY_DATE_PERIOD_POLICY = 60 * 60 * 24 * 30
|
10
8
|
|
11
9
|
def cleanup_repo
|
12
10
|
lock_repo(repo = option_repo) do
|
13
11
|
log_step_with_indent(repo) do
|
14
|
-
log_step_with_indent(
|
12
|
+
log_step_with_indent("Searching for images being used in kubernetes clusters in one of the kube-config contexts") do
|
15
13
|
deployed_docker_images.each do |deployed_img|
|
16
14
|
log(deployed_img)
|
17
15
|
end
|
@@ -54,13 +52,15 @@ module Dapp
|
|
54
52
|
|
55
53
|
def cleanup_repo_by_nonexistent_git_primitive(registry, detailed_dimgs_images_by_scheme)
|
56
54
|
%w(git_tag git_branch git_commit).each do |scheme|
|
57
|
-
cleanup_repo_by_nonexistent_git_base(
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
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
|
64
64
|
end
|
65
65
|
end unless detailed_dimgs_images_by_scheme[scheme].empty?
|
66
66
|
end
|
@@ -74,81 +74,56 @@ 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(
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
end unless nonexist_repo_images.empty?
|
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
|
85
84
|
end
|
86
85
|
|
87
86
|
def cleanup_repo_by_policies(registry, detailed_dimgs_images_by_scheme)
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
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
|
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
|
118
102
|
|
119
|
-
|
120
|
-
|
121
|
-
|
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
|
122
106
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
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
|
129
114
|
end
|
130
115
|
end
|
131
116
|
end
|
132
117
|
|
133
|
-
def
|
134
|
-
@
|
135
|
-
|
136
|
-
|
137
|
-
|
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)
|
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
|
147
123
|
end
|
148
124
|
|
149
|
-
def
|
150
|
-
|
151
|
-
Time.now.to_i - expiry_date_period_policy
|
125
|
+
def git_tag_limit_policy
|
126
|
+
@git_tag_limit_policy ||= policy_value('GIT_TAGS_LIMIT_POLICY', default: GIT_TAGS_LIMIT_POLICY)
|
152
127
|
end
|
153
128
|
|
154
129
|
def policy_value(env_key, default:)
|
@@ -225,65 +200,59 @@ module Dapp
|
|
225
200
|
# pod items[] spec containers[] image
|
226
201
|
def pod_images(client)
|
227
202
|
client.pod_list['items'].map do |item|
|
228
|
-
|
203
|
+
item['spec']['containers'].map{ |cont| cont['image'] }
|
229
204
|
end
|
230
205
|
end
|
231
206
|
|
232
207
|
# cronjob items[] spec jobTemplate spec template spec containers[] image
|
233
208
|
def cronjob_images(client)
|
234
209
|
client.cronjob_list['items'].map do |item|
|
235
|
-
|
210
|
+
item['spec']['jobTemplate']['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
236
211
|
end
|
237
212
|
end
|
238
213
|
|
239
214
|
# daemonsets items[] spec template spec containers[] image
|
240
215
|
def daemonset_images(client)
|
241
216
|
client.daemonset_list['items'].map do |item|
|
242
|
-
|
217
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
243
218
|
end
|
244
219
|
end
|
245
220
|
|
246
221
|
# deployment items[] spec template spec containers[] image
|
247
222
|
def deployment_images(client)
|
248
223
|
client.deployment_list['items'].map do |item|
|
249
|
-
|
224
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
250
225
|
end
|
251
226
|
end
|
252
227
|
|
253
228
|
# job items[] spec template spec containers[] image
|
254
229
|
def job_images(client)
|
255
230
|
client.job_list['items'].map do |item|
|
256
|
-
|
231
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
257
232
|
end
|
258
233
|
end
|
259
234
|
|
260
235
|
# replicasets items[] spec template spec containers[] image
|
261
236
|
def replicaset_images(client)
|
262
237
|
client.replicaset_list['items'].map do |item|
|
263
|
-
|
238
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
264
239
|
end
|
265
240
|
end
|
266
241
|
|
267
242
|
# replicasets items[] spec template spec containers[] image
|
268
243
|
def statefulset_images(client)
|
269
244
|
client.statefulset_list['items'].map do |item|
|
270
|
-
|
245
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
271
246
|
end
|
272
247
|
end
|
273
248
|
|
274
249
|
# replicationcontroller items[] spec template spec containers[] image
|
275
250
|
def replicationcontroller_images(client)
|
276
251
|
client.replicationcontroller_list['items'].map do |item|
|
277
|
-
|
252
|
+
item['spec']['template']['spec']['containers'].map{ |cont| cont['image'] }
|
278
253
|
end
|
279
254
|
end
|
280
255
|
|
281
|
-
def images_from_pod_spec(pod_spec)
|
282
|
-
containers = Array(pod_spec['spec']['containers'])
|
283
|
-
initContainers = Array(pod_spec['spec']['initContainers'])
|
284
|
-
(containers + initContainers).map { |cont| cont['image'] }
|
285
|
-
end
|
286
|
-
|
287
256
|
def without_kube?
|
288
257
|
!!options[:without_kube]
|
289
258
|
end
|
@@ -18,41 +18,48 @@ module Dapp
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def dapp_project_image_by_id(image_id)
|
21
|
-
dapp_project_images.find { |image| image[
|
22
|
-
end
|
23
|
-
|
24
|
-
def dapp_project_image_labels(image)
|
25
|
-
dapp_project_image_inspect(image)['Config']['Labels']
|
26
|
-
end
|
27
|
-
|
28
|
-
def dapp_project_image_inspect(image)
|
29
|
-
image[:inspect] ||= begin
|
30
|
-
cmd = shellout!("#{::Dapp::Dapp.host_docker} inspect --type=image #{image[:id]}")
|
31
|
-
Array(JSON.parse(cmd.stdout.strip)).first || {}
|
32
|
-
end
|
21
|
+
dapp_project_images.find { |image| image["Id"] == image_id }
|
33
22
|
end
|
34
23
|
|
35
24
|
def dapp_project_images
|
36
25
|
@dapp_project_images ||= [].tap do |images|
|
37
|
-
images.concat prepare_docker_images(stage_cache, dimgstage: true)
|
38
|
-
images.concat prepare_docker_images(
|
26
|
+
images.concat prepare_docker_images(extra_filters: [{ reference: stage_cache }], extra_image_fields: { dimgstage: true })
|
27
|
+
images.concat prepare_docker_images(extra_filters: [{ label: "dapp-dimg=true" }], extra_image_fields: { dimg: true })
|
39
28
|
end
|
40
29
|
end
|
41
30
|
|
42
|
-
def prepare_docker_images(
|
43
|
-
[]
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
31
|
+
def prepare_docker_images(extra_filters: [], extra_image_fields: {})
|
32
|
+
filters = []
|
33
|
+
filters << { dangling: "false" }
|
34
|
+
filters << { label: "dapp=#{name}" }
|
35
|
+
filters.concat(extra_filters)
|
36
|
+
|
37
|
+
ruby2go_image_images(filters, ignore_tagless: true).map { |image| image.merge(**extra_image_fields) }
|
38
|
+
end
|
39
|
+
|
40
|
+
def ruby2go_image_images(filters, ignore_tagless:)
|
41
|
+
Image::Stage.ruby2go_command(self, command: :images, options: { filters: filters }).tap do |images|
|
42
|
+
if ignore_tagless
|
43
|
+
break images.select do |image|
|
44
|
+
image["RepoTags"].reject! { |tag| tag.split(":").last == '<none>' }
|
45
|
+
!image["RepoTags"].empty?
|
46
|
+
end
|
52
47
|
end
|
53
48
|
end
|
54
49
|
end
|
55
50
|
|
51
|
+
def ruby2go_image_containers(filters)
|
52
|
+
Image::Stage.ruby2go_command(self, command: :containers, options: { filters: filters })
|
53
|
+
end
|
54
|
+
|
55
|
+
def ruby2go_image_rm(ids, force: false)
|
56
|
+
Image::Stage.ruby2go_command(self, command: :rm, options: { ids: ids, force: force })
|
57
|
+
end
|
58
|
+
|
59
|
+
def ruby2go_image_rmi(ids, force: false)
|
60
|
+
Image::Stage.ruby2go_command(self, command: :rmi, options: { ids: ids, force: force })
|
61
|
+
end
|
62
|
+
|
56
63
|
def remove_project_images(project_images, force: false)
|
57
64
|
update_project_images_cache(project_images)
|
58
65
|
remove_images(project_images_to_delete(project_images), force: force)
|
@@ -63,49 +70,51 @@ module Dapp
|
|
63
70
|
end
|
64
71
|
|
65
72
|
def array_hash_delete_if_by_id(project_images, *images)
|
66
|
-
project_images.delete_if { |image| images.flatten.any? { |i| image[
|
73
|
+
project_images.delete_if { |image| images.flatten.any? { |i| image["Id"] == i["Id"] } }
|
67
74
|
end
|
68
75
|
|
69
76
|
def project_images_to_delete(project_images)
|
70
|
-
project_images.map { |
|
77
|
+
project_images.map { |i| i["RepoTags"] }.flatten.uniq
|
71
78
|
end
|
72
79
|
|
73
80
|
def dapp_containers_flush_by_label(label)
|
74
81
|
log_proper_containers do
|
75
|
-
|
82
|
+
containers = ruby2go_image_containers([{ name: "dapp.build.", label: label }])
|
83
|
+
remove_containers(containers.map { |c| c["Id"] })
|
76
84
|
end
|
77
85
|
end
|
78
86
|
|
79
87
|
def dapp_dangling_images_flush_by_label(label)
|
80
88
|
log_proper_flush_dangling_images do
|
81
|
-
|
89
|
+
images = ruby2go_image_images([{ dangling: "true", label: label }], ignore_tagless: false)
|
90
|
+
remove_images(images.map { |i| i["Id"] })
|
82
91
|
end
|
83
92
|
end
|
84
93
|
|
85
94
|
def dapp_tagless_images_flush
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
95
|
+
remove_images begin
|
96
|
+
ruby2go_image_images([{ dangling: "false", label: "dapp" }], ignore_tagless: false)
|
97
|
+
.map { |image| image["RepoTags"].select { |tag| tag.split(":").last == "<none>" } }
|
98
|
+
.flatten
|
99
|
+
end
|
91
100
|
end
|
92
101
|
|
93
102
|
def remove_images(images_ids_or_names, force: false)
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
end
|
103
|
+
proc = proc { |refs| ruby2go_image_rmi(refs, force: force) }
|
104
|
+
images_ids_or_names = ignore_used_images(images_ids_or_names) unless force
|
105
|
+
remove_base(images_ids_or_names, proc: proc)
|
98
106
|
end
|
99
107
|
|
100
108
|
def ignore_used_images(images_ids_or_names)
|
101
109
|
not_used_images = proc do |*image_id_or_name, log: true|
|
102
|
-
images
|
103
|
-
filters
|
104
|
-
|
105
|
-
|
110
|
+
images = image_id_or_name.flatten
|
111
|
+
filters = images.map { |ref| { ancestor: ref } }
|
112
|
+
|
113
|
+
containers = ruby2go_image_containers(filters).select { |c| images.include?(c["Image"]) || images.include?(c["ImageID"]) } # ancestor filter matches containers based on its image or a descendant of it
|
114
|
+
if containers.empty?
|
106
115
|
true
|
107
116
|
else
|
108
|
-
log_info("Skip `#{images.join('`, `')}` (used by containers: #{
|
117
|
+
log_info("Skip `#{images.join('`, `')}` (used by containers: #{ containers.map { |c| c["Id"] }.join(' ')})") if log
|
109
118
|
false
|
110
119
|
end
|
111
120
|
end
|
@@ -117,35 +126,16 @@ module Dapp
|
|
117
126
|
end
|
118
127
|
end
|
119
128
|
|
120
|
-
def remove_containers_by_query(containers_query)
|
121
|
-
with_subquery(containers_query) { |ids| remove_containers(ids) }
|
122
|
-
end
|
123
|
-
|
124
129
|
def remove_containers(ids)
|
125
|
-
|
126
|
-
|
127
|
-
end
|
130
|
+
proc = proc { |refs| ruby2go_image_rm(refs, force: true) }
|
131
|
+
remove_base(ids, proc: proc)
|
128
132
|
end
|
129
133
|
|
130
|
-
def
|
131
|
-
return
|
132
|
-
ids.uniq
|
133
|
-
|
134
|
-
|
135
|
-
def remove_base(query_format, ids, force: false)
|
136
|
-
return if ids.empty?
|
137
|
-
force_option = force ? ' -f' : ''
|
138
|
-
log(ids.join("\n")) if log_verbose? || dry_run?
|
139
|
-
run_command(format(query_format, force_option: force_option, ids: ids.join(' ')))
|
140
|
-
end
|
141
|
-
|
142
|
-
def with_subquery(query)
|
143
|
-
return if (res = shellout!(query).stdout.strip.lines.map(&:strip)).empty?
|
144
|
-
yield(res)
|
145
|
-
end
|
146
|
-
|
147
|
-
def run_command(cmd)
|
148
|
-
shellout!(cmd) unless dry_run?
|
134
|
+
def remove_base(ids, proc:)
|
135
|
+
return if ids.empty?
|
136
|
+
ids.uniq!
|
137
|
+
log(ids.join("\n")) if dry_run?
|
138
|
+
proc.call(ids) unless dry_run?
|
149
139
|
end
|
150
140
|
|
151
141
|
def dimg_import_export_base(should_be_built: true)
|
@@ -158,20 +148,16 @@ module Dapp
|
|
158
148
|
end
|
159
149
|
end
|
160
150
|
|
161
|
-
def container_name_prefix
|
162
|
-
name
|
163
|
-
end
|
164
|
-
|
165
151
|
def validate_repo_name!(repo)
|
166
152
|
raise ::Dapp::Error::Command, code: :repo_name_incorrect, data: { name: repo } unless ::Dapp::Dimg::DockerRegistry.repo_name?(repo)
|
167
153
|
end
|
168
154
|
|
169
155
|
def validate_image_name!(image)
|
170
|
-
raise ::Dapp::Error::Command, code: :image_name_incorrect, data: { name: image } unless ::Dapp::Dimg::Image::
|
156
|
+
raise ::Dapp::Error::Command, code: :image_name_incorrect, data: { name: image } unless ::Dapp::Dimg::Image::Stage.image_name?(image)
|
171
157
|
end
|
172
158
|
|
173
159
|
def validate_tag_name!(tag)
|
174
|
-
raise ::Dapp::Error::Command, code: :tag_name_incorrect, data: { name: tag } unless ::Dapp::Dimg::Image::
|
160
|
+
raise ::Dapp::Error::Command, code: :tag_name_incorrect, data: { name: tag } unless ::Dapp::Dimg::Image::Stage.tag?(tag)
|
175
161
|
end
|
176
162
|
|
177
163
|
def proper_cache_version?
|