Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-03-23 16:00:41 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-03-23 16:00:41 +0300
commit01d159b409d8b24d36204979a73de249843d71bf (patch)
tree8450df71c27dd6ebf1c48d779273502ac8fb4d15 /app/models/container_repository.rb
parentbd8c8df6ed8dd7321608ce652e23d86ef3bd6899 (diff)
Rename container image model to container repository
Diffstat (limited to 'app/models/container_repository.rb')
-rw-r--r--app/models/container_repository.rb62
1 files changed, 62 insertions, 0 deletions
diff --git a/app/models/container_repository.rb b/app/models/container_repository.rb
new file mode 100644
index 00000000000..2e78fc148b4
--- /dev/null
+++ b/app/models/container_repository.rb
@@ -0,0 +1,62 @@
+class ContainerRepository < ActiveRecord::Base
+ belongs_to :project
+
+ delegate :container_registry, to: :project
+ delegate :client, to: :container_registry
+
+ validates :manifest, presence: true
+
+ before_destroy :delete_tags
+
+ def registry
+ # TODO, container registry with image access level
+ token = Auth::ContainerRegistryAuthenticationService.image_token(self)
+ end
+
+ def tag(tag)
+ ContainerRegistry::Tag.new(self, tag)
+ end
+
+ def manifest
+ @manifest ||= client.repository_tags(self.path)
+ end
+
+ def tags
+ return @tags if defined?(@tags)
+ return [] unless manifest && manifest['tags']
+
+ @tags = manifest['tags'].map do |tag|
+ ContainerRegistry::Tag.new(self, tag)
+ end
+ end
+
+ def blob(config)
+ ContainerRegistry::Blob.new(self, config)
+ end
+
+ def delete_tags
+ return unless tags
+
+ digests = tags.map {|tag| tag.digest }.to_set
+ digests.all? do |digest|
+ client.delete_repository_tag(self.path, digest)
+ end
+ end
+
+ def self.project_from_path(repository_path)
+ return unless repository_path.include?('/')
+
+ ##
+ # Projects are always located inside a namespace, so we can remove
+ # the last node, and see if project with that path exists.
+ #
+ truncated_path = repository_path.slice(0...repository_path.rindex('/'))
+
+ ##
+ # We still make it possible to search projects by a full image path
+ # in order to maintain backwards compatibility.
+ #
+ Project.find_by_full_path(truncated_path) ||
+ Project.find_by_full_path(repository_path)
+ end
+end