27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/dockerun/command/reset_image.rb', line 27
def run(&block)
if params[:help]
print help
exit(0)
else
config = ::Dockerun::Config.from_storage
if config.isConfigFileAvail?
skip = cli.no?("Reset docker image (together with the relative container) ? ")
if not skip
selImg = nil
if is_empty?(config.image_names)
STDOUT.puts "No image found"
elsif config.image_names.length == 1
selImg = config.image_names.first
else
selImg = cli.select("Please select which image you want to reset : ") do |m|
config.image_names.each do |n|
m.choice n,n
end
end
end
if not selImg.nil?
config.container_names(selImg).each do |cn|
dcFact.stop_container(cn).run
dcFact.delete_container(cn).run
end
STDOUT.puts "#{config.container_names(selImg).length} container(s) from image '#{selImg}' deleted"
res = dcFact.delete_image(selImg).run
if not res.failed?
STDOUT.puts "Image '#{selImg}' successfully deleted."
config.remove_image(selImg)
config.to_storage
STDOUT.puts "Image '#{selImg}' removed from history file"
else
STDERR.puts "Image '#{selImg}' deletion failed. Error was : #{res.err_stream}"
removeFromHist = cli.yes?("Image '#{selImg}' failed. Do you want to remove from the history file?")
if removeFromHist
config.remove_image(selImg)
config.to_storage
STDOUT.puts "Image '#{selImg}' removed from history file"
else
STDOUT.puts "Image '#{selImg}' shall remain in the history file"
end
end
end
if is_empty?(config.image_names)
::Dockerun::Config.remove
STDOUT.puts "Dockerun workspace config removed"
end
else
STDOUT.puts "Reset docker image operation aborted"
end
else
STDOUT.puts "Not a dockerun workspace"
end
end
end
|