Class: Centurion::DockerRegistry
- Inherits:
-
Object
- Object
- Centurion::DockerRegistry
- Defined in:
- lib/centurion/docker_registry.rb
Constant Summary collapse
- OFFICIAL_URL =
'https://registry.hub.docker.com'
Instance Method Summary collapse
- #digest_for_tag(repository, tag) ⇒ Object
-
#initialize(base_uri, registry_user = nil, registry_password = nil) ⇒ DockerRegistry
constructor
A new instance of DockerRegistry.
- #repository_tags(repository) ⇒ Object
Constructor Details
#initialize(base_uri, registry_user = nil, registry_password = nil) ⇒ DockerRegistry
Returns a new instance of DockerRegistry.
10 11 12 13 14 |
# File 'lib/centurion/docker_registry.rb', line 10 def initialize(base_uri, registry_user=nil, registry_password=nil) @base_uri = base_uri @user = registry_user @password = registry_password end |
Instance Method Details
#digest_for_tag(repository, tag) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/centurion/docker_registry.rb', line 16 def digest_for_tag(repository, tag) path = "/v1/repositories/#{repository}/tags/#{tag}" uri = uri_for_repository_path(repository, path) $stderr.puts "GET: #{uri}" = { headers: { "Content-Type" => "application/json" } } if @user [:user] = @user [:password] = @password end response = Excon.get( uri, ) raise response.inspect unless response.status == 200 # This hack is stupid, and I hate it. But it works around the fact that # the Docker Registry will return a base JSON String, which the Ruby parser # refuses (possibly correctly) to handle JSON.load('[' + response.body + ']').first end |
#repository_tags(repository) ⇒ Object
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 |
# File 'lib/centurion/docker_registry.rb', line 37 def (repository) path = "/v1/repositories/#{repository}/tags" uri = uri_for_repository_path(repository, path) $stderr.puts "GET: #{uri.inspect}" # Need to workaround a bug in Docker Hub to now pass port in Host header = { omit_default_port: true } if @user [:user] = @user [:password] = @password end response = Excon.get(uri, ) raise response.inspect unless response.status == 200 = JSON.load(response.body) # The Docker Registry API[1] specifies a result in the format # { "[tag]" : "[image_id]" }. However, the official Docker registry returns a # result like [{ "layer": "[image_id]", "name": "[tag]" }]. # # So, we need to normalize the response to what the Docker Registry API # specifies should be returned. # # [1]: https://docs.docker.com/v1.1/reference/api/registry_api/ if is_official_registry?(repository) .each_with_object({}) do |tag, hash| hash[tag['name']] = tag['layer'] end else end end |