Class: Dapp::DockerRegistry::Base

Inherits:
Object
  • Object
show all
Includes:
Mod::Authorization, Mod::Request
Defined in:
lib/dapp/docker_registry/base.rb

Overview

Base

Direct Known Subclasses

Default

Constant Summary collapse

API_VERSION =
'v2'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Mod::Authorization

#authorization_auth, #authorization_options, #authorization_token, #auths_section_from_docker_config, #parse_authenticate_header

Methods included from Mod::Request

#raw_request, #request, #url_available?

Constructor Details

#initialize(repo, hostname_url, repo_suffix) ⇒ Base

Returns a new instance of Base.



15
16
17
18
19
# File 'lib/dapp/docker_registry/base.rb', line 15

def initialize(repo, hostname_url, repo_suffix)
  self.repo = repo
  self.hostname_url = hostname_url
  self.repo_suffix = repo_suffix
end

Instance Attribute Details

#hostname_urlObject

Returns the value of attribute hostname_url.



12
13
14
# File 'lib/dapp/docker_registry/base.rb', line 12

def hostname_url
  @hostname_url
end

#repoObject

Returns the value of attribute repo.



11
12
13
# File 'lib/dapp/docker_registry/base.rb', line 11

def repo
  @repo
end

#repo_suffixObject

Returns the value of attribute repo_suffix.



13
14
15
# File 'lib/dapp/docker_registry/base.rb', line 13

def repo_suffix
  @repo_suffix
end

Instance Method Details

#image_delete(tag) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/dapp/docker_registry/base.rb', line 45

def image_delete(tag)
  image_blobs(tag).each { |hash| blob_delete(hash.values.first) }
  api_request(repo_suffix, "/manifests/#{image_digest(tag)}",
              method: :delete,
              expects: [202, 404],
              headers: { Accept: 'Accept: application/vnd.docker.distribution.manifest.v2+json' })
end

#image_history(tag) ⇒ Object



53
54
55
56
# File 'lib/dapp/docker_registry/base.rb', line 53

def image_history(tag)
  response = manifest_v1(tag)
  JSON.load(response['history'].first['v1Compatibility'])
end

#image_id(tag) ⇒ Object



32
33
34
35
# File 'lib/dapp/docker_registry/base.rb', line 32

def image_id(tag)
  response = manifest_v2(tag)
  response['config']['digest'] if response['schemaVersion'] == 2
end

#image_labels(tag) ⇒ Object



41
42
43
# File 'lib/dapp/docker_registry/base.rb', line 41

def image_labels(tag)
  image_history(tag)['config']['Labels']
end

#image_parent_id(tag) ⇒ Object



37
38
39
# File 'lib/dapp/docker_registry/base.rb', line 37

def image_parent_id(tag)
  image_history(tag)['container_config']['Image']
end

#repo_exist?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/dapp/docker_registry/base.rb', line 21

def repo_exist?
  tags.any?
end

#tagsObject



25
26
27
28
29
30
# File 'lib/dapp/docker_registry/base.rb', line 25

def tags
  @tags ||= api_request(repo_suffix, 'tags/list')['tags'] || []
rescue Error::Registry => e
  raise Exception::Registry, code: :no_such_dimg, data: { registry: api_url } if e.net_status[:code] == :page_not_found
  raise
end