summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzcinski <ayufan@ayufan.eu>2016-05-17 09:41:47 -0500
committerKamil Trzcinski <ayufan@ayufan.eu>2016-05-17 09:41:47 -0500
commita82109eee80bf703ad8e82de2410f490e5fc6d54 (patch)
tree4417e900b39111123d175303fec9deb71be14e4a
parentac6992ba682de08b79e5ddde08dbf566827e2f07 (diff)
downloadgitlab-ce-a82109eee80bf703ad8e82de2410f490e5fc6d54.tar.gz
Add .gitkeep
-rw-r--r--lib/container_registry/config.rb1
-rw-r--r--lib/container_registry/registry.rb10
-rw-r--r--lib/container_registry/repository.rb1
-rw-r--r--lib/container_registry/tag.rb10
-rw-r--r--shared/registry/.gitkeep0
-rw-r--r--spec/lib/container_registry/registry_spec.rb28
6 files changed, 48 insertions, 2 deletions
diff --git a/lib/container_registry/config.rb b/lib/container_registry/config.rb
index 626b36cbaa9..589f9f4380a 100644
--- a/lib/container_registry/config.rb
+++ b/lib/container_registry/config.rb
@@ -9,6 +9,7 @@ module ContainerRegistry
def [](key)
return unless data
+
data[key]
end
end
diff --git a/lib/container_registry/registry.rb b/lib/container_registry/registry.rb
index d3b117eeaca..07490de94ba 100644
--- a/lib/container_registry/registry.rb
+++ b/lib/container_registry/registry.rb
@@ -3,13 +3,19 @@ module ContainerRegistry
attr_reader :uri, :client, :path
def initialize(uri, options = {})
- @path = options[:path] || uri
- @uri = URI.parse(uri)
+ @uri = uri
+ @path = options[:path] || default_path
@client = ContainerRegistry::Client.new(uri, options)
end
def [](name)
ContainerRegistry::Repository.new(self, name)
end
+
+ private
+
+ def default_path
+ @uri.sub(/^https?:\/\//, '')
+ end
end
end
diff --git a/lib/container_registry/repository.rb b/lib/container_registry/repository.rb
index 07cdb78264e..77825056138 100644
--- a/lib/container_registry/repository.rb
+++ b/lib/container_registry/repository.rb
@@ -20,6 +20,7 @@ module ContainerRegistry
def manifest
return @manifest if defined?(@manifest)
+
@manifest = client.repository_tags(name)
end
diff --git a/lib/container_registry/tag.rb b/lib/container_registry/tag.rb
index 14cee8be889..f06806db6a8 100644
--- a/lib/container_registry/tag.rb
+++ b/lib/container_registry/tag.rb
@@ -12,6 +12,7 @@ module ContainerRegistry
def manifest
return @manifest if defined?(@manifest)
+
@manifest = client.repository_manifest(repository.name, name)
end
@@ -21,33 +22,39 @@ module ContainerRegistry
def [](key)
return unless manifest
+
manifest[key]
end
def digest
return @digest if defined?(@digest)
+
@digest = client.repository_tag_digest(repository.name, name)
end
def config_blob
return @config_blob if defined?(@config_blob)
return unless manifest && manifest['config']
+
@config_blob = ContainerRegistry::Blob.new(repository, manifest['config'])
end
def config
return unless config_blob
+
@config ||= ContainerRegistry::Config.new(self, config_blob)
end
def created_at
return unless config
+
@created_at ||= DateTime.rfc3339(config['created'])
end
def layers
return @layers if defined?(@layers)
return unless manifest
+
@layers = manifest['layers'].map do |layer|
ContainerRegistry::Blob.new(repository, layer)
end
@@ -55,16 +62,19 @@ module ContainerRegistry
def total_size
return unless layers
+
layers.map(&:size).sum
end
def delete
return unless digest
+
client.delete_repository_tag(repository.name, digest)
end
def copy_to(repository)
return unless manifest
+
layers.each do |blob|
repository.mount_blob(blob)
end
diff --git a/shared/registry/.gitkeep b/shared/registry/.gitkeep
new file mode 100644
index 00000000000..e69de29bb2d
--- /dev/null
+++ b/shared/registry/.gitkeep
diff --git a/spec/lib/container_registry/registry_spec.rb b/spec/lib/container_registry/registry_spec.rb
new file mode 100644
index 00000000000..f5f7c3c8bf2
--- /dev/null
+++ b/spec/lib/container_registry/registry_spec.rb
@@ -0,0 +1,28 @@
+require 'spec_helper'
+
+describe ContainerRegistry::Registry do
+ let(:path) { nil }
+ let(:registry) { described_class.new('http://example.com', path: path) }
+
+ subject { registry }
+
+ it { is_expected.to respond_to(:client) }
+ it { is_expected.to respond_to(:uri) }
+ it { is_expected.to respond_to(:path) }
+
+ it { expect(subject['test']).to_not be_nil }
+
+ context '#path' do
+ subject { registry.path }
+
+ context 'path from URL' do
+ it { is_expected.to eq('example.com') }
+ end
+
+ context 'custom path' do
+ let(:path) { 'registry.example.com' }
+
+ it { is_expected.to eq(path) }
+ end
+ end
+end