Class: DockerRegistry

Inherits:
Object
  • Object
show all
Defined in:
lib/support/docker_registry.rb

Instance Method Summary collapse

Constructor Details

#initialize(registry_url) ⇒ DockerRegistry

Returns a new instance of DockerRegistry.



5
6
7
8
9
10
11
# File 'lib/support/docker_registry.rb', line 5

def initialize(registry_url)
  @server = registry_url
  if (!registry_url.include? "://")
    registry_url = "https://#{registry_url}"
  end
  @connection = connection(registry_url)
end

Instance Method Details

#find_imagesObject



13
14
15
16
17
18
# File 'lib/support/docker_registry.rb', line 13

def find_images()
  response = @connection.get "/v2/_catalog"
  raise "catalog retrieval return error: #{response.status} #{response.body}" if (response.status != 200)
  json = JSON.parse(response.body)
  return json['repositories']
end

#find_tags(image_name) ⇒ Object



20
21
22
23
24
25
# File 'lib/support/docker_registry.rb', line 20

def find_tags(image_name)
  response = @connection.get "/v2/#{image_name}/tags/list"
  raise "Querying tags returned error code: #{response.status}" if (response.status != 200)
  json = JSON.parse(response.body)
  return json['tags']
end

#has_image_with_version?(image, commit_id) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
33
34
35
# File 'lib/support/docker_registry.rb', line 27

def has_image_with_version?(image, commit_id) 
  tags = self.find_tags(image)
  if (tags != nil)
    tags.each do |tag|
      return true if (tag == commit_id)
    end
  end
  return false
end

#images_and_versionsObject



37
38
39
40
41
42
43
44
45
# File 'lib/support/docker_registry.rb', line 37

def images_and_versions
  hash = {}
  images = find_images()
  images.each do |image|
    tags = find_tags(image)
    hash[image] = tags
  end
  return hash
end