Class: Armada::Clean::Images

Inherits:
Object
  • Object
show all
Defined in:
lib/armada/clean/images.rb

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Images

Returns a new instance of Images.



4
5
6
7
8
9
# File 'lib/armada/clean/images.rb', line 4

def initialize(options)
  @hosts   = options[:hosts]
  @force   = options[:force]
  @noprune = !options[:prune]
  @options = options
end

Instance Method Details

#runObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/armada/clean/images.rb', line 11

def run
  Armada.ui.info "******* DRY RUN *******" unless @force
  @hosts.each_in_parallel do |host|
    docker_host = Armada::Host.create(host, @options)
    docker_host.get_all_images.each do |image|
      if image.info["RepoTags"].include?("<none>:<none>")
        begin
          Armada.ui.info "#{docker_host.host} -- #{image.id[0..11]} is an abandoned image and will be removed"
          image.remove({:force => true, :noprune => @noprune}) if @force
        rescue Exception => e
          Armada.ui.error "#{docker_host.host} -- unable to remove image #{image.id[0..11]} because of the following error - #{e.message}"
        end
      end
    end
  end
end