blob: 2e78fc148b4d13704fed8699e1911ee2e91d1239 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
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
|