diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/container_registry/blob.rb | 10 | ||||
-rw-r--r-- | lib/container_registry/client.rb | 8 | ||||
-rw-r--r-- | lib/container_registry/registry.rb | 2 | ||||
-rw-r--r-- | lib/container_registry/repository.rb | 28 | ||||
-rw-r--r-- | lib/container_registry/tag.rb | 20 |
5 files changed, 14 insertions, 54 deletions
diff --git a/lib/container_registry/blob.rb b/lib/container_registry/blob.rb index d59792a383e..4e20dc4f875 100644 --- a/lib/container_registry/blob.rb +++ b/lib/container_registry/blob.rb @@ -2,6 +2,8 @@ module ContainerRegistry class Blob attr_reader :repository, :config + delegate :registry, :client, to: :repository + def initialize(repository, config) @repository = repository @config = config || {} @@ -35,10 +37,6 @@ module ContainerRegistry revision[0..8] end - def client - @client ||= repository.client - end - def delete client.delete_blob(repository.name, digest) end @@ -46,9 +44,5 @@ module ContainerRegistry def data @data ||= client.blob(repository.name, digest, type) end - - def mount_to(to_repository) - client.repository_mount_blob(to_repository.name, digest, repository.name) - end end end diff --git a/lib/container_registry/client.rb b/lib/container_registry/client.rb index c250a4b6946..4d726692f45 100644 --- a/lib/container_registry/client.rb +++ b/lib/container_registry/client.rb @@ -22,14 +22,6 @@ module ContainerRegistry @faraday.get("/v2/#{name}/manifests/#{reference}").body end - def put_repository_manifest(name, reference, manifest) - @faraday.put("/v2/#{name}/manifests/#{reference}", manifest, { "Content-Type" => MANIFEST_VERSION }).success? - end - - def repository_mount_blob(name, digest, from) - @faraday.post("/v2/#{name}/blobs/uploads/?mount=#{digest}&from=#{from}").status == 201 - end - def repository_tag_digest(name, reference) response = @faraday.head("/v2/#{name}/manifests/#{reference}") response.headers['docker-content-digest'] if response.success? diff --git a/lib/container_registry/registry.rb b/lib/container_registry/registry.rb index 07490de94ba..0e634f6b6ef 100644 --- a/lib/container_registry/registry.rb +++ b/lib/container_registry/registry.rb @@ -8,7 +8,7 @@ module ContainerRegistry @client = ContainerRegistry::Client.new(uri, options) end - def [](name) + def repository(name) ContainerRegistry::Repository.new(self, name) end diff --git a/lib/container_registry/repository.rb b/lib/container_registry/repository.rb index 77825056138..0e4a7cb3cc9 100644 --- a/lib/container_registry/repository.rb +++ b/lib/container_registry/repository.rb @@ -2,19 +2,17 @@ module ContainerRegistry class Repository attr_reader :registry, :name + delegate :client, to: :registry + def initialize(registry, name) @registry, @name = registry, name end - def client - @client ||= registry.client - end - def path [registry.path, name].compact.join('/') end - def [](tag) + def tag(tag) ContainerRegistry::Tag.new(self, tag) end @@ -37,26 +35,14 @@ module ContainerRegistry end end + def blob(config) + ContainerRegistry::Blob.new(self, config) + end + def delete_tags return unless tags tags.all?(&:delete) end - - def mount_blob(blob) - return unless blob - - client.repository_mount_blob(name, blob.digest, blob.repository.name) - end - - def mount_manifest(tag, manifest) - client.put_repository_manifest(name, tag, manifest) - end - - def copy_to(other_repository) - tags.all? do |tag| - tag.copy_to(other_repository) - end - end end end diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb index f06806db6a8..43f8d6dc8c2 100644 --- a/lib/container_registry/tag.rb +++ b/lib/container_registry/tag.rb @@ -2,6 +2,8 @@ module ContainerRegistry class Tag attr_reader :repository, :name + delegate :registry, :client, to: :repository + def initialize(repository, name) @repository, @name = repository, name end @@ -36,7 +38,7 @@ module ContainerRegistry return @config_blob if defined?(@config_blob) return unless manifest && manifest['config'] - @config_blob = ContainerRegistry::Blob.new(repository, manifest['config']) + @config_blob = repository.blob(manifest['config']) end def config @@ -56,7 +58,7 @@ module ContainerRegistry return unless manifest @layers = manifest['layers'].map do |layer| - ContainerRegistry::Blob.new(repository, layer) + repository.blob(layer) end end @@ -71,19 +73,5 @@ module ContainerRegistry client.delete_repository_tag(repository.name, digest) end - - def copy_to(repository) - return unless manifest - - layers.each do |blob| - repository.mount_blob(blob) - end - repository.mount_blob(config_blob) - repository.mount_manifest(name, manifest.to_json) - end - - def client - @client ||= repository.client - end end end |