Class: Dapp::Dimg::DockerRegistry::Base

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

Direct Known Subclasses

Default

Defined Under Namespace

Modules: Authorization, Request

Constant Summary collapse

API_VERSION =
'v2'.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Authorization

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

Methods included from Request

included, #raw_request, #request, #url_available?

Constructor Details

#initialize(repo, hostname_url, repo_suffix) ⇒ Base

Returns a new instance of Base.



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

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.



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

def hostname_url
  @hostname_url
end

#repoObject

Returns the value of attribute repo.



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

def repo
  @repo
end

#repo_suffixObject

Returns the value of attribute repo_suffix.



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

def repo_suffix
  @repo_suffix
end

Instance Method Details

#image_delete(tag) ⇒ Object



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

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



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

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

#image_id(tag) ⇒ Object



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

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

#image_labels(tag) ⇒ Object



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

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

#image_parent_id(tag) ⇒ Object



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

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

#repo_exist?Boolean

Returns:

  • (Boolean)


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

def repo_exist?
  tags.any?
end

#tagsObject



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

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