Class: Drydock::ImageRepository

Inherits:
Object
  • Object
show all
Extended by:
Enumerable
Defined in:
lib/drydock/image_repository.rb

Class Method Summary collapse

Class Method Details

.allObject



11
12
13
14
15
16
17
18
19
20
21
# File 'lib/drydock/image_repository.rb', line 11

def self.all
  image_count = @image_cache.size
  Docker::Image.all(all: 1).map do |image|
    @image_cache[image.id] ||= Docker::Image.get(image.id)
  end
ensure
  delta_count = @image_cache.size - image_count
  if delta_count > 0
    Drydock.logger.info(message: "Loaded metadata for #{delta_count} images from docker cache")
  end
end

.danglingObject



23
24
25
26
# File 'lib/drydock/image_repository.rb', line 23

def self.dangling
  filters = {dangling: ["true"]}
  Docker::Image.all(filters: filters.to_json)
end

.each(&blk) ⇒ Object



28
29
30
# File 'lib/drydock/image_repository.rb', line 28

def self.each(&blk)
  self.all.each(&blk)
end

.find_by_config(config) ⇒ Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/drydock/image_repository.rb', line 32

def self.find_by_config(config)
  base_image = config['Image']
  candidates = self.select_by_config(config)

  possibles = candidates.select do |image|
    image.info['Parent'] == base_image || image.info['ContainerConfig']['Image'] == base_image
  end

  possibles.sort_by { |image| image.info['Created'] }.last
end

.select_by_config(config) ⇒ Object



43
44
45
46
47
# File 'lib/drydock/image_repository.rb', line 43

def self.select_by_config(config)
  # we want to look at 'ContainerConfig', because we're interesting in how
  # the image was built, not how the image will run
  self.select { |image| config == ContainerConfig.from(image.info['ContainerConfig']) }
end