Skip to content
Snippets Groups Projects

Container Registry multi-level image names support

7 unresolved threads
14 files
+ 275
7
Compare changes
  • Side-by-side
  • Inline
Files
14
module ContainerRegistry
class ContainerImage < ActiveRecord::Base
class Repository
belongs_to :project
attr_reader :registry, :name
delegate :client, to: :registry
delegate :container_registry, :container_registry_allowed_paths,
 
:container_registry_path_with_namespace, to: :project
def initialize(registry, name)
delegate :client, to: :container_registry
Please register or sign in to reply
@registry, @name = registry, name
end
def path
validates :manifest, presence: true
[registry.path, name].compact.join('/')
end
def tag(tag)
before_destroy :delete_tags
ContainerRegistry::Tag.new(self, tag)
end
def manifest
before_validation :update_token, on: :create
return @manifest if defined?(@manifest)
def update_token
 
paths = container_registry_allowed_paths << name_with_namespace
 
token = Auth::ContainerRegistryAuthenticationService.full_access_token(paths)
 
client.update_token(token)
 
end
@manifest = client.repository_tags(name)
def path
end
[container_registry.path, name_with_namespace].compact.join('/')
 
end
def valid?
def name_with_namespace
manifest.present?
[container_registry_path_with_namespace, name].reject(&:blank?).join('/')
end
end
def tags
def tag(tag)
return @tags if defined?(@tags)
ContainerRegistry::Tag.new(self, tag)
return [] unless manifest && manifest['tags']
end
@tags = manifest['tags'].map do |tag|
def manifest
ContainerRegistry::Tag.new(self, tag)
@manifest ||= client.repository_tags(name_with_namespace)
end
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
 
end
def blob(config)
def blob(config)
ContainerRegistry::Blob.new(self, 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(name_with_namespace, digest)
end
end
 
end
def delete_tags
# rubocop:disable RedundantReturn
return unless tags
tags.all?(&:delete)
def self.split_namespace(full_path)
Please register or sign in to reply
 
image_name = full_path.split('/').last
 
namespace = full_path.gsub(/(.*)(#{Regexp.escape('/' + image_name)})/, '\1')
 
if namespace.count('/') < 1
 
namespace, image_name = full_path, ""
end
end
 
return namespace, image_name
end
end
end
end
Loading