Commit e1c8663a authored by Kamil Trzcinski's avatar Kamil Trzcinski

Allow to copy all manifests from one container repository to another

parent 7168493e
...@@ -43,5 +43,9 @@ module ImageRegistry ...@@ -43,5 +43,9 @@ module ImageRegistry
return @data if defined?(@data) return @data if defined?(@data)
@data ||= client.blob(repository.name, digest, type) @data ||= client.blob(repository.name, digest, type)
end end
def mount_to(to_repository)
client.repository_mount_blob(to_repository.name, digest, repository.name)
end
end end
end end
...@@ -39,7 +39,7 @@ module ImageRegistry ...@@ -39,7 +39,7 @@ module ImageRegistry
end end
def repository_mount_blob(name, digest, from) def repository_mount_blob(name, digest, from)
@faraday.post("/v2/#{name}/blobls/uploads/?mount=#{digest}&from=#{from}").status == 201 @faraday.post("/v2/#{name}/blobs/uploads/?mount=#{digest}&from=#{from}").status == 201
end end
def repository_tag_digest(name, reference) def repository_tag_digest(name, reference)
......
...@@ -29,11 +29,27 @@ module ImageRegistry ...@@ -29,11 +29,27 @@ module ImageRegistry
@tags = manifest['tags'].map do |tag| @tags = manifest['tags'].map do |tag|
ImageRegistry::Tag.new(self, tag) ImageRegistry::Tag.new(self, tag)
end end
@tags ||= []
end end
def delete_tags def delete_tags
return unless tags return unless tags
tags.each(:delete) tags.each(:delete)
end 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
end end
...@@ -25,11 +25,15 @@ module ImageRegistry ...@@ -25,11 +25,15 @@ module ImageRegistry
@digest = client.repository_tag_digest(repository.name, name) @digest = client.repository_tag_digest(repository.name, name)
end end
def config def config_blob
return @config if defined?(@config) return @config_blob if defined?(@config_blob)
return unless manifest && manifest['config'] return unless manifest && manifest['config']
blob = ImageRegistry::Blob.new(repository, manifest['config']) @config_blob = ImageRegistry::Blob.new(repository, manifest['config'])
@config = ImageRegistry::Config.new(self, blob) end
def config
return unless config_blob
@config ||= ImageRegistry::Config.new(self, config_blob)
end end
def created_at def created_at
...@@ -55,6 +59,15 @@ module ImageRegistry ...@@ -55,6 +59,15 @@ module ImageRegistry
client.delete_repository_tag(repository.name, digest) client.delete_repository_tag(repository.name, digest)
end 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 def client
@client ||= repository.client @client ||= repository.client
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment